Fixing a long-standing iPhone bug: returning to the app meant losing the position of the current feed. Now reading stories will correctly update the feed, even if it is in multiple folders. Progress!

This commit is contained in:
Samuel Clay 2011-10-18 17:44:05 -07:00
parent 81f3f4f05a
commit 90f2ee3327
4 changed files with 47 additions and 24 deletions

View file

@ -36,7 +36,6 @@
int originalStoryCount;
NSInteger selectedIntelligence;
NSMutableArray * recentlyReadStories;
NSIndexPath * activeFeedIndexPath;
NSMutableArray * readStories;
NSDictionary * dictFolders;
@ -64,7 +63,6 @@
@property (readwrite) int originalStoryCount;
@property (readwrite) NSInteger selectedIntelligence;
@property (readwrite, retain) NSMutableArray * recentlyReadStories;
@property (readwrite, retain) NSIndexPath * activeFeedIndexPath;
@property (readwrite, retain) NSMutableArray * readStories;
@property (nonatomic, retain) NSDictionary *dictFolders;

View file

@ -36,7 +36,6 @@
@synthesize selectedIntelligence;
@synthesize activeOriginalStoryURL;
@synthesize recentlyReadStories;
@synthesize activeFeedIndexPath;
@synthesize readStories;
@synthesize dictFolders;
@ -80,7 +79,6 @@
[activeStory release];
[activeOriginalStoryURL release];
[recentlyReadStories release];
[activeFeedIndexPath release];
[readStories release];
[dictFolders release];
@ -304,29 +302,39 @@
if (activeLocation == -1) {
return;
}
id feedId = [self.activeFeed objectForKey:@"id"];
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
int activeIndex = [[activeFeedStoryLocations objectAtIndex:activeLocation] intValue];
NSDictionary *feed = [self.dictFeeds objectForKey:feedIdStr];
NSDictionary *story = [activeFeedStories objectAtIndex:activeIndex];
[story setValue:[NSNumber numberWithInt:1] forKey:@"read_status"];
[self.recentlyReadStories addObject:[NSNumber numberWithInt:activeLocation]];
int score = [NewsBlurAppDelegate computeStoryScore:[story objectForKey:@"intelligence"]];
if (score > 0) {
int unreads = MAX(0, [[activeFeed objectForKey:@"ps"] intValue] - 1);
[self.activeFeed setValue:[NSNumber numberWithInt:unreads] forKey:@"ps"];
int unreads = MAX(0, [[feed objectForKey:@"ps"] intValue] - 1);
[feed setValue:[NSNumber numberWithInt:unreads] forKey:@"ps"];
} else if (score == 0) {
int unreads = MAX(0, [[activeFeed objectForKey:@"nt"] intValue] - 1);
[self.activeFeed setValue:[NSNumber numberWithInt:unreads] forKey:@"nt"];
int unreads = MAX(0, [[feed objectForKey:@"nt"] intValue] - 1);
[feed setValue:[NSNumber numberWithInt:unreads] forKey:@"nt"];
} else if (score < 0) {
int unreads = MAX(0, [[activeFeed objectForKey:@"ng"] intValue] - 1);
[self.activeFeed setValue:[NSNumber numberWithInt:unreads] forKey:@"ng"];
int unreads = MAX(0, [[feed objectForKey:@"ng"] intValue] - 1);
[feed setValue:[NSNumber numberWithInt:unreads] forKey:@"ng"];
}
[self.dictFeeds setValue:feed forKey:feedIdStr];
// NSLog(@"Marked read %d-%d: %@: %d", activeIndex, activeLocation, self.recentlyReadStories, score);
}
- (void)markActiveFeedAllRead {
[self.activeFeed setValue:[NSNumber numberWithInt:0] forKey:@"ps"];
[self.activeFeed setValue:[NSNumber numberWithInt:0] forKey:@"nt"];
[self.activeFeed setValue:[NSNumber numberWithInt:0] forKey:@"ng"];
id feedId = [self.activeFeed objectForKey:@"id"];
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
NSDictionary *feed = [self.dictFeeds objectForKey:feedIdStr];
[feed setValue:[NSNumber numberWithInt:0] forKey:@"ps"];
[feed setValue:[NSNumber numberWithInt:0] forKey:@"nt"];
[feed setValue:[NSNumber numberWithInt:0] forKey:@"ng"];
[self.dictFeeds setValue:feed forKey:feedIdStr];
}
- (void)calculateStoryLocations {

View file

@ -72,12 +72,28 @@
- (void)viewWillAppear:(BOOL)animated {
[self.feedTitlesTable deselectRowAtIndexPath:[feedTitlesTable indexPathForSelectedRow]
animated:animated];
if (appDelegate.activeFeedIndexPath && [appDelegate activeFeed]) {
NSLog(@"Refreshing feed at %d / %d: %@", appDelegate.activeFeedIndexPath.section, appDelegate.activeFeedIndexPath.row, [appDelegate activeFeed]);
// If there is an active feed, we need to update its table row to match
// the updated unread counts.
if ([appDelegate activeFeed]) {
NSMutableArray *indexPaths = [NSMutableArray array];
for (int s=0; s < [appDelegate.dictFoldersArray count]; s++) {
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:s];
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
NSArray *originalFolder = [appDelegate.dictFolders objectForKey:folderName];
for (int f=0; f < [activeFolderFeeds count]; f++) {
int location = [[activeFolderFeeds objectAtIndex:f] intValue];
id feedId = [originalFolder objectAtIndex:location];
if ([feedId compare:[appDelegate.activeFeed objectForKey:@"id"]] == NSOrderedSame) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:f inSection:s];
[indexPaths addObject:indexPath];
}
}
}
// NSLog(@"Refreshing feed at %@: %@", indexPaths, [appDelegate activeFeed]);
[self.feedTitlesTable beginUpdates];
[self.feedTitlesTable
reloadRowsAtIndexPaths:[NSArray
arrayWithObject:appDelegate.activeFeedIndexPath]
reloadRowsAtIndexPaths:indexPaths
withRowAnimation:UITableViewRowAnimationNone];
[self.feedTitlesTable endUpdates];
@ -106,7 +122,7 @@
}
- (void)viewDidAppear:(BOOL)animated {
appDelegate.activeFeed = nil;
// appDelegate.activeFeed = nil;
[super viewDidAppear:animated];
}
@ -160,7 +176,7 @@
#pragma mark Initialization
- (void)returnToApp {
NSDate *decayDate = [[NSDate alloc] initWithTimeIntervalSinceNow:(-10*60)];
NSDate *decayDate = [[NSDate alloc] initWithTimeIntervalSinceNow:(BACKGROUND_REFRESH_SECONDS)];
NSLog(@"Last Update: %@ - %f", self.lastUpdate, [self.lastUpdate timeIntervalSinceDate:decayDate]);
if ([self.lastUpdate timeIntervalSinceDate:decayDate] < 0) {
[self fetchFeedList:YES];
@ -169,7 +185,7 @@
}
- (void)fetchFeedList:(BOOL)showLoader {
// NSLog(@"fetchFeedList: %d %d", showLoader, appDelegate.navigationController.topViewController == appDelegate.feedsViewController);
// NSLog(@"fetchFeedList: %d %d %@", showLoader, appDelegate.navigationController.topViewController == appDelegate.feedsViewController, [appDelegate activeFeed]);
if (showLoader && appDelegate.navigationController.topViewController == appDelegate.feedsViewController) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
@ -192,7 +208,6 @@
[request startAsynchronous];
self.lastUpdate = [NSDate date];
[appDelegate setActiveFeedIndexPath:nil];
}
- (void)finishedWithError:(ASIHTTPRequest *)request {
@ -415,7 +430,6 @@ didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}
[appDelegate setActiveFeed:feed];
[appDelegate setActiveFeedIndexPath:indexPath];
appDelegate.readStories = [NSMutableArray array];
[appDelegate loadFeedDetailView];

View file

@ -5,13 +5,16 @@
#ifdef __OBJC__
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "TestFlight.h"
// #import "TestFlight.h"
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
#define BACKGROUND_REFRESH_SECONDS -10*60
// #define BACKGROUND_REFRESH_SECONDS -5
// #define NEWSBLUR_URL [NSString stringWithFormat:@"nb.local.host:8000"]
#define NEWSBLUR_URL [NSString stringWithFormat:@"www.newsblur.com"]