Mark-read idempotency for social feeds. (#460)

This commit is contained in:
ojiikun 2014-01-14 11:10:48 +00:00
parent 583ffb4553
commit 5f7db73f89
4 changed files with 39 additions and 17 deletions

View file

@ -151,8 +151,9 @@ public abstract class Reading extends NbFragmentActivity implements OnPageChange
if (this.pager == null) {
// if this is the first time we've found a cursor, we know the onCreate chain is done
setupPager();
this.startingUnreadCount = getUnreadCount();
// set up the pager after the unread count, so the first mark-read doesn't happen too quickly
setupPager();
}
try {

View file

@ -347,6 +347,18 @@ public class FeedProvider extends ContentProvider {
public Cursor query(String table, String[] columns, String selection, String[] selectionArgs, String groupBy, String having, String orderBy) {
return mdb.query(table, columns, selection, selectionArgs, groupBy, having, orderBy);
}
public void execSQL(String sql) {
if (AppConstants.VERBOSE_LOG) {
Log.d(LoggingDatabase.class.getName(), "execSQL: " + sql);
}
mdb.execSQL(sql);
}
public int update(String table, ContentValues values, String whereClause, String[] whereArgs) {
return mdb.update(table, values, whereClause, whereArgs);
}
public long insertWithOnConflict(String table, String nullColumnHack, ContentValues initialValues, int conflictAlgorithm) {
return mdb.insertWithOnConflict(table, nullColumnHack, initialValues, conflictAlgorithm);
}
}
@Override
@ -603,7 +615,8 @@ public class FeedProvider extends ContentProvider {
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
final SQLiteDatabase db = databaseHelper.getWritableDatabase();
final SQLiteDatabase rwdb = databaseHelper.getWritableDatabase();
final LoggingDatabase db = new LoggingDatabase(rwdb);
switch (uriMatcher.match(uri)) {
case ALL_FEEDS:
@ -622,10 +635,10 @@ public class FeedProvider extends ContentProvider {
// In order to run a raw SQL query whereby we make decrement the column we need to a dynamic reference - something the usual content provider can't easily handle. Hence this circuitous hack.
case FEED_COUNT:
db.execSQL("UPDATE " + DatabaseConstants.FEED_TABLE + " SET " + selectionArgs[0] + " = " + selectionArgs[0] + " - 1 WHERE " + DatabaseConstants.FEED_ID + " = " + selectionArgs[1]);
return 0;
return 1;
case SOCIALFEED_COUNT:
db.execSQL("UPDATE " + DatabaseConstants.SOCIALFEED_TABLE + " SET " + selectionArgs[0] + " = " + selectionArgs[0] + " - 1 WHERE " + DatabaseConstants.SOCIAL_FEED_ID + " = " + selectionArgs[1]);
return 0;
return 1;
case STARRED_STORIES_COUNT:
int rows = db.update(DatabaseConstants.STARRED_STORY_COUNT_TABLE, values, null, null);
if (rows == 0 ) {

View file

@ -5,7 +5,7 @@ public class AppConstants {
// Enables high-volume logging that may be useful for debugging. This should
// never be enabled for releases, as it not only slows down the app considerably,
// it will log sensitive info such as passwords!
public static final boolean VERBOSE_LOG = false;
public static final boolean VERBOSE_LOG = true;
public static final int STATE_ALL = 0;
public static final int STATE_SOME = 1;

View file

@ -320,20 +320,28 @@ public class FeedUtils {
} else {
selectionArgs = new String[] { DatabaseConstants.FEED_NEGATIVE_COUNT, story.feedId } ;
}
operations.add(ContentProviderOperation.newUpdate(FeedProvider.FEED_COUNT_URI).withValues(emptyValues).withSelection("", selectionArgs).build());
if (!TextUtils.isEmpty(story.socialUserId)) {
String[] socialSelectionArgs;
if (story.getIntelligenceTotal() > 0) {
socialSelectionArgs = new String[] { DatabaseConstants.SOCIAL_FEED_POSITIVE_COUNT, story.socialUserId } ;
} else if (story.getIntelligenceTotal() == 0) {
socialSelectionArgs = new String[] { DatabaseConstants.SOCIAL_FEED_NEUTRAL_COUNT, story.socialUserId } ;
} else {
socialSelectionArgs = new String[] { DatabaseConstants.SOCIAL_FEED_NEGATIVE_COUNT, story.socialUserId } ;
}
operations.add(ContentProviderOperation.newUpdate(FeedProvider.SOCIALCOUNT_URI).withValues(emptyValues).withSelection("", socialSelectionArgs).build());
}
HashSet<String> socialIds = new HashSet<String>();
if (!TextUtils.isEmpty(story.socialUserId)) {
socialIds.add(story.socialUserId);
}
if (story.friendUserIds != null) {
for (String id : story.friendUserIds) {
socialIds.add(id);
}
}
for (String id : socialIds) {
String[] socialSelectionArgs;
if (story.getIntelligenceTotal() > 0) {
socialSelectionArgs = new String[] { DatabaseConstants.SOCIAL_FEED_POSITIVE_COUNT, id } ;
} else if (story.getIntelligenceTotal() == 0) {
socialSelectionArgs = new String[] { DatabaseConstants.SOCIAL_FEED_NEUTRAL_COUNT, id } ;
} else {
socialSelectionArgs = new String[] { DatabaseConstants.SOCIAL_FEED_NEGATIVE_COUNT, id } ;
}
operations.add(ContentProviderOperation.newUpdate(FeedProvider.SOCIALCOUNT_URI).withValues(emptyValues).withSelection("", socialSelectionArgs).build());
}
Uri storyUri = FeedProvider.STORY_URI.buildUpon().appendPath(story.id).build();
ContentValues values = new ContentValues();