diff options
author | Jared234 <jared@fantaye.de> | 2023-02-12 21:12:04 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-12 21:12:04 +0100 |
commit | 7a2f4771ecd327665497f21606ebc9d6c9415fd1 (patch) | |
tree | 6d26ea35891de0004ec04c7752c172c111cac85e /app | |
parent | 8248bc6bb1f5f71a1e6be3101e1b2173948bf516 (diff) | |
download | AntennaPod-7a2f4771ecd327665497f21606ebc9d6c9415fd1.zip |
Add sorting options to downloads screen (#6210)
Diffstat (limited to 'app')
7 files changed, 180 insertions, 120 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java index b39b41897..6d91765da 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CompletedDownloadsFragment.java @@ -4,6 +4,8 @@ import android.os.Bundle; import android.util.Log; import android.view.ContextMenu; import android.view.LayoutInflater; +import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -33,6 +35,8 @@ import de.danoeh.antennapod.fragment.swipeactions.SwipeActions; import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedItemFilter; +import de.danoeh.antennapod.model.feed.SortOrder; +import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.view.EmptyViewHandler; import de.danoeh.antennapod.view.EpisodeItemListRecyclerView; import de.danoeh.antennapod.view.LiftOnScrollListener; @@ -77,6 +81,8 @@ public class CompletedDownloadsFragment extends Fragment MaterialToolbar toolbar = root.findViewById(R.id.toolbar); toolbar.setTitle(R.string.downloads_label); toolbar.inflateMenu(R.menu.downloads_completed); + inflateSortMenu(toolbar); + toolbar.setOnMenuItemClickListener(this); toolbar.setOnLongClickListener(v -> { recyclerView.scrollToPosition(5); @@ -139,6 +145,19 @@ public class CompletedDownloadsFragment extends Fragment return root; } + private void inflateSortMenu(MaterialToolbar toolbar) { + Menu menu = toolbar.getMenu(); + MenuItem downloadsItem = menu.findItem(R.id.downloads_sort); + MenuInflater menuInflater = getActivity().getMenuInflater(); + menuInflater.inflate(R.menu.sort_menu, downloadsItem.getSubMenu()); + + // Remove the sorting options that are not needed in this fragment + menu.findItem(R.id.sort_feed_title).setVisible(false); + menu.findItem(R.id.sort_random).setVisible(false); + menu.findItem(R.id.sort_smart_shuffle).setVisible(false); + menu.findItem(R.id.keep_sorted).setVisible(false); + } + @Override public void onSaveInstanceState(@NonNull Bundle outState) { outState.putBoolean(KEY_UP_ARROW, displayUpArrow); @@ -177,10 +196,21 @@ public class CompletedDownloadsFragment extends Fragment } else if (item.getItemId() == R.id.action_search) { ((MainActivity) getActivity()).loadChildFragment(SearchFragment.newInstance()); return true; + } else { + SortOrder sortOrder = MenuItemToSortOrderConverter.convert(item); + if (sortOrder != null) { + setSortOrder(sortOrder); + return true; + } } return false; } + private void setSortOrder(SortOrder sortOrder) { + UserPreferences.setDownloadsSortedOrder(sortOrder); + loadItems(); + } + @Subscribe(sticky = true, threadMode = ThreadMode.MAIN) public void onEventMainThread(DownloadEvent event) { Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]"); @@ -279,7 +309,9 @@ public class CompletedDownloadsFragment extends Fragment } emptyView.hide(); disposable = Observable.fromCallable(() -> { - List<FeedItem> downloadedItems = DBReader.getDownloadedItems(); + SortOrder sortOrder = UserPreferences.getDownloadsSortedOrder(); + List<FeedItem> downloadedItems = DBReader.getDownloadedItems(sortOrder); + List<Long> mediaIds = new ArrayList<>(); if (runningDownloads == null) { return downloadedItems; diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/MenuItemToSortOrderConverter.java b/app/src/main/java/de/danoeh/antennapod/fragment/MenuItemToSortOrderConverter.java new file mode 100644 index 000000000..51911b122 --- /dev/null +++ b/app/src/main/java/de/danoeh/antennapod/fragment/MenuItemToSortOrderConverter.java @@ -0,0 +1,40 @@ +package de.danoeh.antennapod.fragment; + +import android.view.MenuItem; + +import de.danoeh.antennapod.R; +import de.danoeh.antennapod.model.feed.SortOrder; + +public class MenuItemToSortOrderConverter { + + public static SortOrder convert(MenuItem item) { + final int itemId = item.getItemId(); + + if (itemId == R.id.sort_episode_title_asc) { + return SortOrder.EPISODE_TITLE_A_Z; + } else if (itemId == R.id.sort_episode_title_desc) { + return SortOrder.EPISODE_TITLE_Z_A; + } else if (itemId == R.id.sort_date_asc) { + return SortOrder.DATE_OLD_NEW; + } else if (itemId == R.id.sort_date_desc) { + return SortOrder.DATE_NEW_OLD; + } else if (itemId == R.id.sort_duration_asc) { + return SortOrder.DURATION_SHORT_LONG; + } else if (itemId == R.id.sort_duration_desc) { + return SortOrder.DURATION_LONG_SHORT; + } else if (itemId == R.id.sort_feed_title_asc) { + return SortOrder.FEED_TITLE_A_Z; + } else if (itemId == R.id.sort_feed_title_desc) { + return SortOrder.FEED_TITLE_Z_A; + } else if (itemId == R.id.sort_random) { + return SortOrder.RANDOM; + } else if (itemId == R.id.sort_smart_shuffle_asc) { + return SortOrder.SMART_SHUFFLE_OLD_NEW; + } else if (itemId == R.id.sort_smart_shuffle_desc) { + return SortOrder.SMART_SHUFFLE_NEW_OLD; + } + + return null; + } + +} 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 12fa20d05..4e8999d0f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -10,6 +10,7 @@ import android.util.Log; import android.view.ContextMenu; import android.view.KeyEvent; import android.view.LayoutInflater; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; @@ -256,8 +257,8 @@ public class QueueFragment extends Fragment implements MaterialToolbar.OnMenuIte boolean keepSorted = UserPreferences.isQueueKeepSorted(); toolbar.getMenu().findItem(R.id.queue_lock).setChecked(UserPreferences.isQueueLocked()); toolbar.getMenu().findItem(R.id.queue_lock).setVisible(!keepSorted); - toolbar.getMenu().findItem(R.id.queue_sort_random).setVisible(!keepSorted); - toolbar.getMenu().findItem(R.id.queue_keep_sorted).setChecked(keepSorted); + toolbar.getMenu().findItem(R.id.sort_random).setVisible(!keepSorted); + toolbar.getMenu().findItem(R.id.keep_sorted).setChecked(keepSorted); MenuItemUtils.updateRefreshMenuItem(toolbar.getMenu(), R.id.refresh_item, DownloadService.isRunning && DownloadService.isDownloadingFeeds()); } @@ -286,40 +287,7 @@ public class QueueFragment extends Fragment implements MaterialToolbar.OnMenuIte }; conDialog.createNewDialog().show(); return true; - } else if (itemId == R.id.queue_sort_episode_title_asc) { - setSortOrder(SortOrder.EPISODE_TITLE_A_Z); - return true; - } else if (itemId == R.id.queue_sort_episode_title_desc) { - setSortOrder(SortOrder.EPISODE_TITLE_Z_A); - return true; - } else if (itemId == R.id.queue_sort_date_asc) { - setSortOrder(SortOrder.DATE_OLD_NEW); - return true; - } else if (itemId == R.id.queue_sort_date_desc) { - setSortOrder(SortOrder.DATE_NEW_OLD); - return true; - } else if (itemId == R.id.queue_sort_duration_asc) { - setSortOrder(SortOrder.DURATION_SHORT_LONG); - return true; - } else if (itemId == R.id.queue_sort_duration_desc) { - setSortOrder(SortOrder.DURATION_LONG_SHORT); - return true; - } else if (itemId == R.id.queue_sort_feed_title_asc) { - setSortOrder(SortOrder.FEED_TITLE_A_Z); - return true; - } else if (itemId == R.id.queue_sort_feed_title_desc) { - setSortOrder(SortOrder.FEED_TITLE_Z_A); - return true; - } else if (itemId == R.id.queue_sort_random) { - setSortOrder(SortOrder.RANDOM); - return true; - } else if (itemId == R.id.queue_sort_smart_shuffle_asc) { - setSortOrder(SortOrder.SMART_SHUFFLE_OLD_NEW); - return true; - } else if (itemId == R.id.queue_sort_smart_shuffle_desc) { - setSortOrder(SortOrder.SMART_SHUFFLE_NEW_OLD); - return true; - } else if (itemId == R.id.queue_keep_sorted) { + } else if (itemId == R.id.keep_sorted) { boolean keepSortedOld = UserPreferences.isQueueKeepSorted(); boolean keepSortedNew = !keepSortedOld; UserPreferences.setQueueKeepSorted(keepSortedNew); @@ -335,6 +303,12 @@ public class QueueFragment extends Fragment implements MaterialToolbar.OnMenuIte } else if (itemId == R.id.action_search) { ((MainActivity) getActivity()).loadChildFragment(SearchFragment.newInstance()); return true; + } else { + SortOrder sortOrder = MenuItemToSortOrderConverter.convert(item); + if (sortOrder != null) { + setSortOrder(sortOrder); + return true; + } } return false; } @@ -444,6 +418,10 @@ public class QueueFragment extends Fragment implements MaterialToolbar.OnMenuIte } ((MainActivity) getActivity()).setupToolbarToggle(toolbar, displayUpArrow); toolbar.inflateMenu(R.menu.queue); + + MenuItem queueItem = toolbar.getMenu().findItem(R.id.queue_sort); + MenuInflater menuInflater = getActivity().getMenuInflater(); + menuInflater.inflate(R.menu.sort_menu, queueItem.getSubMenu()); refreshToolbarState(); progressBar = root.findViewById(R.id.progressBar); progressBar.setVisibility(View.VISIBLE); diff --git a/app/src/main/java/de/danoeh/antennapod/ui/home/sections/DownloadsSection.java b/app/src/main/java/de/danoeh/antennapod/ui/home/sections/DownloadsSection.java index 78c336335..0053b0e82 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/home/sections/DownloadsSection.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/home/sections/DownloadsSection.java @@ -23,6 +23,8 @@ import de.danoeh.antennapod.fragment.CompletedDownloadsFragment; import de.danoeh.antennapod.fragment.swipeactions.SwipeActions; import de.danoeh.antennapod.model.feed.FeedItem; import de.danoeh.antennapod.model.feed.FeedItemFilter; +import de.danoeh.antennapod.model.feed.SortOrder; +import de.danoeh.antennapod.storage.preferences.UserPreferences; import de.danoeh.antennapod.ui.home.HomeSection; import de.danoeh.antennapod.view.viewholder.EpisodeItemViewHolder; import io.reactivex.Observable; @@ -121,7 +123,8 @@ public class DownloadsSection extends HomeSection { if (disposable != null) { disposable.dispose(); } - disposable = Observable.fromCallable(DBReader::getDownloadedItems) + SortOrder sortOrder = UserPreferences.getDownloadsSortedOrder(); + disposable = Observable.fromCallable(() -> DBReader.getDownloadedItems(sortOrder)) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(downloads -> { diff --git a/app/src/main/res/menu/downloads_completed.xml b/app/src/main/res/menu/downloads_completed.xml index 61a0e6578..08179de58 100644 --- a/app/src/main/res/menu/downloads_completed.xml +++ b/app/src/main/res/menu/downloads_completed.xml @@ -22,5 +22,10 @@ android:menuCategory="container" android:icon="@drawable/ic_refresh" app:showAsAction="always" /> + <item + android:id="@+id/downloads_sort" + android:title="@string/sort"> + <menu></menu> + </item> </menu> diff --git a/app/src/main/res/menu/queue.xml b/app/src/main/res/menu/queue.xml index c1c2d982c..e4bb63808 100644 --- a/app/src/main/res/menu/queue.xml +++ b/app/src/main/res/menu/queue.xml @@ -24,88 +24,7 @@ <item android:id="@+id/queue_sort" android:title="@string/sort"> - - <menu> - <item - android:id="@+id/queue_sort_date" - android:title="@string/date"> - - <menu> - <item - android:id="@+id/queue_sort_date_asc" - android:title="@string/sort_old_new"/> - <item - android:id="@+id/queue_sort_date_desc" - android:title="@string/sort_new_old"/> - </menu> - </item> - - <item - android:id="@+id/queue_sort_duration" - android:title="@string/duration"> - - <menu> - <item - android:id="@+id/queue_sort_duration_asc" - android:title="@string/sort_short_long"/> - <item - android:id="@+id/queue_sort_duration_desc" - android:title="@string/sort_long_short"/> - </menu> - </item> - - <item - android:id="@+id/queue_sort_episode_title" - android:title="@string/episode_title"> - - <menu> - <item - android:id="@+id/queue_sort_episode_title_asc" - android:title="@string/sort_a_z"/> - <item - android:id="@+id/queue_sort_episode_title_desc" - android:title="@string/sort_z_a"/> - </menu> - </item> - - <item - android:id="@+id/queue_sort_feed_title" - android:title="@string/feed_title"> - - <menu> - <item - android:id="@+id/queue_sort_feed_title_asc" - android:title="@string/sort_a_z"/> - <item - android:id="@+id/queue_sort_feed_title_desc" - android:title="@string/sort_z_a"/> - </menu> - </item> - - <item - android:id="@+id/queue_sort_random" - android:title="@string/random"> - </item> - - <item - android:id="@+id/queue_sort_smart_shuffle" - android:title="@string/smart_shuffle"> - - <menu> - <item - android:id="@+id/queue_sort_smart_shuffle_asc" - android:title="@string/sort_old_new"/> - <item - android:id="@+id/queue_sort_smart_shuffle_desc" - android:title="@string/sort_new_old"/> - </menu> - </item> - - <item - android:id="@+id/queue_keep_sorted" - android:title="@string/keep_sorted" - android:checkable="true" /> - </menu> + <menu></menu> </item> <item diff --git a/app/src/main/res/menu/sort_menu.xml b/app/src/main/res/menu/sort_menu.xml new file mode 100644 index 000000000..f0a22042b --- /dev/null +++ b/app/src/main/res/menu/sort_menu.xml @@ -0,0 +1,83 @@ +<?xml version="1.0" encoding="utf-8"?> +<menu xmlns:android="http://schemas.android.com/apk/res/android"> + + <item + android:id="@+id/sort_date" + android:title="@string/date"> + + <menu> + <item + android:id="@+id/sort_date_asc" + android:title="@string/sort_old_new"/> + <item + android:id="@+id/sort_date_desc" + android:title="@string/sort_new_old"/> + </menu> + </item> + + <item + android:id="@+id/sort_duration" + android:title="@string/duration"> + + <menu> + <item + android:id="@+id/sort_duration_asc" + android:title="@string/sort_short_long"/> + <item + android:id="@+id/sort_duration_desc" + android:title="@string/sort_long_short"/> + </menu> + </item> + + <item + android:id="@+id/sort_episode_title" + android:title="@string/episode_title"> + + <menu> + <item + android:id="@+id/sort_episode_title_asc" + android:title="@string/sort_a_z"/> + <item + android:id="@+id/sort_episode_title_desc" + android:title="@string/sort_z_a"/> + </menu> + </item> + + <item + android:id="@+id/sort_feed_title" + android:title="@string/feed_title"> + + <menu> + <item + android:id="@+id/sort_feed_title_asc" + android:title="@string/sort_a_z"/> + <item + android:id="@+id/sort_feed_title_desc" + android:title="@string/sort_z_a"/> + </menu> + </item> + + <item + android:id="@+id/sort_random" + android:title="@string/random"> + </item> + + <item + android:id="@+id/sort_smart_shuffle" + android:title="@string/smart_shuffle"> + + <menu> + <item + android:id="@+id/sort_smart_shuffle_asc" + android:title="@string/sort_old_new"/> + <item + android:id="@+id/sort_smart_shuffle_desc" + android:title="@string/sort_new_old"/> + </menu> + </item> + <item + android:id="@+id/keep_sorted" + android:title="@string/keep_sorted" + android:checkable="true" /> + +</menu> |