From 6a784b7b31cd6de1935cc7ed242c613d6eff0b0c Mon Sep 17 00:00:00 2001 From: daniel oeh Date: Sat, 9 Mar 2013 11:13:30 +0100 Subject: Added episode cache size preference --- .../antennapod/activity/PreferenceActivity.java | 21 +++++++++++++++++++++ .../antennapod/preferences/UserPreferences.java | 15 ++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/de/danoeh/antennapod/activity/PreferenceActivity.java b/src/de/danoeh/antennapod/activity/PreferenceActivity.java index 7df0c17bd..6bad316a6 100644 --- a/src/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/src/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -144,6 +144,20 @@ public class PreferenceActivity extends SherlockPreferenceActivity { } } }); + findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE) + .setOnPreferenceChangeListener( + new OnPreferenceChangeListener() { + + @Override + public boolean onPreferenceChange( + Preference preference, Object newValue) { + if (newValue instanceof String) { + setEpisodeCacheSizeText(Integer + .valueOf((String) newValue)); + } + return true; + } + }); buildAutodownloadSelectedNetworsPreference(); setSelectedNetworksEnabled(UserPreferences .isEnableAutodownloadWifiFilter()); @@ -162,6 +176,7 @@ public class PreferenceActivity extends SherlockPreferenceActivity { protected void onResume() { super.onResume(); checkItemVisibility(); + setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize()); setDataFolderText(); } @@ -175,6 +190,12 @@ public class PreferenceActivity extends SherlockPreferenceActivity { } + private void setEpisodeCacheSizeText(int cacheSize) { + findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setSummary( + Integer.toString(cacheSize) + + getString(R.string.episodes_suffix)); + } + private void setDataFolderText() { File f = UserPreferences.getDataFolder(this, null); if (f != null) { diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index 72fd7a46a..5684c5f37 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -41,6 +41,7 @@ public class UserPreferences implements public static final String PREF_DATA_FOLDER = "prefDataFolder"; public static final String PREF_ENABLE_AUTODL_WIFI_FILTER = "prefEnableAutoDownloadWifiFilter"; private static final String PREF_AUTODL_SELECTED_NETWORKS = "prefAutodownloadSelectedNetworks"; + public static final String PREF_EPISODE_CACHE_SIZE = "prefEpisodeCacheSize"; private static UserPreferences instance; private Context context; @@ -57,6 +58,7 @@ public class UserPreferences implements private int theme; private boolean enableAutodownloadWifiFilter; private String[] autodownloadSelectedNetworks; + private int episodeCacheSize; private UserPreferences(Context context) { this.context = context; @@ -101,6 +103,8 @@ public class UserPreferences implements PREF_ENABLE_AUTODL_WIFI_FILTER, false); autodownloadSelectedNetworks = StringUtils.split( sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ','); + episodeCacheSize = Integer.valueOf(sp.getString( + PREF_EPISODE_CACHE_SIZE, "20")); } private int readThemeValue(String valueFromPrefs) { @@ -181,6 +185,11 @@ public class UserPreferences implements return instance.autodownloadSelectedNetworks; } + public static int getEpisodeCacheSize() { + instanceAvailable(); + return instance.episodeCacheSize; + } + @Override public void onSharedPreferenceChanged(SharedPreferences sp, String key) { if (AppConfig.DEBUG) @@ -231,10 +240,14 @@ public class UserPreferences implements } else if (key.equals(PREF_AUTODL_SELECTED_NETWORKS)) { autodownloadSelectedNetworks = StringUtils.split( sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ','); + } else if (key.equals(PREF_EPISODE_CACHE_SIZE)) { + episodeCacheSize = Integer.valueOf(sp.getString( + PREF_EPISODE_CACHE_SIZE, "20")); } } - public static void setAutodownloadSelectedNetworks(Context context, String[] value) { + public static void setAutodownloadSelectedNetworks(Context context, + String[] value) { SharedPreferences.Editor editor = PreferenceManager .getDefaultSharedPreferences(context.getApplicationContext()) .edit(); -- cgit v1.2.3