Workaround for un-foldered feeds messing up unread counts.

This commit is contained in:
ojiikun 2013-06-13 19:35:49 +00:00
parent d9849cf9eb
commit 65ff10470b

View file

@ -482,6 +482,9 @@ public class APIManager {
final APIResponse response = client.get(APIConstants.URL_FEEDS, params);
final FeedFolderResponse feedUpdate = new FeedFolderResponse(response.responseString, gson);
// there is a rare issue with feeds that have no folder. capture them for debug.
List<String> debugFeedIds = new ArrayList<String>();
if (response.responseCode == HttpStatus.SC_OK && !response.hasRedirected) {
@ -495,21 +498,7 @@ public class APIManager {
// this actually cleans out the feed, folder, and story tables
contentResolver.delete(FeedProvider.FEEDS_URI, null, null);
// populate the feeds table
List<ContentValues> feedValues = new ArrayList<ContentValues>();
for (String newFeedId : feedUpdate.feeds.keySet()) {
feedValues.add(feedUpdate.feeds.get(newFeedId).getValues());
}
bulkInsertList(FeedProvider.FEEDS_URI, feedValues);
// populate the social feeds table
List<ContentValues> socialFeedValues = new ArrayList<ContentValues>();
for (final SocialFeed feed : feedUpdate.socialFeeds) {
socialFeedValues.add(feed.getValues());
}
bulkInsertList(FeedProvider.SOCIAL_FEEDS_URI, socialFeedValues);
// populate the folder and folder-feed-mapping tables
// data for the folder and folder-feed-mapping tables
List<ContentValues> folderValues = new ArrayList<ContentValues>();
List<ContentValues> ffmValues = new ArrayList<ContentValues>();
for (final Entry<String, List<Long>> entry : feedUpdate.folders.entrySet()) {
@ -526,9 +515,32 @@ public class APIManager {
values.put(DatabaseConstants.FEED_FOLDER_FEED_ID, feedId);
values.put(DatabaseConstants.FEED_FOLDER_FOLDER_NAME, folderName);
ffmValues.add(values);
// note all feeds that belong to some folder
debugFeedIds.add(Long.toString(feedId));
}
}
}
// data for the feeds table
List<ContentValues> feedValues = new ArrayList<ContentValues>();
for (String feedId : feedUpdate.feeds.keySet()) {
// sanity-check that the returned feeds actually exist in a folder or at the root
// if they do not, they should neither display nor count towards unread numbers
if (debugFeedIds.contains(feedId)) {
feedValues.add(feedUpdate.feeds.get(feedId).getValues());
} else {
Log.w(this.getClass().getName(), "Found and ignoring un-foldered feed: " + feedId );
}
}
// data for the the social feeds table
List<ContentValues> socialFeedValues = new ArrayList<ContentValues>();
for (final SocialFeed feed : feedUpdate.socialFeeds) {
socialFeedValues.add(feed.getValues());
}
bulkInsertList(FeedProvider.SOCIAL_FEEDS_URI, socialFeedValues);
bulkInsertList(FeedProvider.FEEDS_URI, feedValues);
bulkInsertList(FeedProvider.FOLDERS_URI, folderValues);
bulkInsertList(FeedProvider.FEED_FOLDER_MAP_URI, ffmValues);