better atomic flagging for story session resets by sync service

This commit is contained in:
dosiecki 2016-10-28 18:58:04 -07:00
parent 895e784dc2
commit f370ac5cd8
2 changed files with 12 additions and 6 deletions

View file

@ -69,6 +69,8 @@ public abstract class ItemListFragment extends NbFragment implements OnScrollLis
super.onCreate(savedInstanceState);
defaultFeedView = (DefaultFeedView)getArguments().getSerializable("defaultFeedView");
activity = (ItemsList) getActivity();
// tell the sync service to discard the reading session at the start of the next sync, just in case
NBSyncService.resetReadingSession();
}
@Override

View file

@ -633,17 +633,21 @@ public class NBSyncService extends Service {
StoryOrder order = PrefsUtils.getStoryOrder(this, fs);
ReadFilter filter = PrefsUtils.getReadFilter(this, fs);
boolean doReset = false;
synchronized (PENDING_FEED_MUTEX) {
if (ResetSession) {
// the next fetch will be the start of a new reading session; clear it so it
// will be re-primed
dbHelper.clearStorySession();
// don't just rely on the auto-prepare code when fetching stories, it might be called
// after we insert our first page and not trigger
dbHelper.prepareReadingSession(fs);
doReset = true;
ResetSession = false;
}
}
if (doReset) {
// the next fetch will be the start of a new reading session; clear it so it
// will be re-primed
dbHelper.clearStorySession();
// don't just rely on the auto-prepare code when fetching stories, it might be called
// after we insert our first page and not trigger
dbHelper.prepareReadingSession(fs);
}
while (totalStoriesSeen < PendingFeedTarget) {
if (stopSync()) return;