From 83a6d70387e8df95e04f198ef99f992aef674413 Mon Sep 17 00:00:00 2001 From: alimemonzx <44647595+alimemonzx@users.noreply.github.com> Date: Tue, 28 May 2019 19:44:18 +0500 Subject: [PATCH] bugfix #3009 - Podcast's feed search results listed in an odd order (#3128) --- .../antennapod/core/storage/FeedSearcher.java | 4 ++-- .../InReverseChronologicalOrder.java | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 core/src/main/java/de/danoeh/antennapod/core/util/comparator/InReverseChronologicalOrder.java diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java index 4093c41a5..c6620a90e 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/FeedSearcher.java @@ -14,7 +14,7 @@ import java.util.concurrent.FutureTask; import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.SearchResult; -import de.danoeh.antennapod.core.util.comparator.SearchResultValueComparator; +import de.danoeh.antennapod.core.util.comparator.InReverseChronologicalOrder; /** * Performs search on Feeds and FeedItems @@ -76,7 +76,7 @@ public class FeedSearcher { } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } - Collections.sort(result, new SearchResultValueComparator()); + Collections.sort(result, new InReverseChronologicalOrder()); return result; } } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/comparator/InReverseChronologicalOrder.java b/core/src/main/java/de/danoeh/antennapod/core/util/comparator/InReverseChronologicalOrder.java new file mode 100644 index 000000000..80246af8f --- /dev/null +++ b/core/src/main/java/de/danoeh/antennapod/core/util/comparator/InReverseChronologicalOrder.java @@ -0,0 +1,21 @@ +package de.danoeh.antennapod.core.util.comparator; + +import java.util.Comparator; + +import de.danoeh.antennapod.core.feed.FeedItem; +import de.danoeh.antennapod.core.feed.SearchResult; + +public class InReverseChronologicalOrder implements Comparator { + /** + * Compare items and sort it on chronological order. + */ + @Override + public int compare(SearchResult o1, SearchResult o2) { + if ((o1.getComponent() instanceof FeedItem) && (o2.getComponent() instanceof FeedItem)) { + FeedItem item1 = (FeedItem) o1.getComponent(); + FeedItem item2 = (FeedItem) o2.getComponent(); + return item2.getPubDate().compareTo(item1.getPubDate()); + } + return 0; + } +}