diff --git a/media/iphone/Classes/FeedDetailViewController.m b/media/iphone/Classes/FeedDetailViewController.m index d2f30f426..8190cad25 100644 --- a/media/iphone/Classes/FeedDetailViewController.m +++ b/media/iphone/Classes/FeedDetailViewController.m @@ -34,6 +34,21 @@ // NSLog(@"Loaded Feed view: %@", appDelegate.activeFeed); self.pageFinished = NO; self.title = [appDelegate.activeFeed objectForKey:@"feed_title"]; + + NSMutableArray *indexPaths = [NSMutableArray array]; + for (id i in appDelegate.recentlyReadStories) { + NSLog(@"Read story %d: %@", [i intValue], appDelegate.recentlyReadStories); + NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[i intValue] + inSection:0]; + [indexPaths addObject:indexPath]; + } + [appDelegate.recentlyReadStories removeAllObjects]; + if ([indexPaths count] > 0) { + NSLog(@"Having read %d stories: %@", [appDelegate.recentlyReadStories count], appDelegate.recentlyReadStories); + [self.storyTitlesTable beginUpdates]; + [self.storyTitlesTable reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; + [self.storyTitlesTable endUpdates]; + } [super viewWillAppear:animated]; } @@ -206,12 +221,9 @@ #pragma mark Table View - Feed List - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { + // The + 1 is for the finished/loading bar. int storyCount = appDelegate.storyCount; - if (self.pageFetching) { - return storyCount + 1; - } else { - return storyCount; - } + return storyCount + 1; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { diff --git a/media/iphone/Classes/NewsBlurAppDelegate.h b/media/iphone/Classes/NewsBlurAppDelegate.h index 485172c7e..4a0332cc5 100644 --- a/media/iphone/Classes/NewsBlurAppDelegate.h +++ b/media/iphone/Classes/NewsBlurAppDelegate.h @@ -31,6 +31,7 @@ NSDictionary * activeStory; NSURL * activeOriginalStoryURL; int storyCount; + NSMutableArray * recentlyReadStories; } @property (nonatomic, retain) IBOutlet UIWindow *window; @@ -49,6 +50,7 @@ @property (readwrite, retain) NSDictionary * activeStory; @property (readwrite, retain) NSURL * activeOriginalStoryURL; @property (readwrite) int storyCount; +@property (readwrite, retain) NSMutableArray * recentlyReadStories; - (void)showLogin; - (void)loadFeedDetailView; diff --git a/media/iphone/Classes/NewsBlurAppDelegate.m b/media/iphone/Classes/NewsBlurAppDelegate.m index 15bc12389..a029c9110 100644 --- a/media/iphone/Classes/NewsBlurAppDelegate.m +++ b/media/iphone/Classes/NewsBlurAppDelegate.m @@ -30,6 +30,7 @@ @synthesize activeStory; @synthesize storyCount; @synthesize activeOriginalStoryURL; +@synthesize recentlyReadStories; - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { navigationController.viewControllers = [NSArray arrayWithObject:feedsViewController]; @@ -55,6 +56,7 @@ [activeFeedStories release]; [activeStory release]; [activeOriginalStoryURL release]; + [recentlyReadStories release]; [super dealloc]; } @@ -123,12 +125,21 @@ - (int)indexOfNextStory { int activeIndex = [self indexOfActiveStory]; - NSLog(@"ActiveStory: %d", activeIndex); - NSLog(@"ActiveStory: %d", self.storyCount); + int readStatus = -1; + NSLog(@"ActiveStory: %d/%d", activeIndex, self.storyCount); for (int i=activeIndex+1; i < self.storyCount; i++) { NSDictionary *story = [activeFeedStories objectAtIndex:i]; - int readStatus = [[story objectForKey:@"read_status"] intValue]; - NSLog(@"readStatus: %@", readStatus); + readStatus = [[story objectForKey:@"read_status"] intValue]; + NSLog(@"readStatus at %d: %d", i, readStatus); + if (readStatus == 0) { + NSLog(@"NextStory: %d", i); + return i; + } + } + for (int i=activeIndex; i >= 0; i--) { + NSDictionary *story = [activeFeedStories objectAtIndex:i]; + readStatus = [[story objectForKey:@"read_status"] intValue]; + NSLog(@"readStatus at %d: %d", i, readStatus); if (readStatus == 0) { NSLog(@"NextStory: %d", i); return i; @@ -167,12 +178,15 @@ - (void)setStories:(NSArray *)activeFeedStoriesValue { self.activeFeedStories = activeFeedStoriesValue; self.storyCount = [self.activeFeedStories count]; + self.recentlyReadStories = [[NSMutableArray alloc] init]; } - (void)markActiveStoryRead { int activeIndex = [self indexOfActiveStory]; NSDictionary *story = [activeFeedStories objectAtIndex:activeIndex]; [story setValue:[NSDecimalNumber numberWithInt:1] forKey:@"read_status"]; + [self.recentlyReadStories addObject:[NSNumber numberWithInt:activeIndex]]; + NSLog(@"Marked read %d: %@", activeIndex, self.recentlyReadStories); } + (int)computeStoryScore:(NSDictionary *)intelligence { diff --git a/media/iphone/Classes/StoryDetailViewController.m b/media/iphone/Classes/StoryDetailViewController.m index 2e2c47ceb..42b9a68d5 100644 --- a/media/iphone/Classes/StoryDetailViewController.m +++ b/media/iphone/Classes/StoryDetailViewController.m @@ -30,9 +30,7 @@ - (void)viewWillAppear:(BOOL)animated { [self showStory]; - if ([[appDelegate.activeStory objectForKey:@"read_status"] intValue] != 1) { - [self markStoryAsRead]; - } + [self markStoryAsRead]; [super viewWillAppear:animated]; } @@ -47,26 +45,28 @@ } - (void)markStoryAsRead { - [appDelegate markActiveStoryRead]; - - NSString *urlString = @"http://nb.local.host:8000/reader/mark_story_as_read"; - NSURL *url = [NSURL URLWithString:urlString]; - ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; - [request setPostValue:[appDelegate.activeStory objectForKey:@"id"] forKey:@"story_id"]; - [request setPostValue:[appDelegate.activeFeed objectForKey:@"id"] forKey:@"feed_id"]; - [request setDelegate:self]; - [request startAsynchronous]; + if ([[appDelegate.activeStory objectForKey:@"read_status"] intValue] != 1) { + [appDelegate markActiveStoryRead]; + + NSString *urlString = @"http://nb.local.host:8000/reader/mark_story_as_read"; + NSURL *url = [NSURL URLWithString:urlString]; + ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url]; + [request setPostValue:[appDelegate.activeStory objectForKey:@"id"] forKey:@"story_id"]; + [request setPostValue:[appDelegate.activeFeed objectForKey:@"id"] forKey:@"feed_id"]; + [request setDelegate:self]; + [request startAsynchronous]; + } } - (void)requestFinished:(ASIHTTPRequest *)request { - NSString *responseString = [request responseString]; - NSDictionary *results = [[NSDictionary alloc] - initWithDictionary:[responseString JSONValue]]; - int code = [[results valueForKey:@"code"] intValue]; - NSLog(@"Read Story: %@", code); +// NSString *responseString = [request responseString]; +// NSDictionary *results = [[NSDictionary alloc] +// initWithDictionary:[responseString JSONValue]]; +// int code = [[results valueForKey:@"code"] intValue]; +// NSLog(@"Read Story: %@", code); - [results release]; +// [results release]; } - (void)requestFailed:(ASIHTTPRequest *)request @@ -184,11 +184,12 @@ - (IBAction)doNextUnreadStory { int nextIndex = [appDelegate indexOfNextStory]; if (nextIndex == -1) { - + [appDelegate.navigationController popToViewController:[appDelegate.navigationController.viewControllers objectAtIndex:0] animated:YES]; } else { [appDelegate setActiveStory:[[appDelegate activeFeedStories] objectAtIndex:nextIndex]]; [self showStory]; - + [self markStoryAsRead]; + [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.5]; [UIView setAnimationBeginsFromCurrentState:NO]; @@ -198,12 +199,13 @@ } - (IBAction)doPreviousStory { - NSInteger nextIndex = [appDelegate indexOfPreviousStory]; + int nextIndex = [appDelegate indexOfPreviousStory]; if (nextIndex == -1) { - + [appDelegate.navigationController popToViewController:[appDelegate.navigationController.viewControllers objectAtIndex:0] animated:YES]; } else { [appDelegate setActiveStory:[[appDelegate activeFeedStories] objectAtIndex:nextIndex]]; [self showStory]; + [self markStoryAsRead]; [UIView beginAnimations:nil context:nil]; [UIView setAnimationDuration:.5];