diff --git a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java index 5fe5bc334..271fc667d 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -5,6 +5,7 @@ import android.content.Intent; import android.os.Bundle; import android.preference.Preference; import android.preference.PreferenceFragment; +import android.preference.PreferenceScreen; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.view.Menu; @@ -40,6 +41,11 @@ public class PreferenceActivity extends AppCompatActivity { return fragment.findPreference(key); } + @Override + public PreferenceScreen getPreferenceScreen() { + return fragment.getPreferenceScreen(); + } + @Override public Activity getActivity() { return PreferenceActivity.this; @@ -135,6 +141,8 @@ public class PreferenceActivity extends AppCompatActivity { switch (preferences) { case R.xml.preferences_downloads: return R.string.downloads_label; + case R.xml.preferences_autodownload: + return R.string.pref_automatic_download_title; case R.xml.preferences_playback: return R.string.playback_pref; case R.xml.preferences_storage: 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 407ab0bdb..58ddc07c7 100644 --- a/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java +++ b/app/src/main/java/de/danoeh/antennapod/preferences/PreferenceController.java @@ -22,6 +22,7 @@ import android.preference.CheckBoxPreference; import android.preference.EditTextPreference; import android.preference.ListPreference; import android.preference.Preference; +import android.preference.PreferenceCategory; import android.preference.PreferenceFragment; import android.preference.PreferenceManager; import android.preference.PreferenceScreen; @@ -166,6 +167,9 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc break; case R.xml.preferences_downloads: setupDownloadsScreen(); + break; + case R.xml.preferences_autodownload: + setupAutoDownloadScreen(); buildAutodownloadSelectedNetworsPreference(); setSelectedNetworksEnabled(UserPreferences.isEnableAutodownloadWifiFilter()); buildEpisodeCleanupPreference(); @@ -398,12 +402,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } } - private void setupDownloadsScreen() { - ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL) - .setOnPreferenceClickListener(preference -> { - showUpdateIntervalTimePreferencesDialog(); - return true; - }); + private void setupAutoDownloadScreen() { ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL).setOnPreferenceChangeListener( (preference, newValue) -> { if (newValue instanceof Boolean) { @@ -426,6 +425,26 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } } ); + ui.findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE) + .setOnPreferenceChangeListener( + (preference, o) -> { + if (o instanceof String) { + setEpisodeCacheSizeText(UserPreferences.readEpisodeCacheSize((String) o)); + } + return true; + } + ); + } + + private void setupDownloadsScreen() { + final Activity activity = ui.getActivity(); + ui.findPreference(AUTO_DL_PREF_SCREEN).setOnPreferenceClickListener(preference -> + openScreen(R.xml.preferences_autodownload, activity)); + ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL) + .setOnPreferenceClickListener(preference -> { + showUpdateIntervalTimePreferencesDialog(); + return true; + }); ui.findPreference(UserPreferences.PREF_PARALLEL_DOWNLOADS) .setOnPreferenceChangeListener( (preference, o) -> { @@ -471,15 +490,6 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc } } }); - ui.findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE) - .setOnPreferenceChangeListener( - (preference, o) -> { - if (o instanceof String) { - setEpisodeCacheSizeText(UserPreferences.readEpisodeCacheSize((String) o)); - } - return true; - } - ); ui.findPreference(PREF_PROXY).setOnPreferenceClickListener(preference -> { ProxyDialog dialog = new ProxyDialog(ui.getActivity()); dialog.createDialog().show(); @@ -614,6 +624,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc case R.xml.preferences_downloads: setUpdateIntervalText(); setParallelDownloadsText(UserPreferences.getParallelDownloads()); + break; + case R.xml.preferences_autodownload: setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize()); checkAutodownloadItemVisibility(); break; @@ -897,7 +909,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc selectedNetworks = new CheckBoxPreference[networks.size()]; List prefValues = Arrays.asList(UserPreferences .getAutodownloadSelectedNetworks()); - PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); + PreferenceScreen prefScreen = ui.getPreferenceScreen(); Preference.OnPreferenceClickListener clickListener = preference -> { if (preference instanceof CheckBoxPreference) { String key = preference.getKey(); @@ -944,7 +956,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc private void clearAutodownloadSelectedNetworsPreference() { if (selectedNetworks != null) { - PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); + PreferenceScreen prefScreen = ui.getPreferenceScreen(); for (CheckBoxPreference network : selectedNetworks) { if (network != null) { @@ -1116,6 +1128,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc */ Preference findPreference(CharSequence key); + PreferenceScreen getPreferenceScreen(); + Activity getActivity(); } } diff --git a/app/src/main/res/xml/preferences_autodownload.xml b/app/src/main/res/xml/preferences_autodownload.xml new file mode 100644 index 000000000..2257db3eb --- /dev/null +++ b/app/src/main/res/xml/preferences_autodownload.xml @@ -0,0 +1,39 @@ + + + + + + + + + + diff --git a/app/src/main/res/xml/preferences_downloads.xml b/app/src/main/res/xml/preferences_downloads.xml index 2e9b8fcdb..d084a614c 100644 --- a/app/src/main/res/xml/preferences_downloads.xml +++ b/app/src/main/res/xml/preferences_downloads.xml @@ -23,44 +23,10 @@ android:key="prefAutoUpdateIntervall" android:summary="@string/pref_autoUpdateIntervallOrTime_sum" android:title="@string/pref_autoUpdateIntervallOrTime_title"/> - - - - - - - - + android:title="@string/pref_automatic_download_title" />