diff options
Diffstat (limited to 'src/de/danoeh/antennapod/preferences/UserPreferences.java')
-rw-r--r-- | src/de/danoeh/antennapod/preferences/UserPreferences.java | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index bd491a5cf..f2f35f41d 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -42,6 +42,8 @@ public class UserPreferences implements private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks"; public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize"; + private static int EPISODE_CACHE_SIZE_UNLIMITED = -1; + private static UserPreferences instance; private Context context; @@ -86,6 +88,8 @@ public class UserPreferences implements private void loadPreferences() { SharedPreferences sp = PreferenceManager .getDefaultSharedPreferences(context); + EPISODE_CACHE_SIZE_UNLIMITED = context.getResources().getInteger( + R.integer.episode_cache_size_unlimited); pauseOnHeadsetDisconnect = sp.getBoolean( PREF_PAUSE_ON_HEADSET_DISCONNECT, true); followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false); @@ -101,7 +105,7 @@ public class UserPreferences implements PREF_ENABLE_AUTODL_WIFI_FILTER, false); autodownloadSelectedNetworks = StringUtils.split( sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ','); - episodeCacheSize = Integer.valueOf(sp.getString( + episodeCacheSize = readEpisodeCacheSize(sp.getString( PREF_EPISODE_CACHE_SIZE, "20")); enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); } @@ -122,6 +126,15 @@ public class UserPreferences implements return TimeUnit.HOURS.toMillis(hours); } + private int readEpisodeCacheSize(String valueFromPrefs) { + if (valueFromPrefs.equals(context + .getString(R.string.pref_episode_cache_unlimited))) { + return EPISODE_CACHE_SIZE_UNLIMITED; + } else { + return Integer.valueOf(valueFromPrefs); + } + } + private static void instanceAvailable() { if (instance == null) { throw new IllegalStateException( @@ -179,6 +192,15 @@ public class UserPreferences implements return instance.autodownloadSelectedNetworks; } + public static int getEpisodeCacheSizeUnlimited() { + return EPISODE_CACHE_SIZE_UNLIMITED; + } + + /** + * Returns the capacity of the episode cache. This method will return the + * negative integer EPISODE_CACHE_SIZE_UNLIMITED if the cache size is set to + * 'unlimited'. + */ public static int getEpisodeCacheSize() { instanceAvailable(); return instance.episodeCacheSize; @@ -224,7 +246,7 @@ public class UserPreferences implements autodownloadSelectedNetworks = StringUtils.split( sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ','); } else if (key.equals(PREF_EPISODE_CACHE_SIZE)) { - episodeCacheSize = Integer.valueOf(sp.getString( + episodeCacheSize = readEpisodeCacheSize(sp.getString( PREF_EPISODE_CACHE_SIZE, "20")); } else if (key.equals(PREF_ENABLE_AUTODL)) { enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); |