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"
|
2011-10-04 18:01:35 -07:00
|
|
|
#import "AddViewController.h"
|
2010-11-13 18:32:43 -05:00
|
|
|
#import "OriginalStoryViewController.h"
|
2011-10-27 09:44:58 -07:00
|
|
|
#import "MBProgressHUD.h"
|
2011-10-28 18:29:33 -07:00
|
|
|
#import "Utilities.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;
|
2011-10-04 18:01:35 -07:00
|
|
|
@synthesize addViewController;
|
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 activeUsername;
|
2011-10-25 09:28:05 -07:00
|
|
|
@synthesize isRiverView;
|
2010-06-25 18:36:01 -04:00
|
|
|
@synthesize activeFeed;
|
2011-10-20 09:32:39 -07:00
|
|
|
@synthesize activeFolder;
|
2011-10-26 08:40:31 -07:00
|
|
|
@synthesize activeFolderFeeds;
|
2010-06-25 18:36:01 -04:00
|
|
|
@synthesize activeFeedStories;
|
2011-07-29 21:27:37 -07:00
|
|
|
@synthesize activeFeedStoryLocations;
|
2011-08-08 09:58:15 -07:00
|
|
|
@synthesize activeFeedStoryLocationIds;
|
2010-06-25 18:36:01 -04:00
|
|
|
@synthesize activeStory;
|
2011-07-24 16:52:24 -07:00
|
|
|
@synthesize storyCount;
|
2011-08-09 17:58:43 -07:00
|
|
|
@synthesize originalStoryCount;
|
2011-07-29 09:06:17 -07:00
|
|
|
@synthesize selectedIntelligence;
|
2010-11-13 18:32:43 -05:00
|
|
|
@synthesize activeOriginalStoryURL;
|
2011-07-24 21:47:58 -07:00
|
|
|
@synthesize recentlyReadStories;
|
2011-11-03 18:08:24 -07:00
|
|
|
@synthesize recentlyReadFeeds;
|
2011-08-22 18:25:33 -07:00
|
|
|
@synthesize readStories;
|
2010-06-17 13:10:45 -04:00
|
|
|
|
2011-10-04 18:01:35 -07:00
|
|
|
@synthesize dictFolders;
|
|
|
|
@synthesize dictFeeds;
|
|
|
|
@synthesize dictFoldersArray;
|
|
|
|
|
2010-06-17 13:10:45 -04:00
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
|
|
|
|
2011-09-07 09:56:54 -07:00
|
|
|
// [TestFlight takeOff:@"101dd20fb90f7355703b131d9af42633_MjQ0NTgyMDExLTA4LTIxIDIzOjU3OjEzLjM5MDcyOA"];
|
2011-09-05 22:06:31 -07:00
|
|
|
[ASIHTTPRequest setDefaultUserAgentString:@"NewsBlur iPhone App v1.0"];
|
2011-08-21 21:39:29 -07:00
|
|
|
|
2011-09-07 09:56:54 -07:00
|
|
|
navigationController.viewControllers = [NSArray arrayWithObject:feedsViewController];
|
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
|
|
|
|
2011-08-13 23:00:51 -07:00
|
|
|
[feedsViewController fetchFeedList:YES];
|
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
|
|
|
|
2011-07-29 09:06:17 -07:00
|
|
|
- (void)viewDidLoad {
|
|
|
|
self.selectedIntelligence = 1;
|
2011-08-01 09:43:13 -07:00
|
|
|
[self setRecentlyReadStories:[NSMutableArray array]];
|
2011-07-29 09:06:17 -07:00
|
|
|
}
|
|
|
|
|
2010-06-17 13:10:45 -04:00
|
|
|
- (void)dealloc {
|
2011-08-01 09:43:13 -07:00
|
|
|
NSLog(@"Dealloc on AppDelegate");
|
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];
|
2011-10-04 18:01:35 -07:00
|
|
|
[addViewController 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];
|
2011-10-20 09:32:39 -07:00
|
|
|
[activeFolder release];
|
2010-06-25 18:36:01 -04:00
|
|
|
[activeFeedStories release];
|
2011-07-29 21:27:37 -07:00
|
|
|
[activeFeedStoryLocations release];
|
2011-08-08 09:58:15 -07:00
|
|
|
[activeFeedStoryLocationIds release];
|
2010-06-25 18:36:01 -04:00
|
|
|
[activeStory release];
|
2010-11-13 18:32:43 -05:00
|
|
|
[activeOriginalStoryURL release];
|
2011-07-24 21:47:58 -07:00
|
|
|
[recentlyReadStories release];
|
2011-11-03 18:08:24 -07:00
|
|
|
[recentlyReadFeeds release];
|
2011-08-22 18:25:33 -07:00
|
|
|
[readStories release];
|
2011-10-04 18:01:35 -07:00
|
|
|
|
|
|
|
[dictFolders release];
|
|
|
|
[dictFeeds release];
|
|
|
|
[dictFoldersArray 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];
|
2011-08-13 17:08:26 -07:00
|
|
|
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
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];
|
|
|
|
}
|
|
|
|
|
2011-10-04 18:01:35 -07:00
|
|
|
- (void)showAdd {
|
|
|
|
UINavigationController *navController = self.navigationController;
|
2011-10-15 15:26:18 -07:00
|
|
|
[addViewController initWithNibName:nil bundle:nil];
|
2011-10-04 18:01:35 -07:00
|
|
|
[navController presentModalViewController:addViewController animated:YES];
|
2011-10-10 09:57:54 -07:00
|
|
|
[addViewController reload];
|
2011-10-04 18:01:35 -07:00
|
|
|
}
|
|
|
|
|
2010-11-11 20:05:53 -05:00
|
|
|
- (void)reloadFeedsView {
|
2010-11-11 23:48:27 -05:00
|
|
|
[self setTitle:@"NewsBlur"];
|
2011-08-13 23:00:51 -07:00
|
|
|
[feedsViewController fetchFeedList:YES];
|
2010-11-13 13:42:20 -05:00
|
|
|
[loginViewController dismissModalViewControllerAnimated:YES];
|
2011-08-13 17:08:26 -07:00
|
|
|
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
2010-11-11 20:05:53 -05:00
|
|
|
}
|
2011-10-06 10:27:37 -07:00
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
- (void)loadFeedDetailView {
|
2011-08-25 12:09:41 -07:00
|
|
|
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"All" style: UIBarButtonItemStyleBordered target: nil action: nil];
|
|
|
|
[feedsViewController.navigationItem setBackBarButtonItem: newBackButton];
|
|
|
|
[newBackButton release];
|
2010-06-24 00:22:26 -04:00
|
|
|
UINavigationController *navController = self.navigationController;
|
2011-07-24 16:52:24 -07:00
|
|
|
[self setStories:nil];
|
2010-06-24 00:22:26 -04:00
|
|
|
[navController pushViewController:feedDetailViewController animated:YES];
|
2011-09-06 17:51:02 -07:00
|
|
|
[feedDetailViewController resetFeedDetail];
|
2011-09-05 22:06:31 -07:00
|
|
|
[feedDetailViewController fetchFeedDetail:1 withCallback:nil];
|
2010-11-13 13:42:20 -05:00
|
|
|
[self showNavigationBar:YES];
|
2011-08-25 12:09:41 -07:00
|
|
|
navController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
2011-10-25 09:47:55 -07:00
|
|
|
// navController.navigationBar.tintColor = UIColorFromRGB(0x59f6c1);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadRiverFeedDetailView {
|
|
|
|
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"All" style: UIBarButtonItemStyleBordered target: nil action: nil];
|
|
|
|
[feedsViewController.navigationItem setBackBarButtonItem: newBackButton];
|
|
|
|
[newBackButton release];
|
|
|
|
UINavigationController *navController = self.navigationController;
|
|
|
|
[self setStories:nil];
|
|
|
|
[navController pushViewController:feedDetailViewController animated:YES];
|
|
|
|
[feedDetailViewController resetFeedDetail];
|
|
|
|
[feedDetailViewController fetchRiverPage:1 withCallback:nil];
|
|
|
|
[self showNavigationBar:YES];
|
|
|
|
navController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
|
|
|
// navController.navigationBar.tintColor = UIColorFromRGB(0x59f6c1);
|
2010-06-25 18:36:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadStoryDetailView {
|
2011-10-27 09:44:58 -07:00
|
|
|
NSString *feedTitle;
|
|
|
|
if (self.isRiverView) {
|
|
|
|
feedTitle = self.activeFolder;
|
|
|
|
} else {
|
|
|
|
feedTitle = [activeFeed objectForKey:@"feed_title"];
|
|
|
|
}
|
|
|
|
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle:feedTitle style: UIBarButtonItemStyleBordered target: nil action: nil];
|
2011-08-25 12:09:41 -07:00
|
|
|
[feedDetailViewController.navigationItem setBackBarButtonItem: newBackButton];
|
|
|
|
[newBackButton release];
|
2010-06-25 18:36:01 -04:00
|
|
|
UINavigationController *navController = self.navigationController;
|
|
|
|
[navController pushViewController:storyDetailViewController animated:YES];
|
2011-10-27 09:44:58 -07:00
|
|
|
[navController.navigationItem setLeftBarButtonItem:[[[UIBarButtonItem alloc] initWithTitle:feedTitle style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease]];
|
2011-08-25 12:09:41 -07:00
|
|
|
navController.navigationItem.hidesBackButton = YES;
|
|
|
|
navController.navigationBar.tintColor = [UIColor colorWithRed:0.16f green:0.36f blue:0.46 alpha:0.9];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)navigationController:(UINavigationController *)navController
|
|
|
|
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
|
|
|
|
if (viewController == feedDetailViewController) {
|
|
|
|
UIView *backButtonView = [[UIView alloc] initWithFrame:CGRectMake(0,0,70,35)];
|
|
|
|
UIButton *myBackButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
|
|
|
|
[myBackButton setFrame:CGRectMake(0,0,70,35)];
|
|
|
|
[myBackButton setImage:[UIImage imageNamed:@"toolbar_back_button.png"] forState:UIControlStateNormal];
|
|
|
|
[myBackButton setEnabled:YES];
|
|
|
|
[myBackButton addTarget:viewController.navigationController action:@selector(popViewControllerAnimated:) forControlEvents:UIControlEventTouchUpInside];
|
|
|
|
[backButtonView addSubview:myBackButton];
|
|
|
|
[myBackButton release];
|
|
|
|
UIBarButtonItem* backButton = [[UIBarButtonItem alloc] initWithCustomView:backButtonView];
|
|
|
|
viewController.navigationItem.leftBarButtonItem = backButton;
|
|
|
|
navController.navigationItem.leftBarButtonItem = backButton;
|
|
|
|
viewController.navigationItem.hidesBackButton = YES;
|
|
|
|
navController.navigationItem.hidesBackButton = YES;
|
|
|
|
|
|
|
|
[backButtonView release];
|
|
|
|
[backButton release];
|
|
|
|
}
|
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 {
|
2011-08-08 09:58:15 -07:00
|
|
|
int activeLocation = [self locationOfActiveStory];
|
2011-08-09 17:58:43 -07:00
|
|
|
// int activeIndex = [[activeFeedStoryLocations objectAtIndex:activeLocation] intValue];
|
2011-07-24 21:47:58 -07:00
|
|
|
int readStatus = -1;
|
2011-08-08 17:17:32 -07:00
|
|
|
// NSLog(@"ActiveStory: %d (%d)/%d", activeLocation, activeIndex, self.storyCount);
|
2011-08-08 09:58:15 -07:00
|
|
|
for (int i=activeLocation+1; i < [self.activeFeedStoryLocations count]; i++) {
|
|
|
|
int location = [[self.activeFeedStoryLocations objectAtIndex:i] intValue];
|
|
|
|
NSDictionary *story = [activeFeedStories objectAtIndex:location];
|
2011-07-24 21:47:58 -07:00
|
|
|
readStatus = [[story objectForKey:@"read_status"] intValue];
|
2011-08-08 17:17:32 -07:00
|
|
|
// NSLog(@"+1 readStatus at %d (%d): %d", location, i, readStatus);
|
2011-07-24 21:47:58 -07:00
|
|
|
if (readStatus == 0) {
|
2011-08-08 17:17:32 -07:00
|
|
|
// NSLog(@"NextStory after: %d", i);
|
|
|
|
return location;
|
2011-07-24 21:47:58 -07:00
|
|
|
}
|
|
|
|
}
|
2011-08-08 17:17:32 -07:00
|
|
|
if (activeLocation > 0) {
|
|
|
|
for (int i=activeLocation-1; i >= 0; i--) {
|
|
|
|
int location = [[self.activeFeedStoryLocations objectAtIndex:i] intValue];
|
|
|
|
NSDictionary *story = [activeFeedStories objectAtIndex:location];
|
|
|
|
readStatus = [[story objectForKey:@"read_status"] intValue];
|
|
|
|
// NSLog(@"-1 readStatus at %d (%d): %d", location, i, readStatus);
|
|
|
|
if (readStatus == 0) {
|
|
|
|
// NSLog(@"NextStory before: %d", i);
|
|
|
|
return location;
|
|
|
|
}
|
2011-06-15 11:21:55 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)indexOfPreviousStory {
|
|
|
|
NSInteger activeIndex = [self indexOfActiveStory];
|
2011-07-25 09:08:20 -07:00
|
|
|
return MAX(-1, activeIndex-1);
|
2011-06-15 11:21:55 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int)indexOfActiveStory {
|
2011-07-24 16:52:24 -07:00
|
|
|
for (int i=0; i < self.storyCount; 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-08-08 09:58:15 -07:00
|
|
|
- (int)locationOfActiveStory {
|
|
|
|
for (int i=0; i < [activeFeedStoryLocations count]; i++) {
|
|
|
|
if ([activeFeedStoryLocationIds objectAtIndex:i] ==
|
|
|
|
[self.activeStory objectForKey:@"id"]) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-08-22 18:25:33 -07:00
|
|
|
- (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;
|
|
|
|
}
|
|
|
|
|
2011-07-26 08:37:10 -07:00
|
|
|
- (int)unreadCount {
|
2011-10-31 10:10:38 -07:00
|
|
|
if (self.isRiverView) {
|
|
|
|
return [self unreadCountForFolder:nil];
|
|
|
|
} else {
|
|
|
|
return [self unreadCountForFeed:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)unreadCountForFeed:(NSString *)feedId {
|
2011-08-09 17:58:43 -07:00
|
|
|
int total = 0;
|
2011-10-31 10:10:38 -07:00
|
|
|
NSDictionary *feed;
|
|
|
|
|
|
|
|
if (feedId) {
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
|
|
|
feed = [self.dictFeeds objectForKey:feedIdStr];
|
|
|
|
} else {
|
|
|
|
feed = self.activeFeed;
|
|
|
|
}
|
|
|
|
|
|
|
|
total += [[feed objectForKey:@"ps"] intValue];
|
2011-08-09 17:58:43 -07:00
|
|
|
if ([self selectedIntelligence] <= 0) {
|
2011-10-31 10:10:38 -07:00
|
|
|
total += [[feed objectForKey:@"nt"] intValue];
|
2011-08-09 17:58:43 -07:00
|
|
|
}
|
|
|
|
if ([self selectedIntelligence] <= -1) {
|
2011-10-31 10:10:38 -07:00
|
|
|
total += [[feed objectForKey:@"ng"] intValue];
|
2011-08-09 17:58:43 -07:00
|
|
|
}
|
2011-10-31 10:10:38 -07:00
|
|
|
|
2011-08-09 17:58:43 -07:00
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2011-10-31 10:10:38 -07:00
|
|
|
- (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;
|
2011-07-26 08:37:10 -07:00
|
|
|
}
|
|
|
|
|
2011-07-24 16:52:24 -07:00
|
|
|
- (void)addStories:(NSArray *)stories {
|
2011-07-20 22:21:11 -07:00
|
|
|
self.activeFeedStories = [self.activeFeedStories arrayByAddingObjectsFromArray:stories];
|
2011-07-24 16:52:24 -07:00
|
|
|
self.storyCount = [self.activeFeedStories count];
|
2011-07-29 21:27:37 -07:00
|
|
|
[self calculateStoryLocations];
|
2011-07-24 16:52:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setStories:(NSArray *)activeFeedStoriesValue {
|
|
|
|
self.activeFeedStories = activeFeedStoriesValue;
|
|
|
|
self.storyCount = [self.activeFeedStories count];
|
2011-11-03 18:08:24 -07:00
|
|
|
self.recentlyReadStories = [NSMutableArray array];
|
|
|
|
self.recentlyReadFeeds = [NSMutableSet set];
|
2011-07-29 21:27:37 -07:00
|
|
|
[self calculateStoryLocations];
|
2011-07-20 22:21:11 -07:00
|
|
|
}
|
|
|
|
|
2011-07-24 20:34:54 -07:00
|
|
|
- (void)markActiveStoryRead {
|
2011-08-08 09:58:15 -07:00
|
|
|
int activeLocation = [self locationOfActiveStory];
|
|
|
|
if (activeLocation == -1) {
|
|
|
|
return;
|
|
|
|
}
|
2011-10-27 09:44:58 -07:00
|
|
|
id feedId = [self.activeStory objectForKey:@"story_feed_id"];
|
2011-10-18 17:44:05 -07:00
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
2011-08-22 18:25:33 -07:00
|
|
|
int activeIndex = [[activeFeedStoryLocations objectAtIndex:activeLocation] intValue];
|
2011-10-18 17:44:05 -07:00
|
|
|
NSDictionary *feed = [self.dictFeeds objectForKey:feedIdStr];
|
2011-07-24 20:34:54 -07:00
|
|
|
NSDictionary *story = [activeFeedStories objectAtIndex:activeIndex];
|
2011-10-18 17:44:05 -07:00
|
|
|
|
2011-07-24 22:14:50 -07:00
|
|
|
[story setValue:[NSNumber numberWithInt:1] forKey:@"read_status"];
|
2011-08-08 09:58:15 -07:00
|
|
|
[self.recentlyReadStories addObject:[NSNumber numberWithInt:activeLocation]];
|
2011-11-03 18:08:24 -07:00
|
|
|
if (![self.recentlyReadFeeds containsObject:[story objectForKey:@"story_feed_id"]]) {
|
|
|
|
[self.recentlyReadFeeds addObject:[story objectForKey:@"story_feed_id"]];
|
|
|
|
}
|
2011-07-24 22:14:50 -07:00
|
|
|
int score = [NewsBlurAppDelegate computeStoryScore:[story objectForKey:@"intelligence"]];
|
|
|
|
if (score > 0) {
|
2011-10-18 17:44:05 -07:00
|
|
|
int unreads = MAX(0, [[feed objectForKey:@"ps"] intValue] - 1);
|
|
|
|
[feed setValue:[NSNumber numberWithInt:unreads] forKey:@"ps"];
|
2011-07-24 22:14:50 -07:00
|
|
|
} else if (score == 0) {
|
2011-10-18 17:44:05 -07:00
|
|
|
int unreads = MAX(0, [[feed objectForKey:@"nt"] intValue] - 1);
|
|
|
|
[feed setValue:[NSNumber numberWithInt:unreads] forKey:@"nt"];
|
2011-07-24 22:14:50 -07:00
|
|
|
} else if (score < 0) {
|
2011-10-18 17:44:05 -07:00
|
|
|
int unreads = MAX(0, [[feed objectForKey:@"ng"] intValue] - 1);
|
|
|
|
[feed setValue:[NSNumber numberWithInt:unreads] forKey:@"ng"];
|
2011-07-24 22:14:50 -07:00
|
|
|
}
|
2011-10-18 17:44:05 -07:00
|
|
|
[self.dictFeeds setValue:feed forKey:feedIdStr];
|
|
|
|
|
2011-08-08 09:58:15 -07:00
|
|
|
// NSLog(@"Marked read %d-%d: %@: %d", activeIndex, activeLocation, self.recentlyReadStories, score);
|
2011-07-24 20:34:54 -07:00
|
|
|
}
|
|
|
|
|
2011-07-24 22:23:38 -07:00
|
|
|
- (void)markActiveFeedAllRead {
|
2011-10-18 17:44:05 -07:00
|
|
|
id feedId = [self.activeFeed objectForKey:@"id"];
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
|
|
|
NSDictionary *feed = [self.dictFeeds objectForKey:feedIdStr];
|
|
|
|
|
|
|
|
[feed setValue:[NSNumber numberWithInt:0] forKey:@"ps"];
|
|
|
|
[feed setValue:[NSNumber numberWithInt:0] forKey:@"nt"];
|
|
|
|
[feed setValue:[NSNumber numberWithInt:0] forKey:@"ng"];
|
|
|
|
[self.dictFeeds setValue:feed forKey:feedIdStr];
|
2011-07-24 22:23:38 -07:00
|
|
|
}
|
|
|
|
|
2011-07-29 21:27:37 -07:00
|
|
|
- (void)calculateStoryLocations {
|
2011-08-01 09:43:13 -07:00
|
|
|
self.activeFeedStoryLocations = [NSMutableArray array];
|
2011-08-08 09:58:15 -07:00
|
|
|
self.activeFeedStoryLocationIds = [NSMutableArray array];
|
2011-07-29 21:27:37 -07:00
|
|
|
for (int i=0; i < self.storyCount; i++) {
|
|
|
|
NSDictionary *story = [self.activeFeedStories objectAtIndex:i];
|
|
|
|
int score = [NewsBlurAppDelegate computeStoryScore:[story objectForKey:@"intelligence"]];
|
2011-08-01 09:43:13 -07:00
|
|
|
if (score >= self.selectedIntelligence) {
|
2011-07-29 21:27:37 -07:00
|
|
|
NSNumber *location = [NSNumber numberWithInt:i];
|
|
|
|
[self.activeFeedStoryLocations addObject:location];
|
2011-08-08 09:58:15 -07:00
|
|
|
[self.activeFeedStoryLocationIds addObject:[story objectForKey:@"id"]];
|
2011-07-29 21:27:37 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-22 10:44:52 -05:00
|
|
|
+ (int)computeStoryScore:(NSDictionary *)intelligence {
|
|
|
|
int score = 0;
|
2011-07-26 08:37:10 -07:00
|
|
|
int title = [[intelligence objectForKey:@"title"] intValue];
|
|
|
|
int author = [[intelligence objectForKey:@"author"] intValue];
|
|
|
|
int tags = [[intelligence objectForKey:@"tags"] intValue];
|
|
|
|
|
|
|
|
int score_max = MAX(title, MAX(author, tags));
|
|
|
|
int score_min = MIN(title, MIN(author, tags));
|
2011-07-24 20:07:38 -07:00
|
|
|
|
|
|
|
if (score_max > 0) score = score_max;
|
|
|
|
else if (score_min < 0) score = score_min;
|
2010-11-22 10:44:52 -05:00
|
|
|
|
2011-07-24 20:07:38 -07:00
|
|
|
if (score == 0) score = [[intelligence objectForKey:@"feed"] integerValue];
|
|
|
|
|
2011-07-29 09:06:17 -07:00
|
|
|
// NSLog(@"%d/%d -- %d: %@", score_max, score_min, score, intelligence);
|
2010-11-22 10:44:52 -05:00
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
2011-10-27 19:05:38 -07:00
|
|
|
+ (UIView *)makeGradientView:(CGRect)rect startColor:(NSString *)start endColor:(NSString *)end {
|
|
|
|
UIView *gradientView = [[[UIView alloc] initWithFrame:rect] autorelease];
|
|
|
|
|
|
|
|
CAGradientLayer *gradient = [CAGradientLayer layer];
|
2011-10-30 18:53:10 -07:00
|
|
|
gradient.frame = CGRectMake(0, 1, rect.size.width, rect.size.height-1);
|
2011-10-30 15:06:25 -07:00
|
|
|
gradient.opacity = 1;
|
2011-10-27 19:05:38 -07:00
|
|
|
unsigned int color = 0;
|
|
|
|
unsigned int colorFade = 0;
|
|
|
|
if ([start class] == [NSNull class]) {
|
|
|
|
start = @"505050";
|
|
|
|
}
|
|
|
|
if ([end class] == [NSNull class]) {
|
|
|
|
end = @"303030";
|
|
|
|
}
|
|
|
|
NSScanner *scanner = [NSScanner scannerWithString:start];
|
|
|
|
[scanner scanHexInt:&color];
|
|
|
|
NSScanner *scannerFade = [NSScanner scannerWithString:end];
|
|
|
|
[scannerFade scanHexInt:&colorFade];
|
|
|
|
gradient.colors = [NSArray arrayWithObjects:(id)[UIColorFromRGB(color) CGColor], (id)[UIColorFromRGB(colorFade) CGColor], nil];
|
2011-10-28 18:29:33 -07:00
|
|
|
|
|
|
|
CALayer *whiteBackground = [CALayer layer];
|
2011-10-30 18:53:10 -07:00
|
|
|
whiteBackground.frame = CGRectMake(0, 1, rect.size.width, rect.size.height-1);
|
2011-10-28 18:29:33 -07:00
|
|
|
whiteBackground.backgroundColor = [UIColor whiteColor].CGColor;
|
|
|
|
[gradientView.layer addSublayer:whiteBackground];
|
|
|
|
|
2011-10-27 19:05:38 -07:00
|
|
|
[gradientView.layer addSublayer:gradient];
|
2011-10-28 18:29:33 -07:00
|
|
|
|
|
|
|
CALayer *topBorder = [CALayer layer];
|
2011-10-30 18:53:10 -07:00
|
|
|
topBorder.frame = CGRectMake(0, 1, rect.size.width, 1);
|
2011-10-28 18:29:33 -07:00
|
|
|
topBorder.backgroundColor = UIColorFromRGB(colorFade).CGColor;
|
2011-10-30 15:06:25 -07:00
|
|
|
topBorder.opacity = 1;
|
2011-10-28 18:29:33 -07:00
|
|
|
[gradientView.layer addSublayer:topBorder];
|
|
|
|
|
|
|
|
CALayer *bottomBorder = [CALayer layer];
|
|
|
|
bottomBorder.frame = CGRectMake(0, rect.size.height-1, rect.size.width, 1);
|
|
|
|
bottomBorder.backgroundColor = UIColorFromRGB(colorFade).CGColor;
|
2011-10-30 15:06:25 -07:00
|
|
|
bottomBorder.opacity = 1;
|
2011-10-28 18:29:33 -07:00
|
|
|
[gradientView.layer addSublayer:bottomBorder];
|
|
|
|
|
|
|
|
return gradientView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)makeFeedTitleGradient:(NSDictionary *)feed withRect:(CGRect)rect {
|
|
|
|
UIView *gradientView;
|
|
|
|
if (self.isRiverView) {
|
|
|
|
gradientView = [NewsBlurAppDelegate
|
|
|
|
makeGradientView:rect
|
|
|
|
startColor:[feed objectForKey:@"favicon_color"]
|
|
|
|
endColor:[feed objectForKey:@"favicon_fade"]];
|
|
|
|
|
|
|
|
UILabel *titleLabel = [[[UILabel alloc] init] autorelease];
|
|
|
|
titleLabel.text = [feed objectForKey:@"feed_title"];
|
|
|
|
titleLabel.backgroundColor = [UIColor clearColor];
|
|
|
|
titleLabel.textAlignment = UITextAlignmentLeft;
|
|
|
|
titleLabel.lineBreakMode = UILineBreakModeTailTruncation;
|
|
|
|
titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:11.0];
|
|
|
|
titleLabel.shadowOffset = CGSizeMake(0, 1);
|
|
|
|
if ([[feed objectForKey:@"favicon_text_color"] class] != [NSNull class]) {
|
|
|
|
titleLabel.textColor = [[feed objectForKey:@"favicon_text_color"] isEqualToString:@"white"] ?
|
|
|
|
[UIColor whiteColor] :
|
|
|
|
[UIColor blackColor];
|
|
|
|
titleLabel.shadowColor = [[feed objectForKey:@"favicon_text_color"] isEqualToString:@"white"] ?
|
|
|
|
UIColorFromRGB(0x202020):
|
|
|
|
UIColorFromRGB(0xe0e0e0);
|
|
|
|
} else {
|
|
|
|
titleLabel.textColor = [UIColor whiteColor];
|
|
|
|
titleLabel.shadowColor = [UIColor blackColor];
|
|
|
|
}
|
2011-10-30 18:53:10 -07:00
|
|
|
titleLabel.frame = CGRectMake(32, 1, window.frame.size.width-20, 20);
|
2011-10-28 18:29:33 -07:00
|
|
|
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [feed objectForKey:@"id"]];
|
|
|
|
UIImage *titleImage = [Utilities getImage:feedIdStr];
|
|
|
|
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:titleImage];
|
2011-10-30 18:53:10 -07:00
|
|
|
titleImageView.frame = CGRectMake(8, 3, 16.0, 16.0);
|
2011-10-28 18:29:33 -07:00
|
|
|
[titleLabel addSubview:titleImageView];
|
|
|
|
[titleImageView release];
|
|
|
|
|
|
|
|
[gradientView addSubview:titleLabel];
|
|
|
|
[gradientView addSubview:titleImageView];
|
|
|
|
} else {
|
|
|
|
gradientView = [NewsBlurAppDelegate
|
2011-10-30 22:17:35 -07:00
|
|
|
makeGradientView:CGRectMake(0, -1, window.frame.size.width, 10)
|
2011-10-28 18:29:33 -07:00
|
|
|
startColor:[feed objectForKey:@"favicon_color"]
|
|
|
|
endColor:[feed objectForKey:@"favicon_fade"]];
|
|
|
|
}
|
|
|
|
|
|
|
|
gradientView.opaque = YES;
|
|
|
|
|
2011-10-27 19:05:38 -07:00
|
|
|
return gradientView;
|
|
|
|
}
|
2011-08-18 09:56:52 -07:00
|
|
|
|
2010-06-17 13:10:45 -04:00
|
|
|
@end
|