Skip to content

Commit

Permalink
Move auto-delete settings
Browse files Browse the repository at this point in the history
Users had a hard time understanding that automatic deletion and episode cleanup are two different things.
Maybe that is because in German, both got translated to the exact same string.
Now both are next to each other and the titles are updated, so that it hopefully causes less confusion.
  • Loading branch information
ByteHamster committed Apr 14, 2024
1 parent d9e84f8 commit 1b904f9
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 87 deletions.
@@ -0,0 +1,96 @@
package de.danoeh.antennapod.ui.screen.preferences;

import android.content.res.Resources;
import android.os.Bundle;
import androidx.preference.ListPreference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.TwoStatePreference;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.storage.preferences.UserPreferences;


public class AutomaticDeletionPreferencesFragment extends PreferenceFragmentCompat {
private static final String PREF_AUTO_DELETE_LOCAL = "prefAutoDeleteLocal";
private boolean blockAutoDeleteLocal = true;

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences_auto_deletion);
setupScreen();
buildEpisodeCleanupPreference();
checkItemVisibility(UserPreferences.isAutoDelete());
}

@Override
public void onStart() {
super.onStart();
((PreferenceActivity) getActivity()).getSupportActionBar().setTitle(R.string.auto_delete_label);
}

private void checkItemVisibility(boolean autoDeleteEnabled) {
findPreference(UserPreferences.PREF_FAVORITE_KEEPS_EPISODE).setEnabled(autoDeleteEnabled);
findPreference(PREF_AUTO_DELETE_LOCAL).setEnabled(autoDeleteEnabled);
}

private void setupScreen() {
if (!UserPreferences.isEnableAutodownload()) {
findPreference(UserPreferences.PREF_EPISODE_CLEANUP).setEnabled(false);
findPreference(UserPreferences.PREF_EPISODE_CLEANUP).setSummary(R.string.auto_download_disabled_globally);
}
findPreference(PREF_AUTO_DELETE_LOCAL).setOnPreferenceChangeListener((preference, newValue) -> {
if (blockAutoDeleteLocal && newValue == Boolean.TRUE) {
showAutoDeleteEnableDialog();
return false;
} else {
return true;
}
});
findPreference(UserPreferences.PREF_AUTO_DELETE).setOnPreferenceChangeListener((preference, newValue) -> {
if (newValue instanceof Boolean) {
checkItemVisibility((Boolean) newValue);
}
return true;
});
}

private void showAutoDeleteEnableDialog() {
new MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.pref_auto_local_delete_dialog_body)
.setPositiveButton(R.string.yes, (dialog, which) -> {
blockAutoDeleteLocal = false;
((TwoStatePreference) findPreference(PREF_AUTO_DELETE_LOCAL)).setChecked(true);
blockAutoDeleteLocal = true;
})
.setNegativeButton(R.string.cancel_label, null)
.show();
}


private void buildEpisodeCleanupPreference() {
final Resources res = getActivity().getResources();

ListPreference pref = findPreference(UserPreferences.PREF_EPISODE_CLEANUP);
String[] values = res.getStringArray(
de.danoeh.antennapod.ui.preferences.R.array.episode_cleanup_values);
String[] entries = new String[values.length];
for (int x = 0; x < values.length; x++) {
int v = Integer.parseInt(values[x]);
if (v == UserPreferences.EPISODE_CLEANUP_EXCEPT_FAVORITE) {
entries[x] = res.getString(R.string.episode_cleanup_except_favorite_removal);
} else if (v == UserPreferences.EPISODE_CLEANUP_QUEUE) {
entries[x] = res.getString(R.string.episode_cleanup_queue_removal);
} else if (v == UserPreferences.EPISODE_CLEANUP_NULL) {
entries[x] = res.getString(R.string.episode_cleanup_never);
} else if (v == 0) {
entries[x] = res.getString(R.string.episode_cleanup_after_listening);
} else if (v > 0 && v < 24) {
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_hours_after_listening, v, v);
} else {
int numDays = v / 24; // assume underlying value will be NOT fraction of days, e.g., 36 (hours)
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, numDays, numDays);
}
}
pref.setEntries(entries);
}
}
Expand Up @@ -2,29 +2,23 @@

