Settings menu did not refresh correctly on preference change. fixes #284

This commit is contained in:
daniel oeh 2013-09-25 22:42:58 +02:00
parent 225f03e106
commit bfc5ddc15d
2 changed files with 28 additions and 10 deletions

View File

@ -15,7 +15,6 @@ import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener; import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.Preference.OnPreferenceClickListener; import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
import android.support.v4.app.NavUtils;
import android.util.Log; import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -148,6 +147,17 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
return true; return true;
} }
}); });
findPreference(UserPreferences.PREF_ENABLE_AUTODL)
.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
if (newValue instanceof Boolean) {
findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled((Boolean) newValue);
setSelectedNetworksEnabled((Boolean) newValue && UserPreferences.isEnableAutodownloadWifiFilter());
}
return true;
}
});
findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER) findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER)
.setOnPreferenceChangeListener( .setOnPreferenceChangeListener(
new OnPreferenceChangeListener() { new OnPreferenceChangeListener() {
@ -166,11 +176,11 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE) findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE)
.setOnPreferenceChangeListener( .setOnPreferenceChangeListener(
new OnPreferenceChangeListener() { new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object o) { public boolean onPreferenceChange(Preference preference, Object o) {
checkItemVisibility(); if (o instanceof String) {
setEpisodeCacheSizeText(UserPreferences.readEpisodeCacheSize((String) o));
}
return true; return true;
} }
}); });

View File

@ -115,7 +115,7 @@ public class UserPreferences implements
PREF_ENABLE_AUTODL_WIFI_FILTER, false); PREF_ENABLE_AUTODL_WIFI_FILTER, false);
autodownloadSelectedNetworks = StringUtils.split( autodownloadSelectedNetworks = StringUtils.split(
sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ','); sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ',');
episodeCacheSize = readEpisodeCacheSize(sp.getString( episodeCacheSize = readEpisodeCacheSizeInternal(sp.getString(
PREF_EPISODE_CACHE_SIZE, "20")); PREF_EPISODE_CACHE_SIZE, "20"));
enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false);
playbackSpeed = sp.getString(PREF_PLAYBACK_SPEED, "1.0"); playbackSpeed = sp.getString(PREF_PLAYBACK_SPEED, "1.0");
@ -139,7 +139,7 @@ public class UserPreferences implements
return TimeUnit.HOURS.toMillis(hours); return TimeUnit.HOURS.toMillis(hours);
} }
private int readEpisodeCacheSize(String valueFromPrefs) { private int readEpisodeCacheSizeInternal(String valueFromPrefs) {
if (valueFromPrefs.equals(context if (valueFromPrefs.equals(context
.getString(R.string.pref_episode_cache_unlimited))) { .getString(R.string.pref_episode_cache_unlimited))) {
return EPISODE_CACHE_SIZE_UNLIMITED; return EPISODE_CACHE_SIZE_UNLIMITED;
@ -300,7 +300,7 @@ public class UserPreferences implements
autodownloadSelectedNetworks = StringUtils.split( autodownloadSelectedNetworks = StringUtils.split(
sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ','); sp.getString(PREF_AUTODL_SELECTED_NETWORKS, ""), ',');
} else if (key.equals(PREF_EPISODE_CACHE_SIZE)) { } else if (key.equals(PREF_EPISODE_CACHE_SIZE)) {
episodeCacheSize = readEpisodeCacheSize(sp.getString( episodeCacheSize = readEpisodeCacheSizeInternal(sp.getString(
PREF_EPISODE_CACHE_SIZE, "20")); PREF_EPISODE_CACHE_SIZE, "20"));
} else if (key.equals(PREF_ENABLE_AUTODL)) { } else if (key.equals(PREF_ENABLE_AUTODL)) {
enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false); enableAutodownload = sp.getBoolean(PREF_ENABLE_AUTODL, false);
@ -474,4 +474,12 @@ public class UserPreferences implements
Log.d(TAG, "Automatic update was deactivated"); Log.d(TAG, "Automatic update was deactivated");
} }
} }
/**
* Reads episode cache size as it is saved in the episode_cache_size_values array.
* */
public static int readEpisodeCacheSize(String valueFromPrefs) {
instanceAvailable();
return instance.readEpisodeCacheSizeInternal(valueFromPrefs);
}
} }