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 {
|
public class AllSharedStoriesReading extends Reading {
|
||||||
|
|
||||||
private String[] feedIds;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceBundle) {
|
protected void onCreate(Bundle savedInstanceBundle) {
|
||||||
super.onCreate(savedInstanceBundle);
|
super.onCreate(savedInstanceBundle);
|
||||||
|
|
||||||
feedIds = getIntent().getStringArrayExtra(Reading.EXTRA_FEED_IDS);
|
|
||||||
setTitle(getResources().getString(R.string.all_shared_stories));
|
setTitle(getResources().getString(R.string.all_shared_stories));
|
||||||
|
|
||||||
// No sourceUserId since this is all shared stories. The sourceUsedId for each story will be used.
|
// 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);
|
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 {
|
public class AllStoriesReading extends Reading {
|
||||||
|
|
||||||
private String[] feedIds;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceBundle) {
|
protected void onCreate(Bundle savedInstanceBundle) {
|
||||||
super.onCreate(savedInstanceBundle);
|
super.onCreate(savedInstanceBundle);
|
||||||
|
|
||||||
feedIds = getIntent().getStringArrayExtra(Reading.EXTRA_FEED_IDS);
|
|
||||||
setTitle(getResources().getString(R.string.all_stories_row_title));
|
setTitle(getResources().getString(R.string.all_stories_row_title));
|
||||||
readingAdapter = new MixedFeedsReadingAdapter(getFragmentManager(), getContentResolver(), defaultFeedView, null);
|
readingAdapter = new MixedFeedsReadingAdapter(getFragmentManager(), getContentResolver(), defaultFeedView, null);
|
||||||
getLoaderManager().initLoader(0, null, this);
|
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);
|
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 {
|
public class FolderReading extends Reading {
|
||||||
|
|
||||||
private String[] feedIds;
|
|
||||||
private String folderName;
|
private String folderName;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceBundle) {
|
protected void onCreate(Bundle savedInstanceBundle) {
|
||||||
super.onCreate(savedInstanceBundle);
|
super.onCreate(savedInstanceBundle);
|
||||||
|
|
||||||
feedIds = getIntent().getStringArrayExtra(Reading.EXTRA_FEED_IDS);
|
|
||||||
folderName = getIntent().getStringExtra(Reading.EXTRA_FOLDERNAME);
|
folderName = getIntent().getStringExtra(Reading.EXTRA_FOLDERNAME);
|
||||||
setTitle(folderName);
|
setTitle(folderName);
|
||||||
|
|
||||||
|
@ -29,12 +27,4 @@ public class FolderReading extends Reading {
|
||||||
getLoaderManager().initLoader(0, null, this);
|
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.
|
* 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
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
|
|
|
@ -30,10 +30,4 @@ public class SavedStoriesReading extends Reading {
|
||||||
super.onLoadFinished(loader, cursor);
|
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);
|
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);
|
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) {
|
public void enqueueAction(ReadingAction ra) {
|
||||||
dbRW.insertOrThrow(DatabaseConstants.ACTION_TABLE, null, ra.toContentValues());
|
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});
|
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) {
|
public Cursor getStory(String hash) {
|
||||||
String q = "SELECT * FROM " + DatabaseConstants.STORY_TABLE +
|
String q = "SELECT * FROM " + DatabaseConstants.STORY_TABLE +
|
||||||
" WHERE " + DatabaseConstants.STORY_HASH + " = ?";
|
" WHERE " + DatabaseConstants.STORY_HASH + " = ?";
|
||||||
|
@ -434,8 +412,12 @@ public class BlurDatabaseHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Cursor getStoriesCursor(FeedSet fs, int stateFilter) {
|
public Cursor getStoriesCursor(FeedSet fs, int stateFilter) {
|
||||||
StoryOrder order = PrefsUtils.getStoryOrder(context, fs);
|
|
||||||
ReadFilter readFilter = PrefsUtils.getReadFilter(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) {
|
if (fs.getSingleFeed() != null) {
|
||||||
|
|
||||||
|
|
|
@ -339,13 +339,18 @@ public class DatabaseConstants {
|
||||||
// When a user is viewing "unread only" stories, what they really want are stories that were unread when they started reading,
|
// 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!
|
// or else the selection set will constantly change as they see things!
|
||||||
q.append(" AND ((" + STORY_READ + " = 0) OR (" + STORY_READ_THIS_SESSION + " = 1))");
|
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));
|
q.append(" AND " + getStorySelectionFromState(stateFilter));
|
||||||
if (dedupCol != null) {
|
if (dedupCol != null) {
|
||||||
q.append( " GROUP BY " + dedupCol);
|
q.append( " GROUP BY " + dedupCol);
|
||||||
}
|
}
|
||||||
|
if (order != null) {
|
||||||
q.append(" ORDER BY " + getStorySortOrder(order));
|
q.append(" ORDER BY " + getStorySortOrder(order));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Selection args to filter stories.
|
* Selection args to filter stories.
|
||||||
|
|
|
@ -2,11 +2,11 @@ package com.newsblur.util;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enum to represent read_filter when fetching feeds
|
* Enum to represent read_filter when fetching feeds
|
||||||
* @author mark
|
|
||||||
*/
|
*/
|
||||||
public enum ReadFilter {
|
public enum ReadFilter {
|
||||||
ALL("all"),
|
ALL("all"),
|
||||||
UNREAD("unread");
|
UNREAD("unread"), // in the app, this often means "unread and read since switching activities"
|
||||||
|
PURE_UNREAD("unread");
|
||||||
|
|
||||||
private String parameterValue;
|
private String parameterValue;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue