From f145a4db38062888f171a5bf7e20bdaa27978035 Mon Sep 17 00:00:00 2001 From: Martin Fietz Date: Wed, 13 Jan 2016 18:22:18 +0100 Subject: [PATCH] Move episode cache preference to auto download sub-menu --- .../test/antennapod/ui/PreferencesTest.java | 20 ++++++----- .../preferences/PreferenceController.java | 33 ++++++++----------- app/src/main/res/xml/preferences.xml | 14 ++++---- 3 files changed, 33 insertions(+), 34 deletions(-) diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java index fabc399ba..b70336a30 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java @@ -3,17 +3,10 @@ package de.test.antennapod.ui; import android.content.Context; import android.content.res.Resources; import android.test.ActivityInstrumentationTestCase2; -import android.test.FlakyTest; -import com.robotium.solo.Condition; import com.robotium.solo.Solo; import com.robotium.solo.Timeout; -import org.apache.commons.io.IOUtils; - -import java.io.IOException; -import java.io.InputStream; -import java.util.List; import java.util.concurrent.TimeUnit; import de.danoeh.antennapod.R; @@ -230,6 +223,8 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2 UserPreferences.getEpisodeCacheSize() == minValue, Timeout.getLargeTimeout())); } - public void testSetEpisodeCacheMax() { String[] entries = res.getStringArray(R.array.episode_cache_size_entries); String[] values = res.getStringArray(R.array.episode_cache_size_values); String maxEntry = entries[entries.length-1]; final int maxValue = Integer.valueOf(values[values.length-1]); + solo.clickOnText(solo.getString(R.string.pref_automatic_download_title)); + solo.waitForText(solo.getString(R.string.pref_automatic_download_title)); + if(!UserPreferences.isEnableAutodownload()) { + solo.clickOnText(solo.getString(R.string.pref_automatic_download_title)); + } solo.clickOnText(solo.getString(R.string.pref_episode_cache_title)); solo.waitForDialogToOpen(); solo.clickOnText(maxEntry); diff --git a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java index a872039f9..ecbec4edc 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -216,17 +216,16 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } }); - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL) - .setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - if (newValue instanceof Boolean) { - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled((Boolean) newValue); - setSelectedNetworksEnabled((Boolean) newValue && UserPreferences.isEnableAutodownloadWifiFilter()); - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled((Boolean) newValue); - } - return true; + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL).setOnPreferenceChangeListener( + (preference, newValue) -> { + if (newValue instanceof Boolean) { + boolean enabled = (Boolean) newValue; + ui.findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setEnabled(enabled); + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled(enabled); + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled(enabled); + setSelectedNetworksEnabled(enabled && UserPreferences.isEnableAutodownloadWifiFilter()); } + return true; }); ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER) .setOnPreferenceChangeListener( @@ -527,21 +526,17 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc @SuppressWarnings("deprecation") private void checkItemVisibility() { - boolean hasFlattrToken = FlattrUtils.hasToken(); - ui.findPreference(PreferenceController.PREF_FLATTR_SETTINGS).setEnabled(FlattrUtils.hasAPICredentials()); ui.findPreference(PreferenceController.PREF_FLATTR_AUTH).setEnabled(!hasFlattrToken); ui.findPreference(PreferenceController.PREF_FLATTR_REVOKE).setEnabled(hasFlattrToken); ui.findPreference(PreferenceController.PREF_AUTO_FLATTR_PREFS).setEnabled(hasFlattrToken); - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER) - .setEnabled(UserPreferences.isEnableAutodownload()); - setSelectedNetworksEnabled(UserPreferences.isEnableAutodownload() - && UserPreferences.isEnableAutodownloadWifiFilter()); - - ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY) - .setEnabled(UserPreferences.isEnableAutodownload()); + boolean autoDownload = UserPreferences.isEnableAutodownload(); + ui.findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setEnabled(autoDownload); + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled(autoDownload); + ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled(autoDownload); + setSelectedNetworksEnabled(autoDownload && UserPreferences.isEnableAutodownloadWifiFilter()); ui.findPreference("prefSendCrashReport").setEnabled(CrashReportWriter.getFile().exists()); diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index cdb582898..b2a28e871 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -170,13 +170,6 @@ android:key="prefParallelDownloads" android:title="@string/pref_parallel_downloads_title" app:useStockLayout="true"/> - +