Making the previous button take you to the previous story you read. Obviously.

This commit is contained in:
Samuel Clay 2011-08-22 18:25:33 -07:00
parent f5a4e09751
commit f1c85d15ec
4 changed files with 50 additions and 6 deletions

View file

@ -37,6 +37,7 @@
NSInteger selectedIntelligence; NSInteger selectedIntelligence;
NSMutableArray * recentlyReadStories; NSMutableArray * recentlyReadStories;
NSIndexPath * activeFeedIndexPath; NSIndexPath * activeFeedIndexPath;
NSMutableArray * readStories;
} }
@property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UIWindow *window;
@ -61,6 +62,7 @@
@property (readwrite) NSInteger selectedIntelligence; @property (readwrite) NSInteger selectedIntelligence;
@property (readwrite, retain) NSMutableArray * recentlyReadStories; @property (readwrite, retain) NSMutableArray * recentlyReadStories;
@property (readwrite, retain) NSIndexPath * activeFeedIndexPath; @property (readwrite, retain) NSIndexPath * activeFeedIndexPath;
@property (readwrite, retain) NSMutableArray * readStories;
- (void)showLogin; - (void)showLogin;
- (void)loadFeedDetailView; - (void)loadFeedDetailView;
@ -71,10 +73,15 @@
- (void)setTitle:(NSString *)title; - (void)setTitle:(NSString *)title;
- (void)showOriginalStory:(NSURL *)url; - (void)showOriginalStory:(NSURL *)url;
- (void)closeOriginalStory; - (void)closeOriginalStory;
- (int)indexOfNextStory; - (int)indexOfNextStory;
- (int)indexOfPreviousStory; - (int)indexOfPreviousStory;
- (int)indexOfActiveStory; - (int)indexOfActiveStory;
- (int)locationOfActiveStory; - (int)locationOfActiveStory;
- (void)pushReadStory:(id)storyId;
- (id)popReadStory;
- (int)locationOfStoryId:(id)storyId;
- (void)setStories:(NSArray *)activeFeedStoriesValue; - (void)setStories:(NSArray *)activeFeedStoriesValue;
- (void)addStories:(NSArray *)stories; - (void)addStories:(NSArray *)stories;
- (int)unreadCount; - (int)unreadCount;

View file

