Compare commits

...

3 Commits

Author SHA1 Message Date
ByteHamster 4cdd348b0e
Merge 4b07740b9e into a61f548792 2024-05-08 14:15:29 +02:00
ByteHamster a61f548792
Fix settings toolbar having color (#7169) 2024-05-08 07:46:25 +02:00
ByteHamster 4b07740b9e Move auto-delete settings
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.
2024-04-14 14:59:55 +02:00
11 changed files with 161 additions and 94 deletions

View File

@ -173,6 +173,7 @@ public class PreferencesTest {
@Test
public void testAutoDelete() {
clickPreference(R.string.downloads_pref);
onView(withText(R.string.pref_auto_delete_title)).perform(click());
final boolean autoDelete = UserPreferences.isAutoDelete();
onView(withText(R.string.pref_auto_delete_title)).perform(click());
Awaitility.await().atMost(1000, MILLISECONDS)
@ -185,8 +186,10 @@ public class PreferencesTest {
@Test
public void testAutoDeleteLocal() {
clickPreference(R.string.downloads_pref);
final boolean initialAutoDelete = UserPreferences.isAutoDeleteLocal();
assertFalse(initialAutoDelete);
onView(withText(R.string.pref_auto_delete_title)).perform(click());
onView(withText(R.string.pref_auto_delete_title)).perform(click());
assertTrue(UserPreferences.isAutoDelete());
assertFalse(UserPreferences.isAutoDeleteLocal());
onView(withText(R.string.pref_auto_local_delete_title)).perform(click());
onView(withText(R.string.yes)).perform(click());
@ -289,7 +292,7 @@ public class PreferencesTest {
@Test
public void testEpisodeCleanupFavoriteOnly() {
clickPreference(R.string.downloads_pref);
onView(withText(R.string.pref_automatic_download_title)).perform(click());
onView(withText(R.string.pref_auto_delete_title)).perform(click());
onView(withText(R.string.pref_episode_cleanup_title)).perform(click());
onView(withId(R.id.select_dialog_listview)).perform(swipeDown());
onView(withText(R.string.episode_cleanup_except_favorite_removal)).perform(click());
@ -300,7 +303,7 @@ public class PreferencesTest {
@Test
public void testEpisodeCleanupQueueOnly() {
clickPreference(R.string.downloads_pref);
onView(withText(R.string.pref_automatic_download_title)).perform(click());
onView(withText(R.string.pref_auto_delete_title)).perform(click());
onView(withText(R.string.pref_episode_cleanup_title)).perform(click());
onView(withId(R.id.select_dialog_listview)).perform(swipeDown());
onView(withText(R.string.episode_cleanup_queue_removal)).perform(click());
@ -311,7 +314,7 @@ public class PreferencesTest {
@Test
public void testEpisodeCleanupNeverAlg() {
clickPreference(R.string.downloads_pref);
onView(withText(R.string.pref_automatic_download_title)).perform(click());
onView(withText(R.string.pref_auto_delete_title)).perform(click());
onView(withText(R.string.pref_episode_cleanup_title)).perform(click());
onView(withId(R.id.select_dialog_listview)).perform(swipeUp());
onView(withText(R.string.episode_cleanup_never)).perform(click());
@ -322,7 +325,7 @@ public class PreferencesTest {
@Test
public void testEpisodeCleanupClassic() {
clickPreference(R.string.downloads_pref);
onView(withText(R.string.pref_automatic_download_title)).perform(click());
onView(withText(R.string.pref_auto_delete_title)).perform(click());
onView(withText(R.string.pref_episode_cleanup_title)).perform(click());
onView(withText(R.string.episode_cleanup_after_listening)).perform(click());
Awaitility.await().atMost(1000, MILLISECONDS)
@ -339,7 +342,7 @@ public class PreferencesTest {
@Test
public void testEpisodeCleanupNumDays() {
clickPreference(R.string.downloads_pref);
clickPreference(R.string.pref_automatic_download_title);
onView(withText(R.string.pref_auto_delete_title)).perform(click());
clickPreference(R.string.pref_episode_cleanup_title);
String search = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, 3, 3);
onView(withText(search)).perform(scrollTo());

View File

@ -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);
}
}

View File

@ -2,16 +2,12 @@ package de.danoeh.antennapod.ui.screen.preferences;
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;
@ -19,12 +15,10 @@ 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);
@ -55,6 +49,10 @@ public class DownloadsPreferencesFragment extends PreferenceFragmentCompat
((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());
@ -68,14 +66,6 @@ public class DownloadsPreferencesFragment extends PreferenceFragmentCompat
});
return true;
});
findPreference(PREF_AUTO_DELETE_LOCAL).setOnPreferenceChangeListener((preference, newValue) -> {
if (blockAutoDeleteLocal && newValue == Boolean.TRUE) {
showAutoDeleteEnableDialog();
return false;
} else {
return true;
}
});
}
private void setDataFolderText() {
@ -91,16 +81,4 @@ public class DownloadsPreferencesFragment extends PreferenceFragmentCompat
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();
}
}

View File

@ -83,6 +83,8 @@ public class PreferenceActivity extends AppCompatActivity implements SearchPrefe
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;
}
@ -106,6 +108,8 @@ public class PreferenceActivity extends AppCompatActivity implements SearchPrefe
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;
}

View File

@ -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";

View File

@ -12,6 +12,7 @@
<style name="Theme.Base.AntennaPod.Dynamic.Light" parent="Theme.Material3.DynamicColors.Light">
<item name="progressBarTheme">@style/ProgressBarLight</item>
<item name="background_color">@color/background_light</item>
<item name="actionBarStyle">@style/Widget.AntennaPod.ActionBar</item>
<item name="background_elevated">@color/background_elevated_light</item>
<item name="action_icon_color">@color/black</item>
<item name="android:textAllCaps">false</item>
@ -54,6 +55,7 @@
<item name="background_color">@color/background_darktheme</item>
<item name="background_elevated">@color/background_elevated_darktheme</item>
<item name="action_icon_color">@color/white</item>
<item name="actionBarStyle">@style/Widget.AntennaPod.ActionBar</item>
<item name="android:textAllCaps">false</item>
<item name="seek_background">@color/seek_background_dark</item>
<item name="dragview_background">@drawable/ic_drag_darktheme</item>
@ -289,6 +291,11 @@
<item name="fastScrollVerticalTrackDrawable">@drawable/scrollbar_track</item>
</style>
<style name="Widget.AntennaPod.ActionBar" parent="Widget.Material3.Light.ActionBar.Solid">
<item name="background">?android:attr/colorBackground</item>
<item name="elevation">0dp</item>
</style>
<style name="AddPodcastTextView">
<item name="android:drawablePadding">8dp</item>
<item name="android:paddingTop">8dp</item>

View File

@ -386,7 +386,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>
@ -456,8 +456,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>

View File

@ -3,7 +3,6 @@ package de.danoeh.antennapod.ui.preferences.screen;
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;
@ -11,7 +10,6 @@ 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;
@ -35,7 +33,6 @@ public class AutoDownloadPreferencesFragment extends PreferenceFragmentCompat {
setupAutoDownloadScreen();
buildAutodownloadSelectedNetworksPreference();
setSelectedNetworksEnabled(UserPreferences.isEnableAutodownloadWifiFilter());
buildEpisodeCleanupPreference();
}
@Override
@ -78,7 +75,6 @@ public class AutoDownloadPreferencesFragment extends PreferenceFragmentCompat {
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());
}
@ -165,33 +161,6 @@ public class AutoDownloadPreferencesFragment extends PreferenceFragmentCompat {
}
}
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) {

View File

@ -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>

View File

@ -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"

View File

@ -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"