diff options
author | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-10-05 01:35:47 -0400 |
---|---|---|
committer | Tom Hennen <TomHennen@users.noreply.github.com> | 2015-10-05 01:35:47 -0400 |
commit | 1aa13477249defe72916080da08cd980515e7e40 (patch) | |
tree | ff0c15211ca82b6bc46edfcd2d93a898f427858b | |
parent | 5c4e5a29161f3536d04270dd8600db9f8fef203d (diff) | |
parent | 91cc0b2527573bc653e8d15b6d4b8f16ae31937f (diff) | |
download | AntennaPod-1aa13477249defe72916080da08cd980515e7e40.zip |
Merge pull request #1246 from mfietz/issue/1244-sort-last-update
Drawer: Sort feeds by publication date
4 files changed, 26 insertions, 1 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index c0e53842f..59f8e29e1 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -98,6 +98,7 @@ public class UserPreferences { private static int EPISODE_CACHE_SIZE_UNLIMITED = -1; public static int FEED_ORDER_COUNTER = 0; public static int FEED_ORDER_ALPHABETICAL = 1; + public static int FEED_ORDER_LAST_UPDATE = 2; public static int FEED_COUNTER_SHOW_NEW_UNPLAYED_SUM = 0; public static int FEED_COUNTER_SHOW_NEW = 1; public static int FEED_COUNTER_SHOW_UNPLAYED = 2; diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java index d95e4ff02..7a8609b04 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBReader.java @@ -8,6 +8,7 @@ import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.Date; import java.util.List; import de.danoeh.antennapod.core.feed.Chapter; @@ -947,13 +948,33 @@ public final class DBReader { return 1; } }; - } else { + } else if(feedOrder == UserPreferences.FEED_ORDER_ALPHABETICAL) { comparator = (lhs, rhs) -> { if(lhs.getTitle() == null) { return 1; } return lhs.getTitle().compareTo(rhs.getTitle()); }; + } else { + comparator = (lhs, rhs) -> { + if(lhs.getItems() == null || lhs.getItems().size() == 0) { + List<FeedItem> items = DBReader.getFeedItemList(lhs); + lhs.setItems(items); + } + if(rhs.getItems() == null || rhs.getItems().size() == 0) { + List<FeedItem> items = DBReader.getFeedItemList(rhs); + rhs.setItems(items); + } + if(lhs.getMostRecentItem() == null) { + return 1; + } else if(rhs.getMostRecentItem() == null) { + return -1; + } else { + Date d1 = lhs.getMostRecentItem().getPubDate(); + Date d2 = rhs.getMostRecentItem().getPubDate(); + return d2.compareTo(d1); + } + }; } Collections.sort(feeds, comparator); diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 875a1c4a8..b2f928617 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -132,10 +132,12 @@ <string-array name="nav_drawer_feed_order_options"> <item>@string/drawer_feed_order_unplayed_episodes</item> <item>@string/drawer_feed_order_alphabetical</item> + <item>@string/drawer_feed_order_last_update</item> </string-array> <string-array name="nav_drawer_feed_order_values"> <item>0</item> <item>1</item> + <item>2</item> </string-array> <string-array name="nav_drawer_feed_counter_options"> diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index ae1381de3..34f3791c4 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -36,6 +36,7 @@ <string name="drawer_preferences">Drawer Preferences</string> <string name="drawer_feed_order_unplayed_episodes">Sort by counter</string> <string name="drawer_feed_order_alphabetical">Sort alphabetically</string> + <string name="drawer_feed_order_last_update">Sort by publication date</string> <string name="drawer_feed_counter_new_unplayed">Number of new and unplayed episodes</string> <string name="drawer_feed_counter_new">Number of new episodes</string> <string name="drawer_feed_counter_unplayed">Number of unplayed episodes</string> |