diff options
author | Johan Liesén <johan@liesen.se> | 2014-03-21 16:55:06 +0100 |
---|---|---|
committer | Johan Liesén <johan@liesen.se> | 2014-03-22 15:56:08 +0100 |
commit | ffac53f9edbd59a0157284a2c1892c73d5dce79d (patch) | |
tree | dbe7e663e2b795a4f5fb4b9d2a6a51b7427b36a9 /src/de | |
parent | 299a6e47898df8b6a7da37a2c54dfd22dc5e282f (diff) | |
download | AntennaPod-ffac53f9edbd59a0157284a2c1892c73d5dce79d.zip |
Restore subscriptions when the app is first started
Perform a subscription list restore when the app is started for the
first time. Use a preference setting to figure out if the app is freshly
installed or not.
Diffstat (limited to 'src/de')
-rw-r--r-- | src/de/danoeh/antennapod/activity/MainActivity.java | 24 | ||||
-rw-r--r-- | src/de/danoeh/antennapod/preferences/UserPreferences.java | 17 |
2 files changed, 41 insertions, 0 deletions
diff --git a/src/de/danoeh/antennapod/activity/MainActivity.java b/src/de/danoeh/antennapod/activity/MainActivity.java index 9edb312de..8e84f08f8 100644 --- a/src/de/danoeh/antennapod/activity/MainActivity.java +++ b/src/de/danoeh/antennapod/activity/MainActivity.java @@ -4,6 +4,8 @@ import java.util.ArrayList; import android.app.SearchManager; import android.app.SearchableInfo; +import android.app.backup.BackupManager; +import android.app.backup.RestoreObserver; import android.content.Context; import android.content.Intent; import android.media.AudioManager; @@ -22,6 +24,8 @@ import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.Window; +import android.widget.Toast; + import de.danoeh.antennapod.AppConfig; import de.danoeh.antennapod.R; import de.danoeh.antennapod.feed.EventDistributor; @@ -114,6 +118,26 @@ public class MainActivity extends ActionBarActivity { updateProgressBarVisibility(); EventDistributor.getInstance().register(contentUpdate); + // Possibly restore feed subscriptions from backup + if (UserPreferences.isFreshInstall()) { + new BackupManager(this).requestRestore(new BackupRestoreObserver(this)); + UserPreferences.setIsFreshInstall(false); + } + } + + private static class BackupRestoreObserver extends RestoreObserver { + private final Context mContext; + + public BackupRestoreObserver(final Context context) { + mContext = context; + } + + @Override + public void restoreFinished(int error) { + if (error == 0) { + Toast.makeText(mContext, R.string.backup_restored, Toast.LENGTH_SHORT).show(); + } + } } private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() { diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index 2b4b66362..1ba1b4962 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -50,6 +50,7 @@ public class UserPreferences implements private static final String PREF_PLAYBACK_SPEED = "prefPlaybackSpeed"; private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray"; public static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss"; + private static final String PREF_IS_FRESH_INSTALL = "prefIsFreshInstall"; // TODO: Make this value configurable private static final double PLAYED_DURATION_AUTOFLATTR_THRESHOLD = 0.8; @@ -76,6 +77,7 @@ public class UserPreferences implements private String playbackSpeed; private String[] playbackSpeedArray; private boolean pauseForFocusLoss; + private boolean isFreshInstall; private UserPreferences(Context context) { this.context = context; @@ -130,6 +132,7 @@ public class UserPreferences implements playbackSpeedArray = readPlaybackSpeedArray(sp.getString( PREF_PLAYBACK_SPEED_ARRAY, null)); pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false); + isFreshInstall = sp.getBoolean(PREF_IS_FRESH_INSTALL, true); } private int readThemeValue(String valueFromPrefs) { @@ -284,6 +287,11 @@ public class UserPreferences implements return instance.pauseForFocusLoss; } + public static boolean isFreshInstall() { + instanceAvailable(); + return instance.isFreshInstall; + } + @Override public void onSharedPreferenceChanged(SharedPreferences sp, String key) { if (AppConfig.DEBUG) @@ -334,6 +342,8 @@ public class UserPreferences implements pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false); } else if (key.equals(PREF_PAUSE_ON_HEADSET_DISCONNECT)) { pauseOnHeadsetDisconnect = sp.getBoolean(PREF_PAUSE_ON_HEADSET_DISCONNECT, true); + } else if (key.equals(PREF_IS_FRESH_INSTALL)) { + isFreshInstall = sp.getBoolean(PREF_IS_FRESH_INSTALL, true); } } @@ -526,4 +536,11 @@ public class UserPreferences implements instanceAvailable(); return PLAYED_DURATION_AUTOFLATTR_THRESHOLD; } + + public static void setIsFreshInstall(boolean isFreshInstall) { + instanceAvailable(); + PreferenceManager.getDefaultSharedPreferences(instance.context).edit() + .putBoolean(PREF_IS_FRESH_INSTALL, isFreshInstall) + .apply(); + } } |