@ -36,6 +36,7 @@
@synthesize activeOriginalStoryURL; @synthesize activeOriginalStoryURL;
@synthesize recentlyReadStories; @synthesize recentlyReadStories;
@synthesize activeFeedIndexPath; @synthesize activeFeedIndexPath;
@synthesize readStories;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
navigationController.viewControllers = [NSArray arrayWithObject:feedsViewController]; navigationController.viewControllers = [NSArray arrayWithObject:feedsViewController];
@ -73,6 +74,7 @@
[activeOriginalStoryURL release]; [activeOriginalStoryURL release];
[recentlyReadStories release]; [recentlyReadStories release];
[activeFeedIndexPath release]; [activeFeedIndexPath release];
[readStories release];
[super dealloc]; [super dealloc];
} }
@ -194,6 +196,31 @@
return -1; return -1;
} }
- (void)pushReadStory:(id)storyId {
if ([self.readStories lastObject] != storyId) {
[self.readStories addObject:storyId];
}
}
- (id)popReadStory {
if (storyCount == 0) {
return nil;
} else {
[self.readStories removeLastObject];
id lastStory = [self.readStories lastObject];
return lastStory;
}
}
- (int)locationOfStoryId:(id)storyId {
for (int i=0; i < [activeFeedStoryLocations count]; i++) {
if ([activeFeedStoryLocationIds objectAtIndex:i] == storyId) {
return [[activeFeedStoryLocations objectAtIndex:i] intValue];
}
}
return -1;
}
- (int)unreadCount { - (int)unreadCount {
int total = 0; int total = 0;
total += [[self.activeFeed objectForKey:@"ps"] intValue]; total += [[self.activeFeed objectForKey:@"ps"] intValue];
@ -225,10 +252,10 @@
- (void)markActiveStoryRead { - (void)markActiveStoryRead {
int activeLocation = [self locationOfActiveStory]; int activeLocation = [self locationOfActiveStory];
int activeIndex = [[activeFeedStoryLocations objectAtIndex:activeLocation] intValue];
if (activeLocation == -1) { if (activeLocation == -1) {
return; return;
} }
int activeIndex = [[activeFeedStoryLocations objectAtIndex:activeLocation] intValue];
NSDictionary *story = [activeFeedStories objectAtIndex:activeIndex]; NSDictionary *story = [activeFeedStories objectAtIndex:activeIndex];
[story setValue:[NSNumber numberWithInt:1] forKey:@"read_status"]; [story setValue:[NSNumber numberWithInt:1] forKey:@"read_status"];

View file

@ -409,6 +409,7 @@ blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
[appDelegate setActiveFeed:feed]; [appDelegate setActiveFeed:feed];
[appDelegate setActiveFeedIndexPath:indexPath]; [appDelegate setActiveFeedIndexPath:indexPath];
appDelegate.readStories = [NSMutableArray array];
[appDelegate loadFeedDetailView]; [appDelegate loadFeedDetailView];
} }

View file

@ -43,7 +43,9 @@
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
// NSLog(@"Stories; %@ -- %@ (%d)", self.activeStoryId, [appDelegate.activeStory objectForKey:@"id"], self.activeStoryId == [appDelegate.activeStory objectForKey:@"id"]); // NSLog(@"Stories; %@ -- %@ (%d)", self.activeStoryId, [appDelegate.activeStory objectForKey:@"id"], self.activeStoryId == [appDelegate.activeStory objectForKey:@"id"]);
if (self.activeStoryId != [appDelegate.activeStory objectForKey:@"id"]) { id storyId = [appDelegate.activeStory objectForKey:@"id"];
if (self.activeStoryId != storyId) {
[appDelegate pushReadStory:storyId];
[self setActiveStory]; [self setActiveStory];
[self showStory]; [self showStory];
[self markStoryAsRead]; [self markStoryAsRead];
@ -83,8 +85,10 @@
[buttonNext setTitle:@"Next Unread"]; [buttonNext setTitle:@"Next Unread"];
} }
int previousIndex = [appDelegate indexOfPreviousStory]; int readStoryCount = [appDelegate.readStories count];
if (previousIndex == -1) { if (readStoryCount == 0 ||
(readStoryCount == 1 &&
[appDelegate.readStories lastObject] == [appDelegate.activeStory objectForKey:@"id"])) {
[buttonPrevious setTitle:@"Done"]; [buttonPrevious setTitle:@"Done"];
} else { } else {
[buttonPrevious setTitle:@"Previous"]; [buttonPrevious setTitle:@"Previous"];
@ -255,6 +259,7 @@
} else { } else {
[appDelegate setActiveStory:[[appDelegate activeFeedStories] [appDelegate setActiveStory:[[appDelegate activeFeedStories]
objectAtIndex:nextIndex]]; objectAtIndex:nextIndex]];
[appDelegate pushReadStory:[appDelegate.activeStory objectForKey:@"id"]];
[self setActiveStory]; [self setActiveStory];
[self showStory]; [self showStory];
[self markStoryAsRead]; [self markStoryAsRead];
@ -271,13 +276,17 @@
} }
- (IBAction)doPreviousStory { - (IBAction)doPreviousStory {
int previousIndex = [appDelegate indexOfPreviousStory]; id previousStoryId = [appDelegate popReadStory];
if (previousIndex == -1) { if (!previousStoryId || previousStoryId == [appDelegate.activeStory objectForKey:@"id"]) {
[appDelegate.navigationController [appDelegate.navigationController
popToViewController:[appDelegate.navigationController.viewControllers popToViewController:[appDelegate.navigationController.viewControllers
objectAtIndex:0] objectAtIndex:0]
animated:YES]; animated:YES];
} else { } else {
int previousIndex = [appDelegate locationOfStoryId:previousStoryId];
if (previousIndex == -1) {
return [self doPreviousStory];
}
[appDelegate setActiveStory:[[appDelegate activeFeedStories] [appDelegate setActiveStory:[[appDelegate activeFeedStories]
objectAtIndex:previousIndex]]; objectAtIndex:previousIndex]];
[self setActiveStory]; [self setActiveStory];