diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2017-04-16 19:59:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-16 19:59:28 +0200 |
commit | f1b04d45e4231f47040883d5962557b97821785f (patch) | |
tree | e786c3499a15596f673fa46950167f59de1c918a /core | |
parent | aad56bea56c320cc84bd7f9472f3caff996e411c (diff) | |
parent | 20365111671e4074d33dbe512c79a5204c4cf254 (diff) | |
download | AntennaPod-f1b04d45e4231f47040883d5962557b97821785f.zip |
Merge pull request #2301 from ByteHamster/most-played
Sort feeds by number of played episodes
Diffstat (limited to 'core')
5 files changed, 27 insertions, 0 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 016b6c446..042298e28 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 @@ -126,6 +126,7 @@ public class UserPreferences { public static final int FEED_ORDER_COUNTER = 0; public static final int FEED_ORDER_ALPHABETICAL = 1; public static final int FEED_ORDER_LAST_UPDATE = 2; + public static final int FEED_ORDER_MOST_PLAYED = 3; public static final int FEED_COUNTER_SHOW_NEW_UNPLAYED_SUM = 0; public static final int FEED_COUNTER_SHOW_NEW = 1; public static final 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 1d57d902c..7bda08b7a 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 @@ -1080,6 +1080,21 @@ public final class DBReader { return t1.compareToIgnoreCase(t2); } }; + } else if(feedOrder == UserPreferences.FEED_ORDER_MOST_PLAYED) { + final LongIntMap playedCounters = adapter.getPlayedEpisodesCounters(feedIds); + + comparator = (lhs, rhs) -> { + long counterLhs = playedCounters.get(lhs.getId()); + long counterRhs = playedCounters.get(rhs.getId()); + if(counterLhs > counterRhs) { + // podcast with most played episodes first + return -1; + } else if(counterLhs == counterRhs) { + return lhs.getTitle().compareToIgnoreCase(rhs.getTitle()); + } else { + return 1; + } + }; } else { comparator = (lhs, rhs) -> { if(lhs.getItems() == null || lhs.getItems().size() == 0) { diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java index 111770dab..2d0b5c56a 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java @@ -1463,7 +1463,10 @@ public class PodDBAdapter { default: // NONE return new LongIntMap(0); } + return conditionalFeedCounterRead(whereRead, feedIds); + } + private LongIntMap conditionalFeedCounterRead(String whereRead, long... feedIds) { // work around TextUtils.join wanting only boxed items // and StringUtils.join() causing NoSuchMethodErrors on MIUI StringBuilder builder = new StringBuilder(); @@ -1496,6 +1499,11 @@ public class PodDBAdapter { return result; } + public final LongIntMap getPlayedEpisodesCounters(long... feedIds) { + String whereRead = KEY_READ + "=" + FeedItem.PLAYED; + return conditionalFeedCounterRead(whereRead, feedIds); + } + public final int getNumberOfDownloadedEpisodes() { final String query = "SELECT COUNT(DISTINCT " + KEY_ID + ") AS count FROM " + TABLE_NAME_FEED_MEDIA + " WHERE " + KEY_DOWNLOADED + " > 0"; diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 133a3ed6e..45650495c 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -157,11 +157,13 @@ <item>@string/drawer_feed_order_unplayed_episodes</item> <item>@string/drawer_feed_order_alphabetical</item> <item>@string/drawer_feed_order_last_update</item> + <item>@string/drawer_feed_order_most_played</item> </string-array> <string-array name="nav_drawer_feed_order_values"> <item>0</item> <item>1</item> <item>2</item> + <item>3</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 d9b474de6..328dd34e8 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -39,6 +39,7 @@ <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_order_most_played">Sort by number of played episodes</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> |