mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-09-18 21:50:56 +00:00
Manually count unreads all the time.
This commit is contained in:
parent
97f314270c
commit
00b3eacbcd
10 changed files with 24 additions and 86 deletions
|
@ -16,13 +16,11 @@ import com.newsblur.util.StoryOrder;
|
|||
|
||||
public class AllSharedStoriesReading extends Reading {
|
||||
|
||||
private String[] feedIds;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceBundle) {
|
||||
super.onCreate(savedInstanceBundle);
|
||||
|
||||
feedIds = getIntent().getStringArrayExtra(Reading.EXTRA_FEED_IDS);
|
||||
setTitle(getResources().getString(R.string.all_shared_stories));
|
||||
|
||||
// No sourceUserId since this is all shared stories. The sourceUsedId for each story will be used.
|
||||
|
@ -31,12 +29,4 @@ public class AllSharedStoriesReading extends Reading {
|
|||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUnreadCount() {
|
||||
Cursor folderCursor = contentResolver.query(FeedProvider.SOCIALCOUNT_URI, null, DatabaseConstants.getBlogSelectionFromState(currentState), null, null);
|
||||
int c = FeedUtils.getCursorUnreadCount(folderCursor, currentState);
|
||||
folderCursor.close();
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,24 +16,13 @@ import com.newsblur.util.StoryOrder;
|
|||
|
||||
public class AllStoriesReading extends Reading {
|
||||
|
||||
private String[] feedIds;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceBundle) {
|
||||
super.onCreate(savedInstanceBundle);
|
||||
|
||||
feedIds = getIntent().getStringArrayExtra(Reading.EXTRA_FEED_IDS);
|
||||
setTitle(getResources().getString(R.string.all_stories_row_title));
|
||||
readingAdapter = new MixedFeedsReadingAdapter(getFragmentManager(), getContentResolver(), defaultFeedView, null);
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUnreadCount() {
|
||||
Cursor folderCursor = contentResolver.query(FeedProvider.FEED_COUNT_URI, null, DatabaseConstants.getBlogSelectionFromState(currentState), null, null);
|
||||
int c = FeedUtils.getCursorUnreadCount(folderCursor, currentState);
|
||||
folderCursor.close();
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -41,9 +41,4 @@ public class FeedReading extends Reading {
|
|||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUnreadCount() {
|
||||
return dbHelper.getFeedUnreadCount(feedId, currentState);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,14 +13,12 @@ import com.newsblur.util.PrefsUtils;
|
|||
|
||||
public class FolderReading extends Reading {
|
||||
|
||||
private String[] feedIds;
|
||||
private String folderName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceBundle) {
|
||||
super.onCreate(savedInstanceBundle);
|
||||
|
||||
feedIds = getIntent().getStringArrayExtra(Reading.EXTRA_FEED_IDS);
|
||||
folderName = getIntent().getStringExtra(Reading.EXTRA_FOLDERNAME);
|
||||
setTitle(folderName);
|
||||
|
||||
|
@ -29,12 +27,4 @@ public class FolderReading extends Reading {
|
|||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUnreadCount() {
|
||||
Cursor folderCursor = contentResolver.query(FeedProvider.FOLDERS_URI.buildUpon().appendPath(folderName).build(), null, null, new String[] { DatabaseConstants.getFolderSelectionFromState(currentState) }, null);
|
||||
int c = FeedUtils.getCursorUnreadCount(folderCursor, currentState);
|
||||
folderCursor.close();
|
||||
return c;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -254,7 +254,10 @@ public abstract class Reading extends NbActivity implements OnPageChangeListener
|
|||
/**
|
||||
* Query the DB for the current unreadcount for this view.
|
||||
*/
|
||||
protected abstract int getUnreadCount();
|
||||
private int getUnreadCount() {
|
||||
if (fs.isAllSaved()) return 0; // saved stories doesn't have unreads
|
||||
return dbHelper.getUnreadCount(fs, currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
|
|
@ -30,10 +30,4 @@ public class SavedStoriesReading extends Reading {
|
|||
super.onLoadFinished(loader, cursor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUnreadCount() {
|
||||
// effectively disable the notion of unreads for this feed
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -32,14 +32,4 @@ public class SocialFeedReading extends Reading {
|
|||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getUnreadCount() {
|
||||
Uri socialFeedUri = FeedProvider.SOCIAL_FEEDS_URI.buildUpon().appendPath(userId).build();
|
||||
Cursor cursor = contentResolver.query(socialFeedUri, null, null, null, null);
|
||||
if (cursor.getCount() == 0) return 0;
|
||||
SocialFeed socialFeed = SocialFeed.fromCursor(cursor);
|
||||
cursor.close();
|
||||
return FeedUtils.getFeedUnreadCount(socialFeed, this.currentState);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -361,6 +361,13 @@ public class BlurDatabaseHelper {
|
|||
dbRW.update(DatabaseConstants.SOCIALFEED_TABLE, values, whereClause, whereArgs);
|
||||
}
|
||||
|
||||
public int getUnreadCount(FeedSet fs, int stateFilter) {
|
||||
Cursor c = getStoriesCursor(fs, stateFilter, ReadFilter.PURE_UNREAD, null);
|
||||
int count = c.getCount();
|
||||
c.close();
|
||||
return count;
|
||||
}
|
||||
|
||||
public void enqueueAction(ReadingAction ra) {
|
||||
dbRW.insertOrThrow(DatabaseConstants.ACTION_TABLE, null, ra.toContentValues());
|
||||
}
|
||||
|
@ -374,35 +381,6 @@ public class BlurDatabaseHelper {
|
|||
dbRW.delete(DatabaseConstants.ACTION_TABLE, DatabaseConstants.ACTION_ID + " = ?", new String[]{actionId});
|
||||
}
|
||||
|
||||
public int getFeedUnreadCount(String feedId, int readingState) {
|
||||
// calculate the unread count both from the feeds table and the stories table. If
|
||||
// they disagree, use the maximum value seen.
|
||||
int countFromFeedsTable = 0;
|
||||
int countFromStoriesTable = 0;
|
||||
|
||||
// note we have to select the whole story object so we can get all they flavours of unread count and do math on them
|
||||
String q1 = "SELECT " + TextUtils.join(",", DatabaseConstants.FEED_COLUMNS) +
|
||||
" FROM " + DatabaseConstants.FEED_TABLE +
|
||||
" WHERE " + DatabaseConstants.FEED_ID + "= ?";
|
||||
Cursor c1 = dbRO.rawQuery(q1, new String[]{feedId});
|
||||
if (c1.getCount() > 0) {
|
||||
Feed feed = Feed.fromCursor(c1);
|
||||
countFromFeedsTable = FeedUtils.getFeedUnreadCount(feed, readingState);
|
||||
}
|
||||
c1.close();
|
||||
|
||||
// note we can't select count(*) because the actual story state columns are virtual
|
||||
String q2 = "SELECT " + TextUtils.join(",", DatabaseConstants.STORY_COLUMNS) + " FROM " + DatabaseConstants.STORY_TABLE +
|
||||
" WHERE " + DatabaseConstants.STORY_FEED_ID + "= ?" +
|
||||
" AND " + DatabaseConstants.getStorySelectionFromState(readingState) +
|
||||
" AND " + DatabaseConstants.STORY_READ + " = 0";
|
||||
Cursor c2 = dbRO.rawQuery(q2, new String[]{feedId});
|
||||
countFromStoriesTable = c2.getCount();
|
||||
c2.close();
|
||||
|
||||
return Math.max(countFromFeedsTable, countFromStoriesTable);
|
||||
}
|
||||
|
||||
public Cursor getStory(String hash) {
|
||||
String q = "SELECT * FROM " + DatabaseConstants.STORY_TABLE +
|
||||
" WHERE " + DatabaseConstants.STORY_HASH + " = ?";
|
||||
|
@ -434,8 +412,12 @@ public class BlurDatabaseHelper {
|
|||
}
|
||||
|
||||
public Cursor getStoriesCursor(FeedSet fs, int stateFilter) {
|
||||
StoryOrder order = PrefsUtils.getStoryOrder(context, fs);
|
||||
ReadFilter readFilter = PrefsUtils.getReadFilter(context, fs);
|
||||
StoryOrder order = PrefsUtils.getStoryOrder(context, fs);
|
||||
return getStoriesCursor(fs, stateFilter, readFilter, order);
|
||||
}
|
||||
|
||||
public Cursor getStoriesCursor(FeedSet fs, int stateFilter, ReadFilter readFilter, StoryOrder order) {
|
||||
|
||||
if (fs.getSingleFeed() != null) {
|
||||
|
||||
|
|
|
@ -339,12 +339,17 @@ public class DatabaseConstants {
|
|||
// When a user is viewing "unread only" stories, what they really want are stories that were unread when they started reading,
|
||||
// or else the selection set will constantly change as they see things!
|
||||
q.append(" AND ((" + STORY_READ + " = 0) OR (" + STORY_READ_THIS_SESSION + " = 1))");
|
||||
} else if (readFilter == ReadFilter.PURE_UNREAD) {
|
||||
// This means really just unreads, useful for getting counts
|
||||
q.append(" AND (" + STORY_READ + " = 0)");
|
||||
}
|
||||
q.append(" AND " + getStorySelectionFromState(stateFilter));
|
||||
if (dedupCol != null) {
|
||||
q.append( " GROUP BY " + dedupCol);
|
||||
}
|
||||
q.append(" ORDER BY " + getStorySortOrder(order));
|
||||
if (order != null) {
|
||||
q.append(" ORDER BY " + getStorySortOrder(order));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -2,11 +2,11 @@ package com.newsblur.util;
|
|||
|
||||
/**
|
||||
* Enum to represent read_filter when fetching feeds
|
||||
* @author mark
|
||||
*/
|
||||
public enum ReadFilter {
|
||||
ALL("all"),
|
||||
UNREAD("unread");
|
||||
UNREAD("unread"), // in the app, this often means "unread and read since switching activities"
|
||||
PURE_UNREAD("unread");
|
||||
|
||||
private String parameterValue;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue