diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index 4947d5a87..4b926200d 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -276,12 +276,22 @@ public class QueueFragment extends Fragment { MenuItemUtils.refreshLockItem(getActivity(), menu); - // Show Lock Item and Sort Item only if queue is sorted manually - boolean sortedManually = UserPreferences.isQueueSortedManually(); + // Show Lock Item only if queue is sorted manually + boolean sortedAutomatically = UserPreferences.isQueueSortedAutomatically(); MenuItem lockItem = menu.findItem(R.id.queue_lock); - lockItem.setVisible(sortedManually); - MenuItem sortItem = menu.findItem(R.id.queue_sort); - sortItem.setVisible(sortedManually); + lockItem.setVisible(!sortedAutomatically); + + // Set keep sorted checkbox + MenuItem sortedAutomaticallyItem = menu.findItem(R.id.queue_sort_automatically); + sortedAutomaticallyItem.setChecked(sortedAutomatically); + + // Hide sort menu items for sort orders that are not supported by automatic sort. + MenuItem sortRandomItem = menu.findItem(R.id.queue_sort_random); + sortRandomItem.setVisible(!sortedAutomatically); + MenuItem sortSmart1Item = menu.findItem(R.id.queue_sort_smart_shuffle_asc); + sortSmart1Item.setVisible(!sortedAutomatically); + MenuItem sortSmart2Item = menu.findItem(R.id.queue_sort_smart_shuffle_desc); + sortSmart2Item.setVisible(!sortedAutomatically); isUpdatingFeeds = MenuItemUtils.updateRefreshMenuItem(menu, R.id.refresh_item, updateRefreshMenuItemChecker); } @@ -331,38 +341,52 @@ public class QueueFragment extends Fragment { ((MainActivity) requireActivity()) .loadChildFragment( EpisodesApplyActionFragment.newInstance(queue, ACTION_DELETE | ACTION_REMOVE_FROM_QUEUE)); return true; + case R.id.queue_sort_automatically: + boolean sortedAutomaticallyOld = UserPreferences.isQueueSortedAutomatically(); + boolean sortedAutomaticallyNew = !sortedAutomaticallyOld; + if (sortedAutomaticallyNew) { + // We have to choose an initially sort order, let's sort by episode date + UserPreferences.QueueSortOrder sortOrder = UserPreferences.QueueSortOrder.DATE_NEW_OLD; + UserPreferences.setQueueSortOrder(sortOrder); + QueueSorter.sort(QueueSorter.queueSortOrder2Rule(sortOrder), true); + } else { + UserPreferences.setQueueSortOrder(UserPreferences.QueueSortOrder.MANUALLY); + } + // Update sort menu items visibility and state + getActivity().invalidateOptionsMenu(); + return true; case R.id.queue_sort_episode_title_asc: - QueueSorter.sort(QueueSorter.Rule.EPISODE_TITLE_ASC, true); + queueSortOrderChanged(QueueSorter.Rule.EPISODE_TITLE_ASC); return true; case R.id.queue_sort_episode_title_desc: - QueueSorter.sort(QueueSorter.Rule.EPISODE_TITLE_DESC, true); + queueSortOrderChanged(QueueSorter.Rule.EPISODE_TITLE_DESC); return true; case R.id.queue_sort_date_asc: - QueueSorter.sort(QueueSorter.Rule.DATE_ASC, true); + queueSortOrderChanged(QueueSorter.Rule.DATE_ASC); return true; case R.id.queue_sort_date_desc: - QueueSorter.sort(QueueSorter.Rule.DATE_DESC, true); + queueSortOrderChanged(QueueSorter.Rule.DATE_DESC); return true; case R.id.queue_sort_duration_asc: - QueueSorter.sort(QueueSorter.Rule.DURATION_ASC, true); + queueSortOrderChanged(QueueSorter.Rule.DURATION_ASC); return true; case R.id.queue_sort_duration_desc: - QueueSorter.sort(QueueSorter.Rule.DURATION_DESC, true); + queueSortOrderChanged(QueueSorter.Rule.DURATION_DESC); return true; case R.id.queue_sort_feed_title_asc: - QueueSorter.sort(QueueSorter.Rule.FEED_TITLE_ASC, true); + queueSortOrderChanged(QueueSorter.Rule.FEED_TITLE_ASC); return true; case R.id.queue_sort_feed_title_desc: - QueueSorter.sort(QueueSorter.Rule.FEED_TITLE_DESC, true); + queueSortOrderChanged(QueueSorter.Rule.FEED_TITLE_DESC); return true; case R.id.queue_sort_random: - QueueSorter.sort(QueueSorter.Rule.RANDOM, true); + queueSortOrderChanged(QueueSorter.Rule.RANDOM); return true; case R.id.queue_sort_smart_shuffle_asc: - QueueSorter.sort(QueueSorter.Rule.SMART_SHUFFLE_ASC, true); + queueSortOrderChanged(QueueSorter.Rule.SMART_SHUFFLE_ASC); return true; case R.id.queue_sort_smart_shuffle_desc: - QueueSorter.sort(QueueSorter.Rule.SMART_SHUFFLE_DESC, true); + queueSortOrderChanged(QueueSorter.Rule.SMART_SHUFFLE_DESC); return true; default: return false; @@ -372,6 +396,22 @@ public class QueueFragment extends Fragment { } } + /** + * Sorts the queue on user interaction. + * If the queue is sorted automatically, the new sort order is stored in the preferences. + * + * @param rule Sort rule. + */ + private void queueSortOrderChanged(QueueSorter.Rule rule) { + boolean sortedAutomatically = UserPreferences.isQueueSortedAutomatically(); + UserPreferences.QueueSortOrder sortOrder = QueueSorter.rule2QueueSortOrder(rule); + // remember sort order to keep queue sorted + if (sortedAutomatically && sortOrder != null) { + UserPreferences.setQueueSortOrder(sortOrder); + } + // Sort queue + QueueSorter.sort(rule, true); + } @Override public boolean onContextItemSelected(MenuItem item) { diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java index db852cee7..8c0e0295f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/preferences/UserInterfacePreferencesFragment.java @@ -11,11 +11,7 @@ import android.widget.ListView; import android.widget.Toast; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; -import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.preferences.UserPreferences; -import de.danoeh.antennapod.core.storage.DBWriter; -import de.danoeh.antennapod.core.util.Permutor; -import de.danoeh.antennapod.core.util.QueueSorter; import org.apache.commons.lang3.ArrayUtils; @@ -94,17 +90,6 @@ public class UserInterfacePreferencesFragment extends PreferenceFragmentCompat { if (Build.VERSION.SDK_INT >= 26) { findPreference(UserPreferences.PREF_EXPANDED_NOTIFICATION).setVisible(false); } - - findPreference(UserPreferences.PREF_QUEUE_SORT_ORDER) - .setOnPreferenceChangeListener((preference, newValue) -> { - UserPreferences.QueueSortOrder newSortOrder = UserPreferences.parseQueueSortOrder((String) newValue); - if (newSortOrder != UserPreferences.QueueSortOrder.MANUALLY) { - QueueSorter.Rule sortRule = QueueSorter.queueSortOrder2Rule(newSortOrder); - Permutor permutor = QueueSorter.getPermutor(sortRule); - DBWriter.reorderQueue(permutor, true); - } - return true; - }); } private void showDrawerPreferencesDialog() { diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java index 0c7622a47..5d6af35da 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedItemMenuHandler.java @@ -15,7 +15,6 @@ import de.danoeh.antennapod.core.gpoddernet.model.GpodnetEpisodeAction.Action; import de.danoeh.antennapod.core.preferences.GpodnetPreferences; import de.danoeh.antennapod.core.preferences.UserPreferences; import de.danoeh.antennapod.core.service.playback.PlaybackService; -import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.IntentUtils; @@ -68,17 +67,17 @@ public class FeedItemMenuHandler { } boolean hasMedia = selectedItem.getMedia() != null; boolean isPlaying = hasMedia && selectedItem.getState() == FeedItem.State.PLAYING; - boolean sortedManually = UserPreferences.isQueueSortedManually(); + boolean sortedAutomatically = UserPreferences.isQueueSortedAutomatically(); if (!isPlaying) { mi.setItemVisibility(R.id.skip_episode_item, false); } boolean isInQueue = selectedItem.isTagged(FeedItem.TAG_QUEUE); - if (queueAccess == null || queueAccess.size() == 0 || queueAccess.get(0) == selectedItem.getId() || !sortedManually) { + if (queueAccess == null || queueAccess.size() == 0 || queueAccess.get(0) == selectedItem.getId() || sortedAutomatically) { mi.setItemVisibility(R.id.move_to_top_item, false); } - if (queueAccess == null || queueAccess.size() == 0 || queueAccess.get(queueAccess.size()-1) == selectedItem.getId() || !sortedManually) { + if (queueAccess == null || queueAccess.size() == 0 || queueAccess.get(queueAccess.size()-1) == selectedItem.getId() || sortedAutomatically) { mi.setItemVisibility(R.id.move_to_bottom_item, false); } if (!isInQueue) { diff --git a/app/src/main/res/menu/queue.xml b/app/src/main/res/menu/queue.xml index 0f7729be1..99f0fd950 100644 --- a/app/src/main/res/menu/queue.xml +++ b/app/src/main/res/menu/queue.xml @@ -28,6 +28,11 @@ android:title="@string/sort"> + + diff --git a/app/src/main/res/xml/preferences_user_interface.xml b/app/src/main/res/xml/preferences_user_interface.xml index 455838048..1d970a5f7 100644 --- a/app/src/main/res/xml/preferences_user_interface.xml +++ b/app/src/main/res/xml/preferences_user_interface.xml @@ -32,14 +32,6 @@ android:summary="@string/pref_nav_drawer_feed_counter_sum" android:defaultValue="0" app:useStockLayout="true"/> - queue, List events) { - if (UserPreferences.isQueueSortedManually()) { + if (!UserPreferences.isQueueSortedAutomatically()) { // automatic sort order is disabled, don't change anything return; } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/QueueSorter.java b/core/src/main/java/de/danoeh/antennapod/core/util/QueueSorter.java index 8bc377ffa..56402f940 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/QueueSorter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/QueueSorter.java @@ -149,6 +149,38 @@ public class QueueSorter { } } + /** + * Converts a Rule value to its corresponding QueueSortOrder value. + * + * @param rule Rule value. + * @return QueueSortOrder value corresponding to the given Rule value. null if the Rule value is unsupported or null. + */ + public static UserPreferences.QueueSortOrder rule2QueueSortOrder(Rule rule) { + if (rule == null) { + return null; + } + switch (rule) { + case EPISODE_TITLE_ASC: + return UserPreferences.QueueSortOrder.EPISODE_TITLE_A_Z; + case EPISODE_TITLE_DESC: + return UserPreferences.QueueSortOrder.EPISODE_TITLE_Z_A; + case DATE_ASC: + return UserPreferences.QueueSortOrder.DATE_OLD_NEW; + case DATE_DESC: + return UserPreferences.QueueSortOrder.DATE_NEW_OLD; + case DURATION_ASC: + return UserPreferences.QueueSortOrder.DURATION_SHORT_LONG; + case DURATION_DESC: + return UserPreferences.QueueSortOrder.DURATION_LONG_SHORT; + case FEED_TITLE_ASC: + return UserPreferences.QueueSortOrder.FEED_TITLE_A_Z; + case FEED_TITLE_DESC: + return UserPreferences.QueueSortOrder.FEED_TITLE_Z_A; + default: + return null; + } + } + /** * Implements a reordering by pubdate that avoids consecutive episodes from the same feed in * the queue. diff --git a/core/src/main/res/values-de/strings.xml b/core/src/main/res/values-de/strings.xml index a5ceaab57..449d8b283 100644 --- a/core/src/main/res/values-de/strings.xml +++ b/core/src/main/res/values-de/strings.xml @@ -276,6 +276,7 @@ Zum Anfang verschieben Zum Ende verschieben Sortieren + Automatisch sortieren Datum Dauer Episodentitel @@ -416,8 +417,6 @@ Ändere die Reihenfolge deiner Abonnements Abonnement-Zähler einstellen Ändere die durch den Abonnementszähler angezeigten Informationen. Betrifft auch die Sortierung der Abonnements wenn \"Reihenfolge der Abonnements\" auf \"Zähler\" gesetzt ist. - Sortierung der Abspielliste einstellen - Ändere die Sortierreihenfolge der Episoden in der Abspielliste. Ändere das Aussehen von AntennaPod. Automatisches Herunterladen Konfiguriere das automatische Herunterladen von Episoden. @@ -690,11 +689,6 @@ Datum (alt \u2192 neu) Dauer (kurz \u2192 lang) Dauer (lang \u2192 kurz) - Episodentitel (A \u2192 Z) - Episodentitel (Z \u2192 A) - Podcasttitel (A \u2192 Z) - Podcasttitel (Z \u2192 A) - Manuell Gefällt dir AntennaPod? Wir würden uns freuen, wenn du dir kurz die Zeit nimmst, AntennaPod zu bewerten. diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index d5df4f646..39d1c0a94 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -187,29 +187,6 @@ 3 - - @string/sort_manually - @string/sort_date_new_old - @string/sort_date_old_new - @string/sort_duration_short_long - @string/sort_duration_long_short - @string/sort_episode_title_a_z - @string/sort_episode_title_z_a - @string/sort_feed_title_a_z - @string/sort_feed_title_z_a - - - MANUALLY - DATE_NEW_OLD - DATE_OLD_NEW - DURATION_SHORT_LONG - DURATION_LONG_SHORT - EPISODE_TITLE_A_Z - EPISODE_TITLE_Z_A - FEED_TITLE_A_Z - FEED_TITLE_Z_A - - @string/drawer_feed_counter_new_unplayed @string/drawer_feed_counter_new diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index 9d64cf549..b32bd60df 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -294,6 +294,7 @@ Move to top Move to bottom Sort + Keep sorted Date Duration Episode title @@ -401,8 +402,6 @@ Change the order of your subscriptions Set Subscription Counter Change the information displayed by the subscription counter. Also affects the sorting of subscriptions if \'Subscription Order\' is set to \'Counter\'. - Set Queue Sort Order - Change the sort order of the episodes in the queue. Change the appearance of AntennaPod. Automatic Download Configure the automatic download of episodes. @@ -697,11 +696,6 @@ Date (Old \u2192 New) Duration (Short \u2192 Long) Duration (Long \u2192 Short) - Episode title (A \u2192 Z) - Episode title (Z \u2192 A) - Podcast title (A \u2192 Z) - Podcast title (Z \u2192 A) - Manually Like AntennaPod?