From 7405d927d74ba24ddf18122c13a8685b3ac0a03b Mon Sep 17 00:00:00 2001 From: Samuel Clay Date: Mon, 31 Oct 2011 10:10:38 -0700 Subject: [PATCH] Fixing next/prewvious buttons in River view to include all unread stories and gracefully load new stories in river (iOS). --- media/iphone/Classes/NewsBlurAppDelegate.h | 4 +- media/iphone/Classes/NewsBlurAppDelegate.m | 41 ++++++++++++++++--- media/iphone/Classes/NewsBlurViewController.h | 4 +- media/iphone/Classes/NewsBlurViewController.m | 5 +-- .../Classes/StoryDetailViewController.m | 2 +- 5 files changed, 44 insertions(+), 12 deletions(-) diff --git a/media/iphone/Classes/NewsBlurAppDelegate.h b/media/iphone/Classes/NewsBlurAppDelegate.h index 5fff512d8..09eadbc9e 100644 --- a/media/iphone/Classes/NewsBlurAppDelegate.h +++ b/media/iphone/Classes/NewsBlurAppDelegate.h @@ -36,6 +36,7 @@ NSMutableArray * activeFeedStoryLocationIds; NSDictionary * activeStory; NSURL * activeOriginalStoryURL; + int storyCount; int originalStoryCount; NSInteger selectedIntelligence; @@ -99,7 +100,8 @@ - (void)setStories:(NSArray *)activeFeedStoriesValue; - (void)addStories:(NSArray *)stories; - (int)unreadCount; -- (int)visibleUnreadCount; +- (int)unreadCountForFeed:(NSString *)feedId; +- (int)unreadCountForFolder:(NSString *)folderName; - (void)markActiveStoryRead; - (void)markActiveFeedAllRead; - (void)calculateStoryLocations; diff --git a/media/iphone/Classes/NewsBlurAppDelegate.m b/media/iphone/Classes/NewsBlurAppDelegate.m index 13789776d..c509ae479 100644 --- a/media/iphone/Classes/NewsBlurAppDelegate.m +++ b/media/iphone/Classes/NewsBlurAppDelegate.m @@ -294,19 +294,50 @@ } - (int)unreadCount { + if (self.isRiverView) { + return [self unreadCountForFolder:nil]; + } else { + return [self unreadCountForFeed:nil]; + } +} + +- (int)unreadCountForFeed:(NSString *)feedId { int total = 0; - total += [[self.activeFeed objectForKey:@"ps"] intValue]; + NSDictionary *feed; + + if (feedId) { + NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId]; + feed = [self.dictFeeds objectForKey:feedIdStr]; + } else { + feed = self.activeFeed; + } + + total += [[feed objectForKey:@"ps"] intValue]; if ([self selectedIntelligence] <= 0) { - total += [[self.activeFeed objectForKey:@"nt"] intValue]; + total += [[feed objectForKey:@"nt"] intValue]; } if ([self selectedIntelligence] <= -1) { - total += [[self.activeFeed objectForKey:@"ng"] intValue]; + total += [[feed objectForKey:@"ng"] intValue]; } + return total; } -- (int)visibleUnreadCount { - return 0; +- (int)unreadCountForFolder:(NSString *)folderName { + int total = 0; + NSArray *folder; + + if (!folderName) { + folder = [self.dictFolders objectForKey:self.activeFolder]; + } else { + folder = [self.dictFolders objectForKey:folderName]; + } + + for (id feedId in folder) { + total += [self unreadCountForFeed:feedId]; + } + + return total; } - (void)addStories:(NSArray *)stories { diff --git a/media/iphone/Classes/NewsBlurViewController.h b/media/iphone/Classes/NewsBlurViewController.h index 32aef28ec..8c929555d 100644 --- a/media/iphone/Classes/NewsBlurViewController.h +++ b/media/iphone/Classes/NewsBlurViewController.h @@ -21,8 +21,8 @@ NewsBlurAppDelegate *appDelegate; NSMutableDictionary * activeFeedLocations; - NSMutableDictionary *stillVisibleFeeds; NSMutableDictionary *visibleFeeds; + NSMutableDictionary *stillVisibleFeeds; BOOL viewShowingAllFeeds; PullToRefreshView *pull; NSDate *lastUpdate; @@ -66,8 +66,8 @@ @property (nonatomic, retain) IBOutlet UIBarButtonItem * sitesButton; @property (nonatomic, retain) IBOutlet UIBarButtonItem * addButton; @property (nonatomic, retain) NSMutableDictionary *activeFeedLocations; -@property (nonatomic, retain) NSMutableDictionary *stillVisibleFeeds; @property (nonatomic, retain) NSMutableDictionary *visibleFeeds; +@property (nonatomic, retain) NSMutableDictionary *stillVisibleFeeds; @property (nonatomic, readwrite) BOOL viewShowingAllFeeds; @property (nonatomic, retain) PullToRefreshView *pull; @property (nonatomic, retain) NSDate *lastUpdate; diff --git a/media/iphone/Classes/NewsBlurViewController.m b/media/iphone/Classes/NewsBlurViewController.m index fc3fced1d..2147bd00d 100644 --- a/media/iphone/Classes/NewsBlurViewController.m +++ b/media/iphone/Classes/NewsBlurViewController.m @@ -28,8 +28,8 @@ @synthesize logoutButton; @synthesize intelligenceControl; @synthesize activeFeedLocations; -@synthesize stillVisibleFeeds; @synthesize visibleFeeds; +@synthesize stillVisibleFeeds; @synthesize sitesButton; @synthesize addButton; @synthesize viewShowingAllFeeds; @@ -163,8 +163,8 @@ [logoutButton release]; [intelligenceControl release]; [activeFeedLocations release]; - [stillVisibleFeeds release]; [visibleFeeds release]; + [stillVisibleFeeds release]; [sitesButton release]; [addButton release]; [pull release]; @@ -507,7 +507,6 @@ viewForHeaderInSection:(NSInteger)section { } - (IBAction)sectionTapped:(UIButton *)button { - NSLog(@"touch view: %@", button); button.backgroundColor = [UIColor blackColor]; } diff --git a/media/iphone/Classes/StoryDetailViewController.m b/media/iphone/Classes/StoryDetailViewController.m index 24a94a222..c3839b0cc 100644 --- a/media/iphone/Classes/StoryDetailViewController.m +++ b/media/iphone/Classes/StoryDetailViewController.m @@ -133,7 +133,7 @@ [buttonPrevious setTitle:@"Previous"]; } - float unreads = [appDelegate unreadCount]; + float unreads = (float)[appDelegate unreadCount]; float total = [appDelegate originalStoryCount]; float progress = (total - unreads) / total; // NSLog(@"Total: %f / %f = %f", unreads, total, progress);