import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceManager;
import androidx.preference.TwoStatePreference;

import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.net.download.serviceinterface.FeedUpdateManager;
import de.danoeh.antennapod.ui.preferences.screen.downloads.ChooseDataFolderDialog;
import de.danoeh.antennapod.storage.preferences.UserPreferences;
import de.danoeh.antennapod.ui.preferences.screen.downloads.ChooseDataFolderDialog;

import java.io.File;


public class DownloadsPreferencesFragment extends PreferenceFragmentCompat
implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String PREF_SCREEN_AUTODL = "prefAutoDownloadSettings";
private static final String PREF_AUTO_DELETE_LOCAL = "prefAutoDeleteLocal";
private static final String PREF_SCREEN_AUTO_DELETE = "prefAutoDeleteScreen";
private static final String PREF_PROXY = "prefProxy";
private static final String PREF_CHOOSE_DATA_DIR = "prefChooseDataDir";

private boolean blockAutoDeleteLocal = true;

@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
addPreferencesFromResource(R.xml.preferences_downloads);
Expand Down Expand Up @@ -55,6 +49,10 @@ private void setupNetworkScreen() {
((PreferenceActivity) getActivity()).openScreen(R.xml.preferences_autodownload);
return true;
});
findPreference(PREF_SCREEN_AUTO_DELETE).setOnPreferenceClickListener(preference -> {
((PreferenceActivity) getActivity()).openScreen(R.xml.preferences_auto_deletion);
return true;
});
// validate and set correct value: number of downloads between 1 and 50 (inclusive)
findPreference(PREF_PROXY).setOnPreferenceClickListener(preference -> {
ProxyDialog dialog = new ProxyDialog(getActivity());
Expand All @@ -68,14 +66,6 @@ private void setupNetworkScreen() {
});
return true;
});
findPreference(PREF_AUTO_DELETE_LOCAL).setOnPreferenceChangeListener((preference, newValue) -> {
if (blockAutoDeleteLocal && newValue == Boolean.TRUE) {
showAutoDeleteEnableDialog();
return false;
} else {
return true;
}
});
}

private void setDataFolderText() {
Expand All @@ -91,16 +81,4 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
FeedUpdateManager.getInstance().restartUpdateAlarm(getContext(), true);
}
}

