Added episode cache size preference

This commit is contained in:
daniel oeh 2013-03-09 11:13:30 +01:00
parent 73d23773c5
commit 6a784b7b31
5 changed files with 47 additions and 2 deletions

View File

@ -21,6 +21,15 @@
<item>24</item>
</string-array>
<string-array name="episode_cache_size">
<item>10</item>
<item>20</item>
<item>40</item>
<item>60</item>
<item>80</item>
<item>100</item>
</string-array>
<string-array name="autodl_select_networks_default_entries">
<item>N/A</item>
</string-array>

View File

@ -177,6 +177,7 @@
<string name="pref_automatic_download_sum">Configure the automatic download of episodes.</string>
<string name="pref_autodl_wifi_filter_title">Enable Wi-Fi filter</string>
<string name="pref_autodl_wifi_filter_sum">Allow automatic download only for selected Wi-Fi networks.</string>
<string name="pref_episode_cache_title">Episode cache</string>
<!-- Search -->
<string name="search_hint">Search for Feeds or Episodes</string>

View File

@ -35,9 +35,10 @@
android:summary="@string/pref_mobileUpdate_sum"
android:title="@string/pref_mobileUpdate_title" />
<CheckBoxPreference android:summary="@string/pref_autoQueue_sum" android:defaultValue="true" android:key="prefAutoQueue" android:title="@string/pref_autoQueue_title"/>
<PreferenceScreen android:summary="@string/pref_automatic_download_sum" android:key="prefAutoDownloadSettings" android:title="@string/pref_automatic_download_title">
<ListPreference android:defaultValue="20" android:entries="@array/episode_cache_size" android:key="prefEpisodeCacheSize" android:title="@string/pref_episode_cache_title" android:entryValues="@array/episode_cache_size"/><PreferenceScreen android:summary="@string/pref_automatic_download_sum" android:key="prefAutoDownloadSettings" android:title="@string/pref_automatic_download_title">
<CheckBoxPreference android:key="prefEnableAutoDownloadWifiFilter" android:title="@string/pref_autodl_wifi_filter_title" android:summary="@string/pref_autodl_wifi_filter_sum"/>
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="@string/flattr_settings_label" >
<PreferenceScreen

View File

@ -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) {

View File

@ -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();