Moved autodownload to new file

This commit is contained in:
ByteHamster 2018-04-22 18:12:40 +02:00
parent 33e695b519
commit a64c996e9c
4 changed files with 80 additions and 53 deletions

View File

@ -5,6 +5,7 @@ import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceScreen;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.view.Menu; import android.view.Menu;
@ -40,6 +41,11 @@ public class PreferenceActivity extends AppCompatActivity {
return fragment.findPreference(key); return fragment.findPreference(key);
} }
@Override
public PreferenceScreen getPreferenceScreen() {
return fragment.getPreferenceScreen();
}
@Override @Override
public Activity getActivity() { public Activity getActivity() {
return PreferenceActivity.this; return PreferenceActivity.this;
@ -135,6 +141,8 @@ public class PreferenceActivity extends AppCompatActivity {
switch (preferences) { switch (preferences) {
case R.xml.preferences_downloads: case R.xml.preferences_downloads:
return R.string.downloads_label; return R.string.downloads_label;
case R.xml.preferences_autodownload:
return R.string.pref_automatic_download_title;
case R.xml.preferences_playback: case R.xml.preferences_playback:
return R.string.playback_pref; return R.string.playback_pref;
case R.xml.preferences_storage: case R.xml.preferences_storage:

View File

@ -22,6 +22,7 @@ import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference; import android.preference.EditTextPreference;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.preference.PreferenceScreen; import android.preference.PreferenceScreen;
@ -166,6 +167,9 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
break; break;
case R.xml.preferences_downloads: case R.xml.preferences_downloads:
setupDownloadsScreen(); setupDownloadsScreen();
break;
case R.xml.preferences_autodownload:
setupAutoDownloadScreen();
buildAutodownloadSelectedNetworsPreference(); buildAutodownloadSelectedNetworsPreference();
setSelectedNetworksEnabled(UserPreferences.isEnableAutodownloadWifiFilter()); setSelectedNetworksEnabled(UserPreferences.isEnableAutodownloadWifiFilter());
buildEpisodeCleanupPreference(); buildEpisodeCleanupPreference();
@ -398,12 +402,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
} }
} }
private void setupDownloadsScreen() { private void setupAutoDownloadScreen() {
ui.findPreference(UserPreferences.PREF_UPDATE_INTERVAL)
.setOnPreferenceClickListener(preference -> {
showUpdateIntervalTimePreferencesDialog();
return true;
});
ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL).setOnPreferenceChangeListener( ui.findPreference(UserPreferences.PREF_ENABLE_AUTODL).setOnPreferenceChangeListener(
(preference, newValue) -> { (preference, newValue) -> {
if (newValue instanceof Boolean) { 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) ui.findPreference(UserPreferences.PREF_PARALLEL_DOWNLOADS)
.setOnPreferenceChangeListener( .setOnPreferenceChangeListener(
(preference, o) -> { (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 -> { ui.findPreference(PREF_PROXY).setOnPreferenceClickListener(preference -> {
ProxyDialog dialog = new ProxyDialog(ui.getActivity()); ProxyDialog dialog = new ProxyDialog(ui.getActivity());
dialog.createDialog().show(); dialog.createDialog().show();
@ -614,6 +624,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
case R.xml.preferences_downloads: case R.xml.preferences_downloads:
setUpdateIntervalText(); setUpdateIntervalText();
setParallelDownloadsText(UserPreferences.getParallelDownloads()); setParallelDownloadsText(UserPreferences.getParallelDownloads());
break;
case R.xml.preferences_autodownload:
setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize()); setEpisodeCacheSizeText(UserPreferences.getEpisodeCacheSize());
checkAutodownloadItemVisibility(); checkAutodownloadItemVisibility();
break; break;
@ -897,7 +909,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
selectedNetworks = new CheckBoxPreference[networks.size()]; selectedNetworks = new CheckBoxPreference[networks.size()];
List<String> prefValues = Arrays.asList(UserPreferences List<String> prefValues = Arrays.asList(UserPreferences
.getAutodownloadSelectedNetworks()); .getAutodownloadSelectedNetworks());
PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); PreferenceScreen prefScreen = ui.getPreferenceScreen();
Preference.OnPreferenceClickListener clickListener = preference -> { Preference.OnPreferenceClickListener clickListener = preference -> {
if (preference instanceof CheckBoxPreference) { if (preference instanceof CheckBoxPreference) {
String key = preference.getKey(); String key = preference.getKey();
@ -944,7 +956,7 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
private void clearAutodownloadSelectedNetworsPreference() { private void clearAutodownloadSelectedNetworsPreference() {
if (selectedNetworks != null) { if (selectedNetworks != null) {
PreferenceScreen prefScreen = (PreferenceScreen) ui.findPreference(PreferenceController.AUTO_DL_PREF_SCREEN); PreferenceScreen prefScreen = ui.getPreferenceScreen();
for (CheckBoxPreference network : selectedNetworks) { for (CheckBoxPreference network : selectedNetworks) {
if (network != null) { if (network != null) {
@ -1116,6 +1128,8 @@ public class PreferenceController implements SharedPreferences.OnSharedPreferenc
*/ */
Preference findPreference(CharSequence key); Preference findPreference(CharSequence key);
PreferenceScreen getPreferenceScreen();
Activity getActivity(); Activity getActivity();
} }
} }

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDl"
android:title="@string/pref_automatic_download_title"
android:defaultValue="false"/>
<com.afollestad.materialdialogs.prefs.MaterialListPreference
android:defaultValue="25"
android:entries="@array/episode_cache_size_entries"
android:key="prefEpisodeCacheSize"
android:title="@string/pref_episode_cache_title"
android:entryValues="@array/episode_cache_size_values"
app:useStockLayout="true"/>
<com.afollestad.materialdialogs.prefs.MaterialListPreference
android:defaultValue="-1"
android:entries="@array/episode_cleanup_entries"
android:key="prefEpisodeCleanup"
android:title="@string/pref_episode_cleanup_title"
android:summary="@string/pref_episode_cleanup_summary"
android:entryValues="@array/episode_cleanup_values"
app:useStockLayout="true"/>
<de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDownloadOnBattery"
android:title="@string/pref_automatic_download_on_battery_title"
android:summary="@string/pref_automatic_download_on_battery_sum"
android:defaultValue="true"/>
<de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDownloadOnMobile"
android:title="@string/pref_autodl_allow_on_mobile_title"
android:summary="@string/pref_autodl_allow_on_mobile_sum"
android:defaultValue="false"/>
<de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDownloadWifiFilter"
android:title="@string/pref_autodl_wifi_filter_title"
android:summary="@string/pref_autodl_wifi_filter_sum"/>
</PreferenceScreen>

View File

@ -23,44 +23,10 @@
android:key="prefAutoUpdateIntervall" android:key="prefAutoUpdateIntervall"
android:summary="@string/pref_autoUpdateIntervallOrTime_sum" android:summary="@string/pref_autoUpdateIntervallOrTime_sum"
android:title="@string/pref_autoUpdateIntervallOrTime_title"/> android:title="@string/pref_autoUpdateIntervallOrTime_title"/>
<PreferenceScreen <Preference
android:summary="@string/pref_automatic_download_sum" android:summary="@string/pref_automatic_download_sum"
android:key="prefAutoDownloadSettings" android:key="prefAutoDownloadSettings"
android:title="@string/pref_automatic_download_title"> android:title="@string/pref_automatic_download_title" />
<de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDl"
android:title="@string/pref_automatic_download_title"
android:defaultValue="false"/>
<com.afollestad.materialdialogs.prefs.MaterialListPreference
android:defaultValue="25"
android:entries="@array/episode_cache_size_entries"
android:key="prefEpisodeCacheSize"
android:title="@string/pref_episode_cache_title"
android:entryValues="@array/episode_cache_size_values"
app:useStockLayout="true"/>
<com.afollestad.materialdialogs.prefs.MaterialListPreference
android:defaultValue="-1"
android:entries="@array/episode_cleanup_entries"
android:key="prefEpisodeCleanup"
android:title="@string/pref_episode_cleanup_title"
android:summary="@string/pref_episode_cleanup_summary"
android:entryValues="@array/episode_cleanup_values"
app:useStockLayout="true"/>
<de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDownloadOnBattery"
android:title="@string/pref_automatic_download_on_battery_title"
android:summary="@string/pref_automatic_download_on_battery_sum"
android:defaultValue="true"/>
<de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDownloadOnMobile"
android:title="@string/pref_autodl_allow_on_mobile_title"
android:summary="@string/pref_autodl_allow_on_mobile_sum"
android:defaultValue="false"/>
<de.danoeh.antennapod.preferences.SwitchCompatPreference
android:key="prefEnableAutoDownloadWifiFilter"
android:title="@string/pref_autodl_wifi_filter_title"
android:summary="@string/pref_autodl_wifi_filter_sum"/>
</PreferenceScreen>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/download_pref_details"> <PreferenceCategory android:title="@string/download_pref_details">