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

View file

@ -36,6 +36,7 @@
@synthesize activeOriginalStoryURL;
@synthesize recentlyReadStories;
@synthesize activeFeedIndexPath;
@synthesize readStories;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
navigationController.viewControllers = [NSArray arrayWithObject:feedsViewController];
@ -73,6 +74,7 @@
[activeOriginalStoryURL release];
[recentlyReadStories release];
[activeFeedIndexPath release];
[readStories release];
[super dealloc];
}
@ -194,6 +196,31 @@
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 total = 0;
total += [[self.activeFeed objectForKey:@"ps"] intValue];
@ -225,10 +252,10 @@
- (void)markActiveStoryRead {
int activeLocation = [self locationOfActiveStory];
int activeIndex = [[activeFeedStoryLocations objectAtIndex:activeLocation] intValue];
if (activeLocation == -1) {
return;
}
int activeIndex = [[activeFeedStoryLocations objectAtIndex:activeLocation] intValue];
NSDictionary *story = [activeFeedStories objectAtIndex:activeIndex];
[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 setActiveFeedIndexPath:indexPath];
appDelegate.readStories = [NSMutableArray array];
[appDelegate loadFeedDetailView];
}

View file

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