Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
d9e84f8
commit 4b07740
Showing
10 changed files
with
154 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
...java/de/danoeh/antennapod/ui/screen/preferences/AutomaticDeletionPreferencesFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
ui/preferences/src/main/res/xml/preferences_auto_deletion.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
Oops, something went wrong.