bugfix #3009 - Podcast's feed search results listed in an odd order (#3128)

This commit is contained in:
alimemonzx 2019-05-28 19:44:18 +05:00 committed by H. Lehmann
parent 8380c18543
commit 83a6d70387
2 changed files with 23 additions and 2 deletions

View File

@ -14,7 +14,7 @@ import java.util.concurrent.FutureTask;
import de.danoeh.antennapod.core.R; import de.danoeh.antennapod.core.R;
import de.danoeh.antennapod.core.feed.FeedItem; import de.danoeh.antennapod.core.feed.FeedItem;
import de.danoeh.antennapod.core.feed.SearchResult; 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 * Performs search on Feeds and FeedItems
@ -76,7 +76,7 @@ public class FeedSearcher {
} catch (InterruptedException | ExecutionException e) { } catch (InterruptedException | ExecutionException e) {
e.printStackTrace(); e.printStackTrace();
} }
Collections.sort(result, new SearchResultValueComparator()); Collections.sort(result, new InReverseChronologicalOrder());
return result; return result;
} }
} }

View File

@ -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<SearchResult> {
/**
* 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;
}
}