diff options
author | Martin Fietz <Martin.Fietz@gmail.com> | 2015-05-19 16:46:51 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-05-19 16:46:51 +0200 |
commit | 61754cae52feaed9a9fa149e087bfe98e2015cbd (patch) | |
tree | c6148bc0713f4433038809fd425c5558bf424fbd | |
parent | 44b3a3bb871c2eabae2df8c6092e0a0c0b317f88 (diff) | |
download | AntennaPod-61754cae52feaed9a9fa149e087bfe98e2015cbd.zip |
Show correct number of new items
5 files changed, 28 insertions, 17 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java index 8f18235c7..b59f6ba35 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/AudioplayerActivity.java @@ -703,8 +703,8 @@ public class AudioplayerActivity extends MediaplayerActivity implements ItemDesc } @Override - public int getNumberOfUnreadItems() { - return (navDrawerData != null) ? navDrawerData.numUnreadItems : 0; + public int getNumberOfNewItems() { + return (navDrawerData != null) ? navDrawerData.numNewItems : 0; } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java index 842dbcc9d..d62612c76 100644 --- a/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java +++ b/app/src/main/java/de/danoeh/antennapod/activity/MainActivity.java @@ -507,8 +507,8 @@ public class MainActivity extends ActionBarActivity implements NavDrawerActivity } @Override - public int getNumberOfUnreadItems() { - return (navDrawerData != null) ? navDrawerData.numUnreadItems : 0; + public int getNumberOfNewItems() { + return (navDrawerData != null) ? navDrawerData.numNewItems : 0; } @Override diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java index ae81779e4..13982f57d 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/NavListAdapter.java @@ -210,7 +210,7 @@ public class NavListAdapter extends BaseAdapter holder.count.setVisibility(View.GONE); } } else if (tags.get(position).equals(NewEpisodesFragment.TAG)) { - int unreadItems = itemAccess.getNumberOfUnreadItems(); + int unreadItems = itemAccess.getNumberOfNewItems(); if (unreadItems > 0) { holder.count.setVisibility(View.VISIBLE); holder.count.setText(String.valueOf(unreadItems)); @@ -300,7 +300,7 @@ public class NavListAdapter extends BaseAdapter Feed getItem(int position); int getSelectedItemIndex(); int getQueueSize(); - int getNumberOfUnreadItems(); + int getNumberOfNewItems(); int getNumberOfUnreadFeedItems(long feedId); } 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 f407b65fd..cc20b3d37 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 @@ -982,10 +982,10 @@ public final class DBReader { * @param context A context that is used for opening a database connection. * @return The number of unread items. */ - public static int getNumberOfUnreadItems(final Context context) { + public static int getNumberOfNewItems(final Context context) { PodDBAdapter adapter = new PodDBAdapter(context); adapter.open(); - final int result = adapter.getNumberOfUnreadItems(); + final int result = adapter.getNumberOfNewItems(); adapter.close(); return result; } @@ -1144,15 +1144,15 @@ public final class DBReader { // reverse natural order: podcast with most unplayed episodes first return -1; } else if(numUnreadLhs == numUnreadRhs) { - return 0; + return lhs.getTitle().compareTo(rhs.getTitle()); } else { return 1; } } }); int queueSize = adapter.getQueueSize(); - int numUnreadItems = adapter.getNumberOfUnreadItems(); - NavDrawerData result = new NavDrawerData(feeds, queueSize, numUnreadItems, numUnreadFeedItems); + int numNewItems = adapter.getNumberOfNewItems(); + NavDrawerData result = new NavDrawerData(feeds, queueSize, numNewItems, numUnreadFeedItems); adapter.close(); return result; } @@ -1160,14 +1160,14 @@ public final class DBReader { public static class NavDrawerData { public List<Feed> feeds; public int queueSize; - public int numUnreadItems; + public int numNewItems; public LongIntMap numUnreadFeedItems; - public NavDrawerData(List<Feed> feeds, int queueSize, int numUnreadItems, + public NavDrawerData(List<Feed> feeds, int queueSize, int numNewItems, LongIntMap numUnreadFeedItems) { this.feeds = feeds; this.queueSize = queueSize; - this.numUnreadItems = numUnreadItems; + this.numNewItems = numNewItems; this.numUnreadFeedItems = numUnreadFeedItems; } } 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 6d31b565f..4780098e0 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 @@ -1270,9 +1270,20 @@ public class PodDBAdapter { return result; } - public final int getNumberOfUnreadItems() { - final String query = "SELECT COUNT(DISTINCT " + KEY_ID + ") AS count FROM " + TABLE_NAME_FEED_ITEMS + - " WHERE " + KEY_READ + " = 0"; + public final int getNumberOfNewItems() { + final String query = "SELECT COUNT(" + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + ")" + +" FROM " + TABLE_NAME_FEED_ITEMS + + " LEFT JOIN " + TABLE_NAME_FEED_MEDIA + " ON " + + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "=" + + TABLE_NAME_FEED_MEDIA + "." + KEY_FEEDITEM + + " LEFT JOIN " + TABLE_NAME_QUEUE + " ON " + + TABLE_NAME_FEED_ITEMS + "." + KEY_ID + "=" + + TABLE_NAME_QUEUE + "." + KEY_FEEDITEM + + " WHERE " + + TABLE_NAME_FEED_ITEMS + "." + KEY_READ + " = 0 AND " // unplayed + + TABLE_NAME_FEED_MEDIA + "." + KEY_DOWNLOADED + " = 0 AND " // undownloaded + + TABLE_NAME_FEED_MEDIA + "." + KEY_POSITION + " = 0 AND " // not partially played + + TABLE_NAME_QUEUE + "." + KEY_ID + " IS NULL"; // not in queue Cursor c = db.rawQuery(query, null); int result = 0; if (c.moveToFirst()) { |