Merge pull request #2301 from ByteHamster/most-played

Sort feeds by number of played episodes
This commit is contained in:
Martin Fietz 2017-04-16 19:59:28 +02:00 committed by GitHub
commit f1b04d45e4
5 changed files with 27 additions and 0 deletions

View File

@ -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;

View File

@ -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) {

View File

@ -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";

View File

@ -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">

View File

@ -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>