private void showAutoDeleteEnableDialog() {
new MaterialAlertDialogBuilder(requireContext())
.setMessage(R.string.pref_auto_local_delete_dialog_body)
.setPositiveButton(R.string.yes, (dialog, which) -> {
blockAutoDeleteLocal = false;
((TwoStatePreference) findPreference(PREF_AUTO_DELETE_LOCAL)).setChecked(true);
blockAutoDeleteLocal = true;
})
.setNegativeButton(R.string.cancel_label, null)
.show();
}
}
Expand Up @@ -83,6 +83,8 @@ private PreferenceFragmentCompat getPreferenceScreen(int screen) {
prefFragment = new NotificationPreferencesFragment();
} else if (screen == R.xml.preferences_swipe) {
prefFragment = new SwipePreferencesFragment();
} else if (screen == R.xml.preferences_auto_deletion) {
prefFragment = new AutomaticDeletionPreferencesFragment();
}
return prefFragment;
}
Expand All @@ -106,6 +108,8 @@ public static int getTitleOfPage(int preferences) {
return R.string.feed_settings_label;
} else if (preferences == R.xml.preferences_swipe) {
return R.string.swipeactions_label;
} else if (preferences == R.xml.preferences_auto_deletion) {
return R.string.auto_delete_label;
}
return R.string.settings_label;
}
Expand Down
Expand Up @@ -80,8 +80,8 @@ public abstract class UserPreferences {
public static final String PREF_HARDWARE_PREVIOUS_BUTTON = "prefHardwarePreviousButton";
public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue";
public static final String PREF_SKIP_KEEPS_EPISODE = "prefSkipKeepsEpisode";
private static final String PREF_FAVORITE_KEEPS_EPISODE = "prefFavoriteKeepsEpisode";
private static final String PREF_AUTO_DELETE = "prefAutoDelete";
public static final String PREF_FAVORITE_KEEPS_EPISODE = "prefFavoriteKeepsEpisode";
public static final String PREF_AUTO_DELETE = "prefAutoDelete";
private static final String PREF_AUTO_DELETE_LOCAL = "prefAutoDeleteLocal";
public static final String PREF_SMART_MARK_AS_PLAYED_SECS = "prefSmartMarkAsPlayedSecs";
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
Expand Down
6 changes: 3 additions & 3 deletions ui/i18n/src/main/res/values/strings.xml
Expand Up @@ -385,7 +385,7 @@
<string name="preference_search_hint">Search…</string>
<string name="preference_search_no_results">No results</string>
<string name="preference_search_clear_history">Clear history</string>
<string name="pref_episode_cleanup_title">Episode cleanup</string>
<string name="pref_episode_cleanup_title">Delete before auto download</string>
<string name="pref_episode_cleanup_summary">Episodes that should be eligible for removal if Auto Download needs space for new episodes</string>
<string name="pref_pauseOnDisconnect_sum">Pause playback when headphones or bluetooth are disconnected</string>
<string name="pref_unpauseOnHeadsetReconnect_sum">Resume playback when the headphones are reconnected</string>
Expand Down Expand Up @@ -455,8 +455,8 @@
<string name="pref_autodl_wifi_filter_sum">Allow automatic download only for selected Wi-Fi networks.</string>
<string name="pref_automatic_download_on_battery_title">Download when not charging</string>
<string name="pref_automatic_download_on_battery_sum">Allow automatic download when the battery is not charging</string>
<string name="pref_episode_cache_title">Episode cache</string>
<string name="pref_episode_cache_summary">Total number of downloaded episodes cached on the device. Automatic download will be suspended if this number is reached.</string>
<string name="pref_episode_cache_title">Episode limit</string>
<string name="pref_episode_cache_summary">Automatic download is stopped if this number is reached</string>
<string name="pref_episode_cover_title">Use episode cover</string>
<string name="pref_episode_cover_summary">Use the episode specific cover in lists whenever available. If unchecked, the app will always use the podcast cover image.</string>
<string name="pref_show_remain_time_title">Show remaining time</string>
Expand Down
Expand Up @@ -3,15 +3,13 @@
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.CheckBoxPreference;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceFragmentCompat;
import androidx.preference.PreferenceScreen;
Expand All @@ -35,7 +33,6 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setupAutoDownloadScreen();
buildAutodownloadSelectedNetworksPreference();
setSelectedNetworksEnabled(UserPreferences.isEnableAutodownloadWifiFilter());
buildEpisodeCleanupPreference();
}

@Override
Expand Down Expand Up @@ -78,7 +75,6 @@ private void checkAutodownloadItemVisibility(boolean autoDownload) {
findPreference(UserPreferences.PREF_EPISODE_CACHE_SIZE).setEnabled(autoDownload);
findPreference(UserPreferences.PREF_ENABLE_AUTODL_ON_BATTERY).setEnabled(autoDownload);
findPreference(UserPreferences.PREF_ENABLE_AUTODL_WIFI_FILTER).setEnabled(autoDownload);
findPreference(UserPreferences.PREF_EPISODE_CLEANUP).setEnabled(autoDownload);
setSelectedNetworksEnabled(autoDownload && UserPreferences.isEnableAutodownloadWifiFilter());
}

Expand Down Expand Up @@ -165,33 +161,6 @@ private void clearAutodownloadSelectedNetworsPreference() {
}
}

