Show correct number of new items

This commit is contained in:
Martin Fietz 2015-05-19 16:46:51 +02:00
parent 44b3a3bb87
commit 61754cae52
5 changed files with 28 additions and 17 deletions

View File

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

View File

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

View File

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

View File

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

View File

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