Add option to show number of downloaded episodes as subscription counter

This commit is contained in:
Martin Fietz 2016-10-03 11:46:02 +02:00
parent d0ed378e1e
commit ba37684d7c
4 changed files with 42 additions and 28 deletions

View File

@ -56,7 +56,6 @@ public class UserPreferences {
public static final String PREF_LOCKSCREEN_BACKGROUND = "prefLockscreenBackground";
public static final String PREF_SHOW_DOWNLOAD_REPORT = "prefShowDownloadReport";
// Queue
public static final String PREF_QUEUE_ADD_TO_FRONT = "prefQueueAddToFront";
@ -123,13 +122,14 @@ public class UserPreferences {
private static final int NOTIFICATION_BUTTON_FAST_FORWARD = 1;
private static final int NOTIFICATION_BUTTON_SKIP = 2;
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;
public static int FEED_COUNTER_SHOW_NONE = 3;
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_COUNTER_SHOW_NEW_UNPLAYED_SUM = 0;
public static final int FEED_COUNTER_SHOW_NEW = 1;
public static final int FEED_COUNTER_SHOW_UNPLAYED = 2;
public static final int FEED_COUNTER_SHOW_NONE = 3;
public static final int FEED_COUNTER_SHOW_DOWNLOADED = 4;
private static Context context;
private static SharedPreferences prefs;

View File

@ -42,12 +42,12 @@ import de.greenrobot.event.EventBus;
public class PodDBAdapter {
private static final String TAG = "PodDBAdapter";
public static final String DATABASE_NAME = "Antennapod.db";
private static final String DATABASE_NAME = "Antennapod.db";
/**
* Maximum number of arguments for IN-operator.
*/
public static final int IN_OPERATOR_MAXIMUM = 800;
private static final int IN_OPERATOR_MAXIMUM = 800;
/**
* Maximum number of entries per search request.
@ -109,14 +109,14 @@ public class PodDBAdapter {
public static final String KEY_EXCLUDE_FILTER = "exclude_filter";
// Table names
public static final String TABLE_NAME_FEEDS = "Feeds";
public static final String TABLE_NAME_FEED_ITEMS = "FeedItems";
public static final String TABLE_NAME_FEED_IMAGES = "FeedImages";
public static final String TABLE_NAME_FEED_MEDIA = "FeedMedia";
public static final String TABLE_NAME_DOWNLOAD_LOG = "DownloadLog";
public static final String TABLE_NAME_QUEUE = "Queue";
public static final String TABLE_NAME_SIMPLECHAPTERS = "SimpleChapters";
public static final String TABLE_NAME_FAVORITES = "Favorites";
private static final String TABLE_NAME_FEEDS = "Feeds";
private static final String TABLE_NAME_FEED_ITEMS = "FeedItems";
private static final String TABLE_NAME_FEED_IMAGES = "FeedImages";
private static final String TABLE_NAME_FEED_MEDIA = "FeedMedia";
private static final String TABLE_NAME_DOWNLOAD_LOG = "DownloadLog";
private static final String TABLE_NAME_QUEUE = "Queue";
private static final String TABLE_NAME_SIMPLECHAPTERS = "SimpleChapters";
private static final String TABLE_NAME_FAVORITES = "Favorites";
// SQL Statements for creating new tables
private static final String TABLE_PRIMARY_KEY = KEY_ID
@ -1436,15 +1436,24 @@ public class PodDBAdapter {
public final LongIntMap getFeedCounters(long... feedIds) {
int setting = UserPreferences.getFeedCounterSetting();
String whereRead;
if(setting == UserPreferences.FEED_COUNTER_SHOW_NEW_UNPLAYED_SUM) {
whereRead = "(" + KEY_READ + "=" + FeedItem.NEW
+ " OR " + KEY_READ + "=" + FeedItem.UNPLAYED + ")";
} else if(setting == UserPreferences.FEED_COUNTER_SHOW_NEW) {
whereRead = KEY_READ + "=" + FeedItem.NEW;
} else if(setting == UserPreferences.FEED_COUNTER_SHOW_UNPLAYED) {
whereRead = KEY_READ + "=" + FeedItem.UNPLAYED;
} else { // NONE
return new LongIntMap(0);
switch(setting) {
case UserPreferences.FEED_COUNTER_SHOW_NEW_UNPLAYED_SUM:
whereRead = "(" + KEY_READ + "=" + FeedItem.NEW +
" OR " + KEY_READ + "=" + FeedItem.UNPLAYED + ")";
break;
case UserPreferences.FEED_COUNTER_SHOW_NEW:
whereRead = KEY_READ + "=" + FeedItem.NEW;
break;
case UserPreferences.FEED_COUNTER_SHOW_UNPLAYED:
whereRead = KEY_READ + "=" + FeedItem.UNPLAYED;
break;
case UserPreferences.FEED_COUNTER_SHOW_DOWNLOADED:
whereRead = KEY_DOWNLOADED + "=1";
break;
case UserPreferences.FEED_COUNTER_SHOW_NONE:
// deliberate fall-through
default: // NONE
return new LongIntMap(0);
}
// work around TextUtils.join wanting only boxed items
@ -1459,8 +1468,10 @@ public class PodDBAdapter {
builder.deleteCharAt(builder.length() - 1);
}
final String query = "SELECT " + KEY_FEED + ", COUNT(" + KEY_ID + ") AS count "
final String query = "SELECT " + KEY_FEED + ", COUNT(" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + ") AS count "
+ " FROM " + TABLE_NAME_FEED_ITEMS
+ " LEFT JOIN " + TABLE_NAME_FEED_MEDIA + " ON "
+ TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "=" + TABLE_NAME_FEED_MEDIA + "." + KEY_FEEDITEM
+ " WHERE " + KEY_FEED + " IN (" + builder.toString() + ") "
+ " AND " + whereRead + " GROUP BY " + KEY_FEED;

View File

@ -168,12 +168,14 @@
<item>@string/drawer_feed_counter_new_unplayed</item>
<item>@string/drawer_feed_counter_new</item>
<item>@string/drawer_feed_counter_unplayed</item>
<item>@string/drawer_feed_counter_downloaded</item>
<item>@string/drawer_feed_counter_none</item>
</string-array>
<string-array name="nav_drawer_feed_counter_values">
<item>0</item>
<item>1</item>
<item>2</item>
<item>4</item>
<item>3</item>
</string-array>

View File

@ -42,6 +42,7 @@
<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>
<string name="drawer_feed_counter_downloaded">Number of downloaded episodes</string>
<string name="drawer_feed_counter_none">None</string>
<!-- Webview actions -->