2010-06-17 13:10:45 -04:00
|
|
|
//
|
|
|
|
// NewsBlurAppDelegate.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 6/16/10.
|
2010-06-21 17:17:26 -04:00
|
|
|
// Copyright NewsBlur 2010. All rights reserved.
|
2010-06-17 13:10:45 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
|
|
|
#import "NewsBlurViewController.h"
|
2010-06-21 17:17:26 -04:00
|
|
|
#import "FeedDetailViewController.h"
|
2010-06-25 18:36:01 -04:00
|
|
|
#import "StoryDetailViewController.h"
|
2010-10-31 23:02:13 -04:00
|
|
|
#import "LoginViewController.h"
|
2010-11-13 18:32:43 -05:00
|
|
|
#import "OriginalStoryViewController.h"
|
2010-06-17 13:10:45 -04:00
|
|
|
|
|
|
|
@implementation NewsBlurAppDelegate
|
|
|
|
|
|
|
|
@synthesize window;
|
2010-06-21 17:17:26 -04:00
|
|
|
@synthesize navigationController;
|
|
|
|
@synthesize feedsViewController;
|
2010-06-24 12:53:50 -04:00
|
|
|
@synthesize feedDetailViewController;
|
2010-06-25 18:36:01 -04:00
|
|
|
@synthesize storyDetailViewController;
|
2010-10-31 23:02:13 -04:00
|
|
|
@synthesize loginViewController;
|
2010-11-13 18:32:43 -05:00
|
|
|
@synthesize originalStoryViewController;
|
2010-06-17 13:10:45 -04:00
|
|
|
|
2010-11-13 18:32:43 -05:00
|
|
|
@synthesize logoutDelegate;
|
|
|
|
@synthesize activeUsername;
|
2010-06-25 18:36:01 -04:00
|
|
|
@synthesize activeFeed;
|
|
|
|
@synthesize activeFeedStories;
|
|
|
|
@synthesize activeStory;
|
2010-11-13 18:32:43 -05:00
|
|
|
@synthesize activeOriginalStoryURL;
|
2010-06-17 13:10:45 -04:00
|
|
|
|
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
2010-06-21 17:17:26 -04:00
|
|
|
navigationController.viewControllers = [NSArray arrayWithObject:feedsViewController];
|
2010-06-17 13:10:45 -04:00
|
|
|
|
2010-06-21 17:17:26 -04:00
|
|
|
[window addSubview:navigationController.view];
|
2010-06-17 13:10:45 -04:00
|
|
|
[window makeKeyAndVisible];
|
2010-11-11 23:48:27 -05:00
|
|
|
|
|
|
|
[feedsViewController fetchFeedList];
|
2010-06-25 18:36:01 -04:00
|
|
|
|
2010-06-17 13:10:45 -04:00
|
|
|
return YES;
|
|
|
|
}
|
2010-11-11 20:05:53 -05:00
|
|
|
|
2010-06-17 13:10:45 -04:00
|
|
|
- (void)dealloc {
|
2010-06-21 17:17:26 -04:00
|
|
|
[feedsViewController release];
|
2010-06-24 12:53:50 -04:00
|
|
|
[feedDetailViewController release];
|
2010-06-25 18:36:01 -04:00
|
|
|
[storyDetailViewController release];
|
2010-10-31 23:02:13 -04:00
|
|
|
[loginViewController release];
|
2010-11-13 18:32:43 -05:00
|
|
|
[originalStoryViewController release];
|
2010-06-21 17:17:26 -04:00
|
|
|
[navigationController release];
|
2010-06-17 13:10:45 -04:00
|
|
|
[window release];
|
2010-11-13 18:32:43 -05:00
|
|
|
[activeUsername release];
|
2010-06-25 18:36:01 -04:00
|
|
|
[activeFeed release];
|
|
|
|
[activeFeedStories release];
|
|
|
|
[activeStory release];
|
2010-11-13 18:32:43 -05:00
|
|
|
[activeOriginalStoryURL release];
|
2010-06-17 13:10:45 -04:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2010-06-21 17:17:26 -04:00
|
|
|
- (void)hideNavigationBar:(BOOL)animated {
|
|
|
|
[[self navigationController] setNavigationBarHidden:YES animated:animated];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)showNavigationBar:(BOOL)animated {
|
|
|
|
[[self navigationController] setNavigationBarHidden:NO animated:animated];
|
|
|
|
}
|
2010-06-17 13:10:45 -04:00
|
|
|
|
2010-06-24 00:22:26 -04:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Views
|
|
|
|
|
2010-11-11 23:48:27 -05:00
|
|
|
- (void)showLogin {
|
|
|
|
UINavigationController *navController = self.navigationController;
|
|
|
|
[navController presentModalViewController:loginViewController animated:YES];
|
|
|
|
}
|
|
|
|
|
2010-11-11 20:05:53 -05:00
|
|
|
- (void)reloadFeedsView {
|
|
|
|
NSLog(@"Reloading feeds list");
|
2010-11-11 23:48:27 -05:00
|
|
|
[self setTitle:@"NewsBlur"];
|
2010-11-11 20:05:53 -05:00
|
|
|
[feedsViewController fetchFeedList];
|
2010-11-13 13:42:20 -05:00
|
|
|
[loginViewController dismissModalViewControllerAnimated:YES];
|
2010-11-13 18:32:43 -05:00
|
|
|
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.6];
|
2010-11-11 20:05:53 -05:00
|
|
|
}
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
- (void)loadFeedDetailView {
|
2010-06-24 00:22:26 -04:00
|
|
|
UINavigationController *navController = self.navigationController;
|
2010-11-13 18:32:43 -05:00
|
|
|
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@"All" style:UIBarButtonItemStylePlain target:nil action:nil];
|
|
|
|
navController.navigationItem.backBarButtonItem = backButton;
|
|
|
|
[backButton release];
|
2010-06-24 00:22:26 -04:00
|
|
|
[navController pushViewController:feedDetailViewController animated:YES];
|
2011-07-20 22:21:11 -07:00
|
|
|
[feedDetailViewController fetchFeedDetail:1];
|
2010-11-13 13:42:20 -05:00
|
|
|
[self showNavigationBar:YES];
|
2010-11-13 18:32:43 -05:00
|
|
|
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.8];
|
2010-06-25 18:36:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadStoryDetailView {
|
|
|
|
UINavigationController *navController = self.navigationController;
|
|
|
|
[navController pushViewController:storyDetailViewController animated:YES];
|
2010-11-13 18:32:43 -05:00
|
|
|
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
2010-06-24 00:22:26 -04:00
|
|
|
}
|
|
|
|
|
2010-11-11 23:48:27 -05:00
|
|
|
- (void)setTitle:(NSString *)title {
|
|
|
|
UILabel *label = [[UILabel alloc] init];
|
|
|
|
[label setFont:[UIFont boldSystemFontOfSize:16.0]];
|
|
|
|
[label setBackgroundColor:[UIColor clearColor]];
|
|
|
|
[label setTextColor:[UIColor whiteColor]];
|
|
|
|
[label setText:title];
|
|
|
|
[label sizeToFit];
|
|
|
|
[navigationController.navigationBar.topItem setTitleView:label];
|
|
|
|
[label release];
|
|
|
|
}
|
2010-06-24 00:22:26 -04:00
|
|
|
|
2010-11-13 18:32:43 -05:00
|
|
|
- (void)showOriginalStory:(NSURL *)url {
|
|
|
|
self.activeOriginalStoryURL = url;
|
|
|
|
UINavigationController *navController = self.navigationController;
|
|
|
|
[navController presentModalViewController:originalStoryViewController animated:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)closeOriginalStory {
|
|
|
|
[originalStoryViewController dismissModalViewControllerAnimated:YES];
|
|
|
|
}
|
2010-06-24 00:22:26 -04:00
|
|
|
|
2011-06-15 11:21:55 -04:00
|
|
|
- (int)indexOfNextStory {
|
|
|
|
int activeIndex = [self indexOfActiveStory];
|
2011-06-16 09:02:40 -04:00
|
|
|
NSUInteger activeFeedStoriesCount = [activeFeedStories count];
|
|
|
|
NSLog(@"ActiveStory: %d", activeIndex);
|
|
|
|
NSLog(@"ActiveStory: %d", activeFeedStoriesCount);
|
2011-06-15 11:21:55 -04:00
|
|
|
for (int i=activeIndex+1; i < activeFeedStoriesCount; i++) {
|
|
|
|
NSDictionary *story = [activeFeedStories objectAtIndex:i];
|
2011-06-16 09:02:40 -04:00
|
|
|
NSDecimalNumber *readStatus = [story objectForKey:@"read_status"];
|
|
|
|
NSLog(@"readStatus: %@", readStatus);
|
|
|
|
if (readStatus == 0) {
|
|
|
|
NSLog(@"NextStory: %d", i);
|
2011-06-15 11:21:55 -04:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)indexOfPreviousStory {
|
|
|
|
NSInteger activeIndex = [self indexOfActiveStory];
|
|
|
|
for (int i=activeIndex-1; i >= 0; i--) {
|
|
|
|
NSDictionary *story = [activeFeedStories objectAtIndex:i];
|
|
|
|
if ([story objectForKey:@"read_status"] == 1) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)indexOfActiveStory {
|
2011-06-14 10:35:33 -04:00
|
|
|
for (int i=0; i < [activeFeedStories count]; i++) {
|
2011-06-15 11:21:55 -04:00
|
|
|
NSDictionary *story = [activeFeedStories objectAtIndex:i];
|
|
|
|
if ([activeStory objectForKey:@"id"] == [story objectForKey:@"id"]) {
|
|
|
|
return i;
|
2011-06-14 10:35:33 -04:00
|
|
|
}
|
|
|
|
}
|
2011-06-15 11:21:55 -04:00
|
|
|
return -1;
|
2011-06-14 10:35:33 -04:00
|
|
|
}
|
|
|
|
|
2011-07-20 22:21:11 -07:00
|
|
|
- (void)addActiveFeedStories:(NSArray *)stories {
|
2011-07-22 09:10:13 -07:00
|
|
|
// NSLog(@"Adding: %d to %@", [stories count], stories);
|
2011-07-20 22:21:11 -07:00
|
|
|
self.activeFeedStories = [self.activeFeedStories arrayByAddingObjectsFromArray:stories];
|
|
|
|
}
|
|
|
|
|
2010-11-22 10:44:52 -05:00
|
|
|
+ (int)computeStoryScore:(NSDictionary *)intelligence {
|
|
|
|
int score = 0;
|
2011-03-09 18:23:55 -05:00
|
|
|
// int score_max = 0;
|
2010-11-22 10:44:52 -05:00
|
|
|
// [intelligence objectForKey:@"title"]
|
|
|
|
// var score_max = Math.max(story.intelligence['title'],
|
|
|
|
// story.intelligence['author'],
|
|
|
|
// story.intelligence['tags']);
|
|
|
|
// var score_min = Math.min(story.intelligence['title'],
|
|
|
|
// story.intelligence['author'],
|
|
|
|
// story.intelligence['tags']);
|
|
|
|
// if (score_max > 0) score = score_max;
|
|
|
|
// else if (score_min < 0) score = score_min;
|
|
|
|
//
|
|
|
|
// if (score == 0) score = story.intelligence['feed'];
|
|
|
|
|
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
2010-06-17 13:10:45 -04:00
|
|
|
@end
|