diff options
author | orionlee <orionlee@yahoo.com> | 2019-10-24 11:01:48 -0700 |
---|---|---|
committer | orionlee <orionlee@yahoo.com> | 2019-10-24 11:01:48 -0700 |
commit | f56a02d5138c7dc63d371de65e527b7b50f60255 (patch) | |
tree | c40a4bbc9205beb003aaf47d9dd0036634846cd7 /app/src/main | |
parent | 05dfccacc39190f67940b06d82974be4c5de7181 (diff) | |
download | AntennaPod-f56a02d5138c7dc63d371de65e527b7b50f60255.zip |
sort in Podcast screen - implement all the sorts
Diffstat (limited to 'app/src/main')
3 files changed, 13 insertions, 24 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/dialog/IntraFeedSortDialog.java b/app/src/main/java/de/danoeh/antennapod/dialog/IntraFeedSortDialog.java index a554f8d76..2ee716c7c 100644 --- a/app/src/main/java/de/danoeh/antennapod/dialog/IntraFeedSortDialog.java +++ b/app/src/main/java/de/danoeh/antennapod/dialog/IntraFeedSortDialog.java @@ -7,16 +7,16 @@ import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import de.danoeh.antennapod.R; -import de.danoeh.antennapod.core.feed.IntraFeedSortOrder; +import de.danoeh.antennapod.core.util.SortOrder; public abstract class IntraFeedSortDialog { @Nullable - protected IntraFeedSortOrder currentSortOrder; + protected SortOrder currentSortOrder; @NonNull protected Context context; - public IntraFeedSortDialog(@NonNull Context context, @Nullable IntraFeedSortOrder sortOrder) { + public IntraFeedSortDialog(@NonNull Context context, @Nullable SortOrder sortOrder) { this.context = context; this.currentSortOrder = sortOrder; } @@ -24,9 +24,9 @@ public abstract class IntraFeedSortDialog { public void openDialog() { final String[] items = context.getResources().getStringArray(R.array.feed_episodes_sort_options); final String[] valueStrs = context.getResources().getStringArray(R.array.feed_episodes_sort_values); - final IntraFeedSortOrder[] values = new IntraFeedSortOrder[valueStrs.length]; + final SortOrder[] values = new SortOrder[valueStrs.length]; for (int i = 0; i < valueStrs.length; i++) { - values[i] = IntraFeedSortOrder.valueOf(valueStrs[i]); + values[i] = SortOrder.valueOf(valueStrs[i]); } int idxCurrentSort = -1; @@ -47,5 +47,5 @@ public abstract class IntraFeedSortDialog { builder.create().show(); } - protected abstract void updateSort(@NonNull IntraFeedSortOrder sortOrder); + protected abstract void updateSort(@NonNull SortOrder sortOrder); } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java index 415af83d5..88f48003f 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedItemlistFragment.java @@ -34,7 +34,6 @@ import org.greenrobot.eventbus.EventBus; import org.greenrobot.eventbus.Subscribe; import org.greenrobot.eventbus.ThreadMode; -import java.util.Collections; import java.util.List; import de.danoeh.antennapod.R; @@ -53,7 +52,6 @@ import de.danoeh.antennapod.core.feed.FeedEvent; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItemFilter; import de.danoeh.antennapod.core.feed.FeedMedia; -import de.danoeh.antennapod.core.feed.IntraFeedSortOrder; import de.danoeh.antennapod.core.glide.ApGlideSettings; import de.danoeh.antennapod.core.glide.FastBlurTransformation; import de.danoeh.antennapod.core.service.download.DownloadService; @@ -65,7 +63,7 @@ import de.danoeh.antennapod.core.storage.DownloadRequester; import de.danoeh.antennapod.core.util.FeedItemUtil; import de.danoeh.antennapod.core.util.LongList; import de.danoeh.antennapod.core.util.Optional; -import de.danoeh.antennapod.core.util.comparator.FeedItemPubdateComparator; +import de.danoeh.antennapod.core.util.QueueSorter; import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil; import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment; import de.danoeh.antennapod.dialog.RenameFeedDialog; @@ -634,19 +632,10 @@ public class FeedItemlistFragment extends ListFragment { FeedItemFilter filter = feed.getItemFilter(); feed.setItems(filter.filter(feed.getItems())); } - IntraFeedSortOrder sortOrder = feed.getSortOrder(); - if (sortOrder != null) { - long tS = System.currentTimeMillis(); // TODO-2524: - if (sortOrder == IntraFeedSortOrder.DATE_OLD_NEW) { - List<FeedItem> feedItems = feed.getItems(); - Collections.sort(feedItems, FeedItemPubdateComparator.ascending); - feed.setItems(feedItems); - } else { - System.err.println("DBG - to-implement: " + sortOrder); // TODO-2524: - } - long tE = System.currentTimeMillis(); - System.err.println("DBG - sort elapsed time: " + (tE -tS) + - "ms ; " + "num items: " + feed.getItems().size() + ", order: " + sortOrder); // TODO: 2524 + if (feed != null && feed.getSortOrder() != null) { + List<FeedItem> feedItems = feed.getItems(); + QueueSorter.getPermutor(feed.getSortOrder()).reorder(feedItems); + feed.setItems(feedItems); } return Optional.ofNullable(feed); } diff --git a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java index 53d95bd1c..e32deba27 100644 --- a/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java +++ b/app/src/main/java/de/danoeh/antennapod/menuhandler/FeedMenuHandler.java @@ -16,12 +16,12 @@ import java.util.Set; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.dialog.ConfirmationDialog; import de.danoeh.antennapod.core.feed.Feed; -import de.danoeh.antennapod.core.feed.IntraFeedSortOrder; import de.danoeh.antennapod.core.storage.DBTasks; import de.danoeh.antennapod.core.storage.DBWriter; import de.danoeh.antennapod.core.storage.DownloadRequestException; import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.ShareUtils; +import de.danoeh.antennapod.core.util.SortOrder; import de.danoeh.antennapod.dialog.FilterDialog; import de.danoeh.antennapod.dialog.IntraFeedSortDialog; @@ -120,7 +120,7 @@ public class FeedMenuHandler { private static void showSortDialog(Context context, Feed selectedFeed) { IntraFeedSortDialog sortDialog = new IntraFeedSortDialog(context, selectedFeed.getSortOrder()) { @Override - protected void updateSort(@NonNull IntraFeedSortOrder sortOrder) { + protected void updateSort(@NonNull SortOrder sortOrder) { selectedFeed.setSortOrder(sortOrder); DBWriter.setFeedItemSortOrder(selectedFeed.getId(), sortOrder); } |