private void buildEpisodeCleanupPreference() {
final Resources res = getActivity().getResources();

ListPreference pref = findPreference(UserPreferences.PREF_EPISODE_CLEANUP);
String[] values = res.getStringArray(
R.array.episode_cleanup_values);
String[] entries = new String[values.length];
for (int x = 0; x < values.length; x++) {
int v = Integer.parseInt(values[x]);
if (v == UserPreferences.EPISODE_CLEANUP_EXCEPT_FAVORITE) {
entries[x] = res.getString(R.string.episode_cleanup_except_favorite_removal);
} else if (v == UserPreferences.EPISODE_CLEANUP_QUEUE) {
entries[x] = res.getString(R.string.episode_cleanup_queue_removal);
} else if (v == UserPreferences.EPISODE_CLEANUP_NULL){
entries[x] = res.getString(R.string.episode_cleanup_never);
} else if (v == 0) {
entries[x] = res.getString(R.string.episode_cleanup_after_listening);
} else if (v > 0 && v < 24) {
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_hours_after_listening, v, v);
} else {
int numDays = v / 24; // assume underlying value will be NOT fraction of days, e.g., 36 (hours)
entries[x] = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, numDays, numDays);
}
}
pref.setEntries(entries);
}

private void setSelectedNetworksEnabled(boolean b) {
if (selectedNetworks != null) {
for (Preference p : selectedNetworks) {
Expand Down
31 changes: 31 additions & 0 deletions ui/preferences/src/main/res/xml/preferences_auto_deletion.xml
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">

<SwitchPreferenceCompat
android:defaultValue="false"
android:enabled="true"
android:key="prefAutoDelete"
android:summary="@string/pref_auto_delete_sum"
android:title="@string/pref_auto_delete_title"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:enabled="true"
android:key="prefAutoDeleteLocal"
android:summary="@string/pref_auto_local_delete_sum"
android:title="@string/pref_auto_local_delete_title"/>
<SwitchPreferenceCompat
android:defaultValue="true"
android:enabled="true"
android:key="prefFavoriteKeepsEpisode"
android:summary="@string/pref_favorite_keeps_episodes_sum"
android:title="@string/pref_favorite_keeps_episodes_title"/>
<de.danoeh.antennapod.ui.preferences.preference.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"/>

</PreferenceScreen>
7 changes: 0 additions & 7 deletions ui/preferences/src/main/res/xml/preferences_autodownload.xml
Expand Up @@ -15,13 +15,6 @@
android:title="@string/pref_episode_cache_title"
android:summary="@string/pref_episode_cache_summary"
android:entryValues="@array/episode_cache_size_values"/>
<de.danoeh.antennapod.ui.preferences.preference.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"/>
<SwitchPreferenceCompat
android:key="prefEnableAutoDownloadOnBattery"
android:title="@string/pref_automatic_download_on_battery_title"
Expand Down
18 changes: 2 additions & 16 deletions ui/preferences/src/main/res/xml/preferences_downloads.xml
Expand Up @@ -27,24 +27,10 @@
android:key="prefAutoDownloadSettings"
android:title="@string/pref_automatic_download_title"
search:ignore="true" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:enabled="true"
android:key="prefAutoDelete"
<Preference
android:key="prefAutoDeleteScreen"
android:summary="@string/pref_auto_delete_sum"
android:title="@string/pref_auto_delete_title"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:enabled="true"
android:key="prefAutoDeleteLocal"
android:summary="@string/pref_auto_local_delete_sum"
android:title="@string/pref_auto_local_delete_title"/>
<SwitchPreferenceCompat
android:defaultValue="true"
android:enabled="true"
android:key="prefFavoriteKeepsEpisode"
android:summary="@string/pref_favorite_keeps_episodes_sum"
android:title="@string/pref_favorite_keeps_episodes_title"/>
<SwitchPreferenceCompat
android:defaultValue="false"
android:enabled="true"
Expand Down

0 comments on commit 1b904f9

Please sign in to comment.