2011-08-25 12:09:41 -07:00
|
|
|
//
|
2010-06-20 11:04:23 -04:00
|
|
|
// NewsBlurViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 6/16/10.
|
|
|
|
// Copyright NewsBlur 2010. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2012-06-19 11:48:51 -07:00
|
|
|
#import "NewsBlurViewController.h"
|
2010-06-21 17:17:26 -04:00
|
|
|
#import "NewsBlurAppDelegate.h"
|
2012-07-10 16:48:05 -07:00
|
|
|
#import "DashboardViewController.h"
|
2011-07-18 09:56:48 -07:00
|
|
|
#import "FeedTableCell.h"
|
2012-06-19 13:51:48 -07:00
|
|
|
#import "FeedsMenuViewController.h"
|
2011-08-04 17:58:28 -07:00
|
|
|
#import "ASIHTTPRequest.h"
|
|
|
|
#import "PullToRefreshView.h"
|
2011-08-13 23:00:51 -07:00
|
|
|
#import "MBProgressHUD.h"
|
2011-08-03 10:00:41 -07:00
|
|
|
#import "Base64.h"
|
2010-06-20 11:04:23 -04:00
|
|
|
#import "JSON.h"
|
2011-10-17 09:28:40 -07:00
|
|
|
#import "Utilities.h"
|
2010-06-20 11:04:23 -04:00
|
|
|
|
2012-07-10 16:48:05 -07:00
|
|
|
|
2011-07-19 09:38:49 -07:00
|
|
|
#define kTableViewRowHeight 40;
|
2012-07-11 11:03:34 -07:00
|
|
|
#define kBlurblogTableViewRowHeight 45;
|
2011-07-19 09:38:49 -07:00
|
|
|
|
2012-06-19 11:48:51 -07:00
|
|
|
@implementation NewsBlurViewController
|
2010-06-21 17:17:26 -04:00
|
|
|
|
|
|
|
@synthesize appDelegate;
|
|
|
|
|
2011-08-02 09:16:54 -07:00
|
|
|
@synthesize feedTitlesTable;
|
2010-06-20 11:04:23 -04:00
|
|
|
@synthesize feedViewToolbar;
|
2010-06-21 17:17:26 -04:00
|
|
|
@synthesize feedScoreSlider;
|
2012-06-19 10:55:46 -07:00
|
|
|
@synthesize homeButton;
|
2011-08-02 09:16:54 -07:00
|
|
|
@synthesize intelligenceControl;
|
2011-08-02 10:13:06 -07:00
|
|
|
@synthesize activeFeedLocations;
|
2011-08-24 21:41:44 -07:00
|
|
|
@synthesize visibleFeeds;
|
2011-10-31 10:10:38 -07:00
|
|
|
@synthesize stillVisibleFeeds;
|
2011-08-04 17:27:31 -07:00
|
|
|
@synthesize viewShowingAllFeeds;
|
2011-08-04 17:58:28 -07:00
|
|
|
@synthesize pull;
|
|
|
|
@synthesize lastUpdate;
|
2011-10-14 09:51:27 -07:00
|
|
|
@synthesize imageCache;
|
2012-06-19 13:51:48 -07:00
|
|
|
@synthesize popoverController;
|
2010-06-20 11:04:23 -04:00
|
|
|
|
2010-06-21 17:17:26 -04:00
|
|
|
#pragma mark -
|
2011-08-24 21:44:16 -07:00
|
|
|
#pragma mark Globals
|
2010-06-21 17:17:26 -04:00
|
|
|
|
2010-06-20 11:04:23 -04:00
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2010-06-21 17:17:26 -04:00
|
|
|
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
|
2011-08-24 21:44:16 -07:00
|
|
|
[appDelegate hideNavigationBar:NO];
|
2010-06-20 11:04:23 -04:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidLoad {
|
2012-06-27 10:04:44 -07:00
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
2012-07-09 17:32:22 -07:00
|
|
|
if ([userPreferences integerForKey:@"siteDisplayMode"] == 0) {
|
|
|
|
NSLog(@"Show ALL stories");
|
|
|
|
self.viewShowingAllFeeds = YES;
|
|
|
|
[self.intelligenceControl setSelectedSegmentIndex:0];
|
|
|
|
} else if ([userPreferences integerForKey:@"siteDisplayMode"] == 1) {
|
|
|
|
NSLog(@"Show UNREAD stories");
|
2012-06-27 10:04:44 -07:00
|
|
|
self.viewShowingAllFeeds = NO;
|
2012-07-09 17:32:22 -07:00
|
|
|
[self.intelligenceControl setSelectedSegmentIndex:1];
|
2012-06-27 10:04:44 -07:00
|
|
|
} else {
|
2012-07-09 17:32:22 -07:00
|
|
|
NSLog(@"Show FOCUS stories");
|
|
|
|
self.viewShowingAllFeeds = NO;
|
|
|
|
[self.intelligenceControl setSelectedSegmentIndex:2];
|
|
|
|
[appDelegate setSelectedIntelligence:1];
|
2012-06-27 10:04:44 -07:00
|
|
|
}
|
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
[appDelegate showNavigationBar:NO];
|
|
|
|
pull = [[PullToRefreshView alloc] initWithScrollView:self.feedTitlesTable];
|
2011-08-04 17:58:28 -07:00
|
|
|
[pull setDelegate:self];
|
|
|
|
[self.feedTitlesTable addSubview:pull];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2011-08-26 09:34:30 -07:00
|
|
|
[[NSNotificationCenter defaultCenter]
|
|
|
|
addObserver:self
|
|
|
|
selector:@selector(returnToApp)
|
|
|
|
name:UIApplicationWillEnterForegroundNotification
|
|
|
|
object:nil];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2011-10-14 09:51:27 -07:00
|
|
|
imageCache = [[NSCache alloc] init];
|
|
|
|
[imageCache setDelegate:self];
|
2012-06-19 11:48:51 -07:00
|
|
|
|
2010-06-20 11:04:23 -04:00
|
|
|
[super viewDidLoad];
|
|
|
|
}
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2011-11-03 18:08:24 -07:00
|
|
|
// If there is an active feed or a set of feeds readin the river,
|
|
|
|
// we need to update its table row to match the updated unread counts.
|
2011-11-29 17:57:20 -08:00
|
|
|
if (appDelegate.activeFeed || appDelegate.isRiverView) {
|
2011-08-02 09:16:54 -07:00
|
|
|
[self.feedTitlesTable beginUpdates];
|
|
|
|
[self.feedTitlesTable
|
2011-11-29 17:57:20 -08:00
|
|
|
reloadRowsAtIndexPaths:[self.feedTitlesTable indexPathsForVisibleRows]
|
2011-08-24 21:44:16 -07:00
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
2011-08-02 09:16:54 -07:00
|
|
|
[self.feedTitlesTable endUpdates];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
|
|
|
NSInteger previousLevel = [self.intelligenceControl selectedSegmentIndex] - 1;
|
|
|
|
NSInteger newLevel = [appDelegate selectedIntelligence];
|
|
|
|
if (newLevel != previousLevel) {
|
2011-08-27 15:53:51 -07:00
|
|
|
[appDelegate setSelectedIntelligence:newLevel];
|
2011-09-06 17:51:02 -07:00
|
|
|
if (!self.viewShowingAllFeeds) {
|
|
|
|
[self updateFeedsWithIntelligence:previousLevel newLevel:newLevel];
|
|
|
|
}
|
2011-08-27 15:53:51 -07:00
|
|
|
[self redrawUnreadCounts];
|
2011-08-24 21:44:16 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-03 18:08:24 -07:00
|
|
|
|
2012-07-11 10:33:39 -07:00
|
|
|
[self.intelligenceControl setImage:[UIImage imageNamed:@"16-List.png"]
|
2011-08-26 09:34:30 -07:00
|
|
|
forSegmentAtIndex:0];
|
2012-07-10 16:48:05 -07:00
|
|
|
[self.intelligenceControl setImage:[UIImage imageNamed:@"unread.png"]
|
2011-08-26 09:34:30 -07:00
|
|
|
forSegmentAtIndex:1];
|
2012-07-10 16:48:05 -07:00
|
|
|
[self.intelligenceControl setImage:[UIImage imageNamed:@"focused.png"]
|
2011-08-26 09:34:30 -07:00
|
|
|
forSegmentAtIndex:2];
|
2011-08-02 09:16:54 -07:00
|
|
|
[self.intelligenceControl addTarget:self
|
2011-08-24 21:44:16 -07:00
|
|
|
action:@selector(selectIntelligence)
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
2012-07-09 17:32:22 -07:00
|
|
|
|
2010-11-13 18:32:43 -05:00
|
|
|
[appDelegate showNavigationBar:animated];
|
2011-10-26 23:12:21 -07:00
|
|
|
|
|
|
|
[self.feedTitlesTable selectRowAtIndexPath:[feedTitlesTable indexPathForSelectedRow]
|
|
|
|
animated:YES scrollPosition:UITableViewScrollPositionMiddle];
|
2012-06-27 14:37:37 -07:00
|
|
|
|
|
|
|
[appDelegate showDashboard];
|
2010-06-25 18:36:01 -04:00
|
|
|
}
|
|
|
|
|
2010-06-21 17:17:26 -04:00
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
2011-10-18 17:44:05 -07:00
|
|
|
// appDelegate.activeFeed = nil;
|
2011-08-24 21:44:16 -07:00
|
|
|
[super viewDidAppear:animated];
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewWillDisappear:(BOOL)animated {
|
2010-11-12 10:55:44 -05:00
|
|
|
//[appDelegate showNavigationBar:YES];
|
2012-06-19 14:27:35 -07:00
|
|
|
[self dismissFeedsMenu];
|
|
|
|
[super viewWillDisappear:animated];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dismissFeedsMenu {
|
|
|
|
if (popoverController.isPopoverVisible) {
|
2012-06-19 13:51:48 -07:00
|
|
|
[popoverController dismissPopoverAnimated:NO];
|
|
|
|
}
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
2010-06-20 11:04:23 -04:00
|
|
|
|
2012-06-08 10:37:51 -07:00
|
|
|
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
|
|
|
|
// Return YES for supported orientations
|
2012-06-08 19:21:10 -07:00
|
|
|
return YES;
|
2012-06-07 11:42:29 -07:00
|
|
|
}
|
|
|
|
|
2012-06-29 23:25:56 -07:00
|
|
|
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
|
|
|
|
/* When MGSplitViewController rotates, it causes a resize of our view; we need to resize our UIBarButtonControls or they will be 0-width */
|
|
|
|
[self.navigationItem.titleView sizeToFit];
|
|
|
|
}
|
|
|
|
|
2010-06-20 11:04:23 -04:00
|
|
|
- (void)didReceiveMemoryWarning {
|
2011-08-24 21:44:16 -07:00
|
|
|
// Releases the view if it doesn't have a superview.
|
2010-06-20 11:04:23 -04:00
|
|
|
[super didReceiveMemoryWarning];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
|
|
|
// Release any cached data, images, etc that aren't in use.
|
2010-06-20 11:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidUnload {
|
2011-08-24 21:44:16 -07:00
|
|
|
// Release any retained subviews of the main view.
|
|
|
|
// e.g. self.myOutlet = nil;
|
2010-06-20 11:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
- (void)dealloc {
|
|
|
|
[appDelegate release];
|
|
|
|
|
|
|
|
[feedTitlesTable release];
|
|
|
|
[feedViewToolbar release];
|
|
|
|
[feedScoreSlider release];
|
2012-06-19 10:55:46 -07:00
|
|
|
[homeButton release];
|
2011-08-02 09:16:54 -07:00
|
|
|
[intelligenceControl release];
|
2011-08-24 21:44:16 -07:00
|
|
|
[activeFeedLocations release];
|
|
|
|
[visibleFeeds release];
|
2011-10-31 10:10:38 -07:00
|
|
|
[stillVisibleFeeds release];
|
2011-08-24 21:44:16 -07:00
|
|
|
[pull release];
|
|
|
|
[lastUpdate release];
|
2011-10-14 09:51:27 -07:00
|
|
|
[imageCache release];
|
2012-06-19 13:51:48 -07:00
|
|
|
[popoverController release];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2010-06-20 11:04:23 -04:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Initialization
|
|
|
|
|
2011-08-18 21:48:30 -07:00
|
|
|
- (void)returnToApp {
|
2011-10-18 17:44:05 -07:00
|
|
|
NSDate *decayDate = [[NSDate alloc] initWithTimeIntervalSinceNow:(BACKGROUND_REFRESH_SECONDS)];
|
2011-08-24 21:44:16 -07:00
|
|
|
NSLog(@"Last Update: %@ - %f", self.lastUpdate, [self.lastUpdate timeIntervalSinceDate:decayDate]);
|
|
|
|
if ([self.lastUpdate timeIntervalSinceDate:decayDate] < 0) {
|
2012-07-02 11:42:06 -07:00
|
|
|
[self fetchFeedList:YES refreshFeeds:YES];
|
2011-08-24 21:44:16 -07:00
|
|
|
}
|
|
|
|
[decayDate release];
|
2011-08-18 21:48:30 -07:00
|
|
|
}
|
|
|
|
|
2012-07-02 11:42:06 -07:00
|
|
|
-(void)fetchFeedList:(BOOL)showLoader refreshFeeds:(BOOL)refreshFeeds {
|
2011-09-07 09:56:54 -07:00
|
|
|
if (showLoader && appDelegate.navigationController.topViewController == appDelegate.feedsViewController) {
|
2011-09-16 09:26:22 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
2011-08-24 21:44:16 -07:00
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
|
HUD.labelText = @"On its way...";
|
|
|
|
}
|
2012-07-02 11:42:06 -07:00
|
|
|
|
|
|
|
if (refreshFeeds) {
|
|
|
|
[self refreshFeedList];
|
|
|
|
return;
|
|
|
|
}
|
2011-10-14 17:15:48 -07:00
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
NSURL *urlFeedList = [NSURL URLWithString:
|
|
|
|
[NSString stringWithFormat:@"http://%@/reader/feeds?flat=true",
|
|
|
|
NEWSBLUR_URL]];
|
2011-09-05 22:06:31 -07:00
|
|
|
|
|
|
|
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:urlFeedList];
|
2011-10-15 17:48:10 -07:00
|
|
|
[[NSHTTPCookieStorage sharedHTTPCookieStorage]
|
|
|
|
setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
|
2011-09-05 22:06:31 -07:00
|
|
|
[request setDelegate:self];
|
|
|
|
[request setResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDidFinishSelector:@selector(finishLoadingFeedList:)];
|
|
|
|
[request setDidFailSelector:@selector(finishedWithError:)];
|
|
|
|
[request setTimeOutSeconds:30];
|
|
|
|
[request startAsynchronous];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
|
|
|
self.lastUpdate = [NSDate date];
|
2010-06-20 11:04:23 -04:00
|
|
|
}
|
|
|
|
|
2011-10-14 17:15:48 -07:00
|
|
|
- (void)finishedWithError:(ASIHTTPRequest *)request {
|
2011-08-24 21:44:16 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
[pull finishedLoading];
|
|
|
|
|
|
|
|
// User clicking on another link before the page loads is OK.
|
2011-10-27 09:44:58 -07:00
|
|
|
[self informError:[request error]];
|
2010-11-13 13:42:20 -05:00
|
|
|
}
|
|
|
|
|
2011-09-05 22:06:31 -07:00
|
|
|
- (void)finishLoadingFeedList:(ASIHTTPRequest *)request {
|
|
|
|
if ([request responseStatusCode] == 403) {
|
2011-11-30 09:38:31 -08:00
|
|
|
return [appDelegate showLogin];
|
|
|
|
} else if ([request responseStatusCode] >= 500) {
|
|
|
|
[pull finishedLoading];
|
|
|
|
return [self informError:@"The server barfed!"];
|
2011-09-05 22:06:31 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
initWithDictionary:[responseString JSONValue]];
|
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
self.stillVisibleFeeds = [NSMutableDictionary dictionary];
|
|
|
|
self.visibleFeeds = [NSMutableDictionary dictionary];
|
|
|
|
[pull finishedLoading];
|
|
|
|
[self loadFavicons];
|
2012-06-26 11:45:42 -07:00
|
|
|
|
2011-09-05 22:06:31 -07:00
|
|
|
appDelegate.activeUsername = [results objectForKey:@"user"];
|
2012-06-27 10:04:44 -07:00
|
|
|
//if (appDelegate.feedsViewController.view.window) {
|
2011-09-05 22:06:31 -07:00
|
|
|
[appDelegate setTitle:[results objectForKey:@"user"]];
|
2012-06-27 10:04:44 -07:00
|
|
|
//}
|
2012-07-11 10:33:39 -07:00
|
|
|
|
|
|
|
|
|
|
|
NSString *url = [NSString stringWithFormat:@"%@", [[results objectForKey:@"social_profile"] objectForKey:@"photo_url"]];
|
|
|
|
NSURL * imageURL = [NSURL URLWithString:url];
|
|
|
|
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
|
|
|
|
UIImage * userAvatarImage = [UIImage imageWithData:imageData];
|
|
|
|
userAvatarImage = [self roundCorneredImage:userAvatarImage radius:6];
|
|
|
|
|
|
|
|
UIButton *userAvatarButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
userAvatarButton.bounds = CGRectMake(0, 0, 32, 32);
|
|
|
|
[userAvatarButton setImage:userAvatarImage forState:UIControlStateNormal];
|
|
|
|
|
|
|
|
UIBarButtonItem *userAvatar = [[UIBarButtonItem alloc]
|
|
|
|
initWithCustomView:userAvatarButton];
|
|
|
|
|
|
|
|
self.navigationItem.leftBarButtonItem = userAvatar;
|
|
|
|
|
|
|
|
[userAvatar release];
|
2012-06-26 12:29:37 -07:00
|
|
|
|
2011-09-05 22:06:31 -07:00
|
|
|
NSMutableDictionary *sortedFolders = [[NSMutableDictionary alloc] init];
|
2011-10-14 17:15:48 -07:00
|
|
|
NSArray *sortedArray;
|
2011-09-05 22:06:31 -07:00
|
|
|
|
2012-07-01 18:26:39 -07:00
|
|
|
// Set up dictUserProfile
|
|
|
|
appDelegate.dictUserProfile = [results objectForKey:@"social_profile"];
|
2012-07-10 16:48:05 -07:00
|
|
|
[appDelegate.dashboardViewController refreshInteractions];
|
|
|
|
|
2011-09-05 22:06:31 -07:00
|
|
|
|
2012-06-26 12:29:37 -07:00
|
|
|
// Set up dictSocialFeeds
|
2012-06-26 11:45:42 -07:00
|
|
|
NSArray *socialFeedsArray = [results objectForKey:@"social_feeds"];
|
2012-06-25 15:02:20 -07:00
|
|
|
NSMutableArray *socialFolder = [[NSMutableArray alloc] init];
|
|
|
|
NSMutableDictionary *socialDict = [[NSMutableDictionary alloc] init];
|
2012-06-26 16:24:19 -07:00
|
|
|
appDelegate.dictActiveFeeds = [[NSMutableDictionary alloc] init];
|
2012-06-25 15:02:20 -07:00
|
|
|
|
2012-06-26 11:45:42 -07:00
|
|
|
for (int i = 0; i < socialFeedsArray.count; i++) {
|
2012-06-25 15:02:20 -07:00
|
|
|
NSString *userKey = [NSString stringWithFormat:@"%@",
|
2012-06-26 11:45:42 -07:00
|
|
|
[[socialFeedsArray objectAtIndex:i] objectForKey:@"id"]];
|
|
|
|
[socialFolder addObject: [[socialFeedsArray objectAtIndex:i] objectForKey:@"id"]];
|
|
|
|
[socialDict setObject:[socialFeedsArray objectAtIndex:i]
|
2012-06-25 15:02:20 -07:00
|
|
|
forKey:userKey];
|
|
|
|
}
|
2012-07-01 18:26:39 -07:00
|
|
|
|
2012-06-25 15:02:20 -07:00
|
|
|
appDelegate.dictSocialFeeds = socialDict;
|
2012-06-26 11:45:42 -07:00
|
|
|
[self loadAvatars];
|
2012-07-10 16:48:05 -07:00
|
|
|
|
2012-06-26 12:29:37 -07:00
|
|
|
// set up dictFolders
|
|
|
|
NSMutableDictionary * allFolders = [results objectForKey:@"flat_folders"];
|
|
|
|
[allFolders setValue:socialFolder forKey:@""];
|
|
|
|
appDelegate.dictFolders = allFolders;
|
|
|
|
|
|
|
|
// set up dictFeeds
|
|
|
|
appDelegate.dictFeeds = [results objectForKey:@"feeds"];
|
|
|
|
|
|
|
|
// sort all the folders
|
|
|
|
appDelegate.dictFoldersArray = [NSMutableArray array];
|
|
|
|
for (id f in appDelegate.dictFolders) {
|
|
|
|
[appDelegate.dictFoldersArray addObject:f];
|
|
|
|
NSArray *folder = [appDelegate.dictFolders objectForKey:f];
|
|
|
|
sortedArray = [folder sortedArrayUsingComparator:^NSComparisonResult(id id1, id id2) {
|
|
|
|
NSString *feedTitleA;
|
|
|
|
NSString *feedTitleB;
|
|
|
|
|
|
|
|
if ([appDelegate isSocialFeed:[NSString stringWithFormat:@"%@", id1]]) {
|
|
|
|
feedTitleA = [[appDelegate.dictSocialFeeds
|
|
|
|
objectForKey:[NSString stringWithFormat:@"%@", id1]]
|
|
|
|
objectForKey:@"feed_title"];
|
|
|
|
feedTitleB = [[appDelegate.dictSocialFeeds
|
|
|
|
objectForKey:[NSString stringWithFormat:@"%@", id2]]
|
|
|
|
objectForKey:@"feed_title"];
|
|
|
|
} else {
|
|
|
|
feedTitleA = [[appDelegate.dictFeeds
|
|
|
|
objectForKey:[NSString stringWithFormat:@"%@", id1]]
|
|
|
|
objectForKey:@"feed_title"];
|
|
|
|
feedTitleB = [[appDelegate.dictFeeds
|
|
|
|
objectForKey:[NSString stringWithFormat:@"%@", id2]]
|
|
|
|
objectForKey:@"feed_title"];
|
|
|
|
}
|
|
|
|
return [feedTitleA caseInsensitiveCompare:feedTitleB];
|
|
|
|
}];
|
|
|
|
[sortedFolders setValue:sortedArray forKey:f];
|
|
|
|
}
|
2012-06-26 11:45:42 -07:00
|
|
|
|
2011-10-14 17:15:48 -07:00
|
|
|
appDelegate.dictFolders = sortedFolders;
|
2011-10-04 18:01:35 -07:00
|
|
|
[appDelegate.dictFoldersArray sortUsingSelector:@selector(caseInsensitiveCompare:)];
|
2012-06-25 15:02:20 -07:00
|
|
|
|
2012-06-27 10:04:44 -07:00
|
|
|
if (self.viewShowingAllFeeds) {
|
|
|
|
[self calculateFeedLocations:NO];
|
|
|
|
} else {
|
|
|
|
[self calculateFeedLocations:YES];
|
|
|
|
}
|
2011-09-05 22:06:31 -07:00
|
|
|
[self.feedTitlesTable reloadData];
|
2012-06-27 10:04:44 -07:00
|
|
|
|
|
|
|
|
2012-06-28 11:12:38 -07:00
|
|
|
// NSLog(@"appDelegate.dictFolders: %@", appDelegate.dictFolders);
|
|
|
|
// NSLog(@"appDelegate.dictFoldersArray: %@", appDelegate.dictFoldersArray);
|
2011-09-05 22:06:31 -07:00
|
|
|
|
2012-06-27 10:04:44 -07:00
|
|
|
// test for latest version of app
|
2012-06-09 09:38:32 -07:00
|
|
|
NSString *serveriPhoneVersion = [results objectForKey:@"iphone_version"];
|
2011-12-07 09:57:33 -08:00
|
|
|
NSString *currentiPhoneVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
|
2012-06-07 12:45:11 -07:00
|
|
|
|
|
|
|
float serveriPhoneVersionFloat = [serveriPhoneVersion floatValue];
|
|
|
|
float currentiPhoneVersionFloat = [currentiPhoneVersion floatValue];
|
|
|
|
|
|
|
|
if (currentiPhoneVersionFloat < serveriPhoneVersionFloat) {
|
|
|
|
NSLog(@"Version: %f - %f", serveriPhoneVersionFloat, currentiPhoneVersionFloat);
|
2012-06-26 11:45:42 -07:00
|
|
|
NSString *title = [NSString stringWithFormat:@
|
|
|
|
"You should download the new version of NewsBlur.\n\nNew version: v%@\nYou have: v%@",
|
|
|
|
serveriPhoneVersion,
|
|
|
|
currentiPhoneVersion];
|
|
|
|
UIAlertView *upgradeConfirm = [[UIAlertView alloc] initWithTitle:title
|
|
|
|
message:nil
|
|
|
|
delegate:self
|
|
|
|
cancelButtonTitle:@"Cancel"
|
|
|
|
otherButtonTitles:@"Upgrade!", nil];
|
2011-12-07 09:57:33 -08:00
|
|
|
[upgradeConfirm show];
|
|
|
|
[upgradeConfirm setTag:2];
|
|
|
|
[upgradeConfirm release];
|
|
|
|
}
|
|
|
|
|
2011-09-05 22:06:31 -07:00
|
|
|
[sortedFolders release];
|
|
|
|
[results release];
|
2010-11-11 23:48:27 -05:00
|
|
|
}
|
|
|
|
|
2012-06-28 11:12:38 -07:00
|
|
|
- (IBAction)showMenuButton:(id)sender {
|
2012-06-19 13:51:48 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
if (popoverController == nil) {
|
|
|
|
popoverController = [[UIPopoverController alloc]
|
|
|
|
initWithContentViewController:appDelegate.feedsMenuViewController];
|
|
|
|
|
|
|
|
popoverController.delegate = self;
|
|
|
|
}
|
|
|
|
|
2012-07-02 11:28:55 -07:00
|
|
|
[popoverController setPopoverContentSize:CGSizeMake(200, 86)];
|
2012-06-28 11:12:38 -07:00
|
|
|
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
|
2012-06-19 13:51:48 -07:00
|
|
|
} else {
|
|
|
|
[appDelegate showFeedsMenu];
|
|
|
|
}
|
2011-08-21 21:39:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
|
2012-06-19 10:55:46 -07:00
|
|
|
if (alertView.tag == 2) {
|
2011-12-07 09:57:33 -08:00
|
|
|
if (buttonIndex == 0) {
|
|
|
|
return;
|
|
|
|
} else {
|
2012-06-07 12:45:11 -07:00
|
|
|
// this doesn't work in simulator!!! because simulator has no app store
|
2011-12-07 09:57:33 -08:00
|
|
|
NSURL *url = [NSURL URLWithString:@"http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=463981119&mt=8"];
|
|
|
|
[[UIApplication sharedApplication] openURL:url];
|
|
|
|
}
|
2011-08-24 21:44:16 -07:00
|
|
|
}
|
2010-11-13 13:42:20 -05:00
|
|
|
}
|
2010-11-11 23:48:27 -05:00
|
|
|
|
2012-06-27 10:04:44 -07:00
|
|
|
- (void)switchSitesUnread {
|
|
|
|
NSDictionary *feed;
|
2011-08-24 21:44:16 -07:00
|
|
|
|
|
|
|
NSInteger intelligenceLevel = [appDelegate selectedIntelligence];
|
|
|
|
NSMutableArray *indexPaths = [NSMutableArray array];
|
|
|
|
|
|
|
|
if (self.viewShowingAllFeeds) {
|
|
|
|
[self calculateFeedLocations:NO];
|
|
|
|
}
|
|
|
|
|
2012-06-27 10:04:44 -07:00
|
|
|
// NSLog(@"View showing all: %d and %@", self.viewShowingAllFeeds, self.stillVisibleFeeds);
|
2011-10-19 08:49:35 -07:00
|
|
|
|
2011-10-04 18:01:35 -07:00
|
|
|
for (int s=0; s < [appDelegate.dictFoldersArray count]; s++) {
|
|
|
|
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:s];
|
2011-08-24 21:44:16 -07:00
|
|
|
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
|
2011-10-04 18:01:35 -07:00
|
|
|
NSArray *originalFolder = [appDelegate.dictFolders objectForKey:folderName];
|
2011-08-24 21:44:16 -07:00
|
|
|
for (int f=0; f < [activeFolderFeeds count]; f++) {
|
|
|
|
int location = [[activeFolderFeeds objectAtIndex:f] intValue];
|
|
|
|
id feedId = [originalFolder objectAtIndex:location];
|
|
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:f inSection:s];
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
2012-06-26 12:12:31 -07:00
|
|
|
if ([appDelegate isSocialFeed:feedIdStr]) {
|
|
|
|
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
|
|
|
|
} else {
|
|
|
|
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
|
|
|
|
}
|
2012-06-27 10:04:44 -07:00
|
|
|
|
2012-06-19 11:48:51 -07:00
|
|
|
int maxScore = [NewsBlurViewController computeMaxScoreForFeed:feed];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2011-10-19 08:49:35 -07:00
|
|
|
if (!self.viewShowingAllFeeds ||
|
|
|
|
(self.viewShowingAllFeeds && ![self.stillVisibleFeeds objectForKey:feedIdStr])) {
|
|
|
|
if (maxScore < intelligenceLevel) {
|
|
|
|
[indexPaths addObject:indexPath];
|
|
|
|
}
|
2011-08-24 21:44:16 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!self.viewShowingAllFeeds) {
|
|
|
|
[self calculateFeedLocations:YES];
|
|
|
|
}
|
2011-08-04 17:27:31 -07:00
|
|
|
|
|
|
|
[self.feedTitlesTable beginUpdates];
|
|
|
|
if ([indexPaths count] > 0) {
|
2011-08-24 21:44:16 -07:00
|
|
|
if (self.viewShowingAllFeeds) {
|
|
|
|
[self.feedTitlesTable insertRowsAtIndexPaths:indexPaths
|
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
} else {
|
|
|
|
[self.feedTitlesTable deleteRowsAtIndexPaths:indexPaths
|
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
}
|
2011-08-04 17:27:31 -07:00
|
|
|
}
|
|
|
|
[self.feedTitlesTable endUpdates];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2012-05-17 22:10:55 -04:00
|
|
|
CGPoint offset = CGPointMake(0, 0);
|
|
|
|
[self.feedTitlesTable setContentOffset:offset animated:YES];
|
2012-06-27 10:04:44 -07:00
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
// Forget still visible feeds, since they won't be populated when
|
|
|
|
// all feeds are showing, and shouldn't be populated after this
|
|
|
|
// hide/show runs.
|
|
|
|
self.stillVisibleFeeds = [NSMutableDictionary dictionary];
|
2011-08-27 15:53:51 -07:00
|
|
|
[self redrawUnreadCounts];
|
2011-08-03 10:00:41 -07:00
|
|
|
}
|
|
|
|
|
2010-06-20 11:04:23 -04:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Table View - Feed List
|
|
|
|
|
|
|
|
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
2011-10-04 18:01:35 -07:00
|
|
|
return [appDelegate.dictFoldersArray count];
|
2010-06-20 11:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
|
2011-10-04 18:01:35 -07:00
|
|
|
return [appDelegate.dictFoldersArray objectAtIndex:section];
|
2010-06-20 11:04:23 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2011-10-04 18:01:35 -07:00
|
|
|
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:section];
|
2011-08-24 21:44:16 -07:00
|
|
|
return [[self.activeFeedLocations objectForKey:folderName] count];
|
2010-06-20 11:04:23 -04:00
|
|
|
}
|
|
|
|
|
2011-08-02 18:03:11 -07:00
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView
|
2011-11-29 18:39:52 -08:00
|
|
|
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2012-06-25 15:02:20 -07:00
|
|
|
NSDictionary *feed;
|
2011-08-24 21:44:16 -07:00
|
|
|
static NSString *FeedCellIdentifier = @"FeedCellIdentifier";
|
|
|
|
|
|
|
|
FeedTableCell *cell = (FeedTableCell *)[tableView dequeueReusableCellWithIdentifier:FeedCellIdentifier];
|
|
|
|
if (cell == nil) {
|
2011-10-15 15:26:18 -07:00
|
|
|
cell = [[[FeedTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FeedCellIdentifier"] autorelease];
|
2011-08-24 21:44:16 -07:00
|
|
|
cell.appDelegate = (NewsBlurAppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
|
}
|
|
|
|
|
2011-10-04 18:01:35 -07:00
|
|
|
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:indexPath.section];
|
|
|
|
NSArray *feeds = [appDelegate.dictFolders objectForKey:folderName];
|
2011-08-24 21:44:16 -07:00
|
|
|
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
|
|
|
|
int location = [[activeFolderFeeds objectAtIndex:indexPath.row] intValue];
|
|
|
|
id feedId = [feeds objectAtIndex:location];
|
2012-06-25 15:02:20 -07:00
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
2012-06-27 10:18:29 -07:00
|
|
|
BOOL isSocial = [appDelegate isSocialFeed:feedIdStr];
|
2012-06-25 15:02:20 -07:00
|
|
|
|
2012-06-27 10:18:29 -07:00
|
|
|
if (isSocial) {
|
2012-06-25 15:02:20 -07:00
|
|
|
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
|
2012-06-26 11:45:42 -07:00
|
|
|
cell.feedFavicon = [Utilities getImage:feedIdStr];
|
2012-06-25 15:02:20 -07:00
|
|
|
} else {
|
|
|
|
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
|
2012-06-25 18:05:25 -07:00
|
|
|
cell.feedFavicon = [Utilities getImage:feedIdStr];
|
2012-06-25 15:02:20 -07:00
|
|
|
}
|
2011-10-17 09:37:16 -07:00
|
|
|
cell.feedTitle = [feed objectForKey:@"feed_title"];
|
2011-08-24 21:44:16 -07:00
|
|
|
cell.positiveCount = [[feed objectForKey:@"ps"] intValue];
|
|
|
|
cell.neutralCount = [[feed objectForKey:@"nt"] intValue];
|
|
|
|
cell.negativeCount = [[feed objectForKey:@"ng"] intValue];
|
2012-06-27 10:18:29 -07:00
|
|
|
cell.isSocial = isSocial;
|
2011-08-24 21:44:16 -07:00
|
|
|
|
|
|
|
return cell;
|
2010-06-20 11:04:23 -04:00
|
|
|
}
|
|
|
|
|
2011-08-12 10:12:30 -07:00
|
|
|
- (void)tableView:(UITableView *)tableView
|
2011-11-29 18:39:52 -08:00
|
|
|
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
2012-06-25 15:02:20 -07:00
|
|
|
NSDictionary *feed;
|
2011-10-04 18:01:35 -07:00
|
|
|
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:indexPath.section];
|
|
|
|
NSArray *feeds = [appDelegate.dictFolders objectForKey:folderName];
|
2011-08-24 21:44:16 -07:00
|
|
|
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
|
|
|
|
int location = [[activeFolderFeeds objectAtIndex:indexPath.row] intValue];
|
|
|
|
id feedId = [feeds objectAtIndex:location];
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
2012-06-25 15:02:20 -07:00
|
|
|
|
2012-06-26 16:24:19 -07:00
|
|
|
if ([appDelegate isSocialFeed:feedIdStr]) {
|
2012-06-25 15:02:20 -07:00
|
|
|
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
|
2012-06-26 16:24:19 -07:00
|
|
|
appDelegate.isSocialView = YES;
|
2012-06-25 15:02:20 -07:00
|
|
|
} else {
|
|
|
|
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
|
2012-06-26 16:24:19 -07:00
|
|
|
appDelegate.isSocialView = NO;
|
2012-06-25 15:02:20 -07:00
|
|
|
}
|
2011-08-24 21:44:16 -07:00
|
|
|
|
|
|
|
// If all feeds are already showing, no need to remember this one.
|
|
|
|
if (!self.viewShowingAllFeeds) {
|
|
|
|
[self.stillVisibleFeeds setObject:indexPath forKey:feedIdStr];
|
|
|
|
}
|
|
|
|
|
|
|
|
[appDelegate setActiveFeed:feed];
|
2011-10-20 09:32:39 -07:00
|
|
|
[appDelegate setActiveFolder:folderName];
|
2011-08-24 21:44:16 -07:00
|
|
|
appDelegate.readStories = [NSMutableArray array];
|
2011-10-25 09:28:05 -07:00
|
|
|
appDelegate.isRiverView = NO;
|
2012-06-29 10:20:06 -07:00
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
[appDelegate loadFeedDetailView];
|
2010-06-20 11:04:23 -04:00
|
|
|
}
|
|
|
|
|
2011-08-12 10:12:30 -07:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView
|
2011-11-29 18:39:52 -08:00
|
|
|
heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2012-07-11 11:03:34 -07:00
|
|
|
|
|
|
|
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:indexPath.section];
|
|
|
|
|
|
|
|
if ([folderName isEqualToString:@""]) { // blurblogs
|
|
|
|
return kBlurblogTableViewRowHeight;
|
|
|
|
} else {
|
|
|
|
return kTableViewRowHeight;
|
|
|
|
}
|
2011-07-19 09:38:49 -07:00
|
|
|
}
|
|
|
|
|
2011-08-12 10:12:30 -07:00
|
|
|
- (UIView *)tableView:(UITableView *)tableView
|
2011-11-29 18:39:52 -08:00
|
|
|
viewForHeaderInSection:(NSInteger)section {
|
2012-06-07 13:37:23 -07:00
|
|
|
|
|
|
|
int headerLabelHeight, folderImageViewY, disclosureImageViewY;
|
2012-06-07 17:52:14 -07:00
|
|
|
|
2012-06-09 09:38:32 -07:00
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
|
2012-06-07 13:37:23 -07:00
|
|
|
headerLabelHeight = 30;
|
|
|
|
folderImageViewY = 7;
|
|
|
|
disclosureImageViewY = 8;
|
2012-06-09 09:38:32 -07:00
|
|
|
} else {
|
2012-06-07 13:37:23 -07:00
|
|
|
headerLabelHeight = 20;
|
|
|
|
folderImageViewY = 2;
|
|
|
|
disclosureImageViewY = 3;
|
|
|
|
}
|
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
// create the parent view that will hold header Label
|
2011-10-26 23:12:21 -07:00
|
|
|
UIControl* customView = [[[UIControl alloc]
|
|
|
|
initWithFrame:CGRectMake(0.0, 0.0,
|
2012-06-07 13:37:23 -07:00
|
|
|
tableView.bounds.size.width, headerLabelHeight + 1)]
|
2011-10-26 23:12:21 -07:00
|
|
|
autorelease];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
|
|
|
|
|
|
|
UIView *borderBottom = [[[UIView alloc]
|
2012-06-07 13:37:23 -07:00
|
|
|
initWithFrame:CGRectMake(0.0, headerLabelHeight,
|
2011-08-24 21:44:16 -07:00
|
|
|
tableView.bounds.size.width, 1.0)]
|
|
|
|
autorelease];
|
|
|
|
borderBottom.backgroundColor = [UIColorFromRGB(0xB7BDC6) colorWithAlphaComponent:0.5];
|
|
|
|
borderBottom.opaque = NO;
|
|
|
|
[customView addSubview:borderBottom];
|
|
|
|
|
|
|
|
UILabel * headerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
|
|
|
|
customView.opaque = NO;
|
|
|
|
headerLabel.backgroundColor = [UIColor clearColor];
|
|
|
|
headerLabel.opaque = NO;
|
|
|
|
headerLabel.textColor = [UIColor colorWithRed:0.3 green:0.3 blue:0.3 alpha:1.0];
|
|
|
|
headerLabel.highlightedTextColor = [UIColor whiteColor];
|
|
|
|
headerLabel.font = [UIFont boldSystemFontOfSize:11];
|
2012-06-07 13:37:23 -07:00
|
|
|
headerLabel.frame = CGRectMake(36.0, 1.0, 286.0, headerLabelHeight);
|
2011-11-30 18:46:11 -08:00
|
|
|
headerLabel.shadowColor = [UIColor colorWithRed:.94 green:0.94 blue:0.97 alpha:1.0];
|
|
|
|
headerLabel.shadowOffset = CGSizeMake(0.0, 1.0);
|
2011-11-29 18:39:52 -08:00
|
|
|
if (section == 0) {
|
2012-06-27 14:37:37 -07:00
|
|
|
headerLabel.text = @"BLURBLOGS";
|
2012-06-26 11:45:42 -07:00
|
|
|
customView.backgroundColor = [UIColorFromRGB(0xD7DDE6)
|
|
|
|
colorWithAlphaComponent:0.8];
|
|
|
|
} else if (section == 1) {
|
2011-11-29 18:39:52 -08:00
|
|
|
headerLabel.text = @"EVERYTHING";
|
2011-11-30 18:46:11 -08:00
|
|
|
customView.backgroundColor = [UIColorFromRGB(0xE6DDD7)
|
|
|
|
colorWithAlphaComponent:0.8];
|
2011-11-29 18:39:52 -08:00
|
|
|
} else {
|
2011-11-30 18:46:11 -08:00
|
|
|
headerLabel.text = [[appDelegate.dictFoldersArray objectAtIndex:section] uppercaseString];
|
2011-11-29 18:39:52 -08:00
|
|
|
customView.backgroundColor = [UIColorFromRGB(0xD7DDE6)
|
|
|
|
colorWithAlphaComponent:0.8];
|
|
|
|
}
|
2011-08-24 21:44:16 -07:00
|
|
|
[customView addSubview:headerLabel];
|
|
|
|
[headerLabel release];
|
|
|
|
|
|
|
|
UIImage *folderImage = [UIImage imageNamed:@"folder.png"];
|
|
|
|
UIImageView *folderImageView = [[UIImageView alloc] initWithImage:folderImage];
|
2012-07-01 12:08:30 -07:00
|
|
|
folderImageView.frame = CGRectMake(12.0, folderImageViewY, 16.0, 16.0);
|
2011-08-24 21:44:16 -07:00
|
|
|
[customView addSubview:folderImageView];
|
|
|
|
[folderImageView release];
|
2011-10-26 23:12:21 -07:00
|
|
|
|
2012-06-26 12:12:31 -07:00
|
|
|
if (section != 0) {
|
|
|
|
UIImage *disclosureImage = [UIImage imageNamed:@"disclosure.png"];
|
|
|
|
UIImageView *disclosureImageView = [[UIImageView alloc] initWithImage:disclosureImage];
|
|
|
|
disclosureImageView.frame = CGRectMake(customView.frame.size.width - 20, disclosureImageViewY, 9.0, 14.0);
|
|
|
|
[customView addSubview:disclosureImageView];
|
|
|
|
[disclosureImageView release];
|
|
|
|
}
|
2011-10-26 23:12:21 -07:00
|
|
|
|
2011-10-25 09:28:05 -07:00
|
|
|
UIButton *invisibleHeaderButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
|
invisibleHeaderButton.frame = CGRectMake(0, 0, customView.frame.size.width, customView.frame.size.height);
|
|
|
|
invisibleHeaderButton.alpha = .1;
|
2011-10-25 09:47:55 -07:00
|
|
|
invisibleHeaderButton.tag = section;
|
|
|
|
[invisibleHeaderButton addTarget:self action:@selector(didSelectSectionHeader:) forControlEvents:UIControlEventTouchUpInside];
|
2011-10-25 09:28:05 -07:00
|
|
|
[customView addSubview:invisibleHeaderButton];
|
|
|
|
|
2011-10-26 23:12:21 -07:00
|
|
|
[invisibleHeaderButton addTarget:self action:@selector(sectionTapped:) forControlEvents:UIControlEventTouchDown];
|
2011-11-30 18:46:11 -08:00
|
|
|
[invisibleHeaderButton addTarget:self action:@selector(sectionUntapped:) forControlEvents:UIControlEventTouchUpInside];
|
2012-06-26 12:12:31 -07:00
|
|
|
[invisibleHeaderButton addTarget:self action:@selector(sectionUntappedOutside:) forControlEvents:UIControlEventTouchUpOutside];
|
2011-10-26 23:12:21 -07:00
|
|
|
|
|
|
|
[customView setAutoresizingMask:UIViewAutoresizingNone];
|
2011-08-24 21:44:16 -07:00
|
|
|
return customView;
|
2011-08-12 10:12:30 -07:00
|
|
|
}
|
|
|
|
|
2011-10-26 23:12:21 -07:00
|
|
|
- (IBAction)sectionTapped:(UIButton *)button {
|
2012-06-26 12:12:31 -07:00
|
|
|
// current position of social header
|
|
|
|
if (button.tag == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-30 18:46:11 -08:00
|
|
|
button.backgroundColor =[UIColor colorWithRed:0.15 green:0.55 blue:0.95 alpha:1.0];
|
|
|
|
}
|
|
|
|
- (IBAction)sectionUntapped:(UIButton *)button {
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.15 * NSEC_PER_SEC),
|
|
|
|
dispatch_get_current_queue(), ^{
|
|
|
|
button.backgroundColor = [UIColor clearColor];
|
|
|
|
});
|
2011-10-26 23:12:21 -07:00
|
|
|
}
|
|
|
|
|
2012-06-26 12:12:31 -07:00
|
|
|
- (IBAction)sectionUntappedOutside:(UIButton *)button {
|
|
|
|
button.backgroundColor = [UIColor clearColor];
|
|
|
|
}
|
|
|
|
|
2011-08-12 10:12:30 -07:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
|
2011-11-29 18:39:52 -08:00
|
|
|
// NSString *folder = [appDelegate.dictFoldersArray objectAtIndex:section];
|
|
|
|
// if ([[folder stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
|
|
|
|
// return 0;
|
|
|
|
// }
|
2012-06-07 13:37:23 -07:00
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad){
|
|
|
|
return 31;
|
|
|
|
}else{
|
|
|
|
return 21;
|
|
|
|
}
|
2011-08-12 10:12:30 -07:00
|
|
|
}
|
|
|
|
|
2011-10-25 09:47:55 -07:00
|
|
|
- (void)didSelectSectionHeader:(UIButton *)button {
|
2012-06-26 12:12:31 -07:00
|
|
|
// current position of social header
|
|
|
|
if (button.tag == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2011-10-25 09:47:55 -07:00
|
|
|
|
|
|
|
appDelegate.readStories = [NSMutableArray array];
|
|
|
|
appDelegate.isRiverView = YES;
|
2011-10-26 08:40:31 -07:00
|
|
|
NSMutableArray *feeds = [NSMutableArray array];
|
2011-11-29 18:39:52 -08:00
|
|
|
|
|
|
|
if (button.tag == 0) {
|
|
|
|
[appDelegate setActiveFolder:@"Everything"];
|
|
|
|
for (NSString *folderName in self.activeFeedLocations) {
|
|
|
|
NSArray *originalFolder = [appDelegate.dictFolders objectForKey:folderName];
|
|
|
|
NSArray *folderFeeds = [self.activeFeedLocations objectForKey:folderName];
|
|
|
|
for (int l=0; l < [folderFeeds count]; l++) {
|
|
|
|
[feeds addObject:[originalFolder objectAtIndex:[[folderFeeds objectAtIndex:l] intValue]]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:button.tag];
|
|
|
|
|
|
|
|
[appDelegate setActiveFolder:folderName];
|
|
|
|
NSArray *originalFolder = [appDelegate.dictFolders objectForKey:folderName];
|
|
|
|
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
|
|
|
|
for (int l=0; l < [activeFolderFeeds count]; l++) {
|
|
|
|
[feeds addObject:[originalFolder objectAtIndex:[[activeFolderFeeds objectAtIndex:l] intValue]]];
|
|
|
|
}
|
|
|
|
|
2011-10-26 08:40:31 -07:00
|
|
|
}
|
|
|
|
appDelegate.activeFolderFeeds = feeds;
|
|
|
|
|
|
|
|
[appDelegate loadRiverFeedDetailView];
|
2011-10-25 09:28:05 -07:00
|
|
|
}
|
|
|
|
|
2011-08-02 09:16:54 -07:00
|
|
|
- (IBAction)selectIntelligence {
|
2012-07-10 12:34:58 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.feedTitlesTable animated:NO];
|
|
|
|
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.feedTitlesTable animated:YES];
|
2012-07-09 18:17:01 -07:00
|
|
|
|
|
|
|
hud.mode = MBProgressHUDModeText;
|
|
|
|
hud.removeFromSuperViewOnHide = YES;
|
|
|
|
|
2012-07-09 17:32:22 -07:00
|
|
|
int selectedSegmentIndex = [self.intelligenceControl selectedSegmentIndex];
|
2011-08-27 15:53:51 -07:00
|
|
|
|
2012-07-09 17:32:22 -07:00
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
|
|
|
if (selectedSegmentIndex == 0) {
|
2012-07-09 18:17:01 -07:00
|
|
|
hud.labelText = @"All stories";
|
2012-07-09 17:32:22 -07:00
|
|
|
[userPreferences setInteger:0 forKey:@"siteDisplayMode"];
|
|
|
|
[userPreferences synchronize];
|
|
|
|
|
2012-07-09 17:42:32 -07:00
|
|
|
if (appDelegate.selectedIntelligence == 1) {
|
2012-07-09 17:32:22 -07:00
|
|
|
[appDelegate setSelectedIntelligence:0];
|
|
|
|
[self updateFeedsWithIntelligence:1 newLevel:0];
|
|
|
|
[self redrawUnreadCounts];
|
|
|
|
}
|
2012-07-09 17:42:32 -07:00
|
|
|
self.viewShowingAllFeeds = YES;
|
|
|
|
[self switchSitesUnread];
|
2012-07-09 18:17:01 -07:00
|
|
|
} else if(selectedSegmentIndex == 1) {
|
|
|
|
hud.labelText = @"Unread stories";
|
2012-07-09 17:32:22 -07:00
|
|
|
[userPreferences setInteger:1 forKey:@"siteDisplayMode"];
|
|
|
|
[userPreferences synchronize];
|
|
|
|
|
2012-07-09 17:42:32 -07:00
|
|
|
if (appDelegate.selectedIntelligence == 1) {
|
2012-07-09 17:32:22 -07:00
|
|
|
[appDelegate setSelectedIntelligence:0];
|
|
|
|
[self updateFeedsWithIntelligence:1 newLevel:0];
|
|
|
|
[self redrawUnreadCounts];
|
|
|
|
}
|
2012-07-09 17:42:32 -07:00
|
|
|
self.viewShowingAllFeeds = NO;
|
|
|
|
[self switchSitesUnread];
|
2012-07-09 17:32:22 -07:00
|
|
|
} else {
|
2012-07-09 18:17:01 -07:00
|
|
|
hud.labelText = @"Focus stories";
|
2012-07-09 17:32:22 -07:00
|
|
|
[userPreferences setInteger:2 forKey:@"siteDisplayMode"];
|
|
|
|
[userPreferences synchronize];
|
|
|
|
|
|
|
|
if (self.viewShowingAllFeeds == YES) {
|
|
|
|
self.viewShowingAllFeeds = NO;
|
|
|
|
[self switchSitesUnread];
|
|
|
|
}
|
|
|
|
[appDelegate setSelectedIntelligence:1];
|
|
|
|
[self updateFeedsWithIntelligence:0 newLevel:1];
|
|
|
|
[self redrawUnreadCounts];
|
2011-08-24 21:44:16 -07:00
|
|
|
}
|
|
|
|
|
2012-07-09 18:17:01 -07:00
|
|
|
|
|
|
|
|
|
|
|
[hud hide:YES afterDelay:0.75];
|
|
|
|
|
2011-08-02 18:19:46 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateFeedsWithIntelligence:(int)previousLevel newLevel:(int)newLevel {
|
2011-08-02 09:16:54 -07:00
|
|
|
NSMutableArray *insertIndexPaths = [NSMutableArray array];
|
|
|
|
NSMutableArray *deleteIndexPaths = [NSMutableArray array];
|
2011-10-14 16:35:40 -07:00
|
|
|
NSMutableDictionary *addToVisibleFeeds = [NSMutableDictionary dictionary];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2011-08-24 21:41:44 -07:00
|
|
|
if (newLevel <= previousLevel) {
|
2011-08-24 21:44:16 -07:00
|
|
|
[self calculateFeedLocations:NO];
|
|
|
|
}
|
|
|
|
|
2011-10-04 18:01:35 -07:00
|
|
|
for (int s=0; s < [appDelegate.dictFoldersArray count]; s++) {
|
|
|
|
NSString *folderName = [appDelegate.dictFoldersArray objectAtIndex:s];
|
2011-08-24 21:44:16 -07:00
|
|
|
NSArray *activeFolderFeeds = [self.activeFeedLocations objectForKey:folderName];
|
2011-10-04 18:01:35 -07:00
|
|
|
NSArray *originalFolder = [appDelegate.dictFolders objectForKey:folderName];
|
2011-10-14 16:35:40 -07:00
|
|
|
|
2011-10-25 09:47:55 -07:00
|
|
|
// if (s == 9) {
|
2011-10-14 16:35:40 -07:00
|
|
|
// NSLog(@"Section %d: %@. %d to %d", s, folderName, previousLevel, newLevel);
|
2011-10-25 09:47:55 -07:00
|
|
|
// }
|
2011-10-14 16:35:40 -07:00
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
for (int f=0; f < [originalFolder count]; f++) {
|
|
|
|
NSNumber *feedId = [originalFolder objectAtIndex:f];
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
2012-06-26 12:29:37 -07:00
|
|
|
NSDictionary *feed;
|
|
|
|
|
|
|
|
if ([appDelegate isSocialFeed:feedIdStr]) {
|
|
|
|
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
|
|
|
|
} else {
|
|
|
|
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
|
|
|
|
}
|
2012-06-19 11:48:51 -07:00
|
|
|
int maxScore = [NewsBlurViewController computeMaxScoreForFeed:feed];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2011-10-25 09:47:55 -07:00
|
|
|
// if (s == 9) {
|
2011-10-14 16:35:40 -07:00
|
|
|
// NSLog(@"MaxScore: %d for %@ (%@/%@/%@). Visible: %@", maxScore,
|
|
|
|
// [feed objectForKey:@"feed_title"],
|
|
|
|
// [feed objectForKey:@"ng"], [feed objectForKey:@"nt"], [feed objectForKey:@"ng"],
|
|
|
|
// [self.visibleFeeds objectForKey:feedIdStr]);
|
2011-10-25 09:47:55 -07:00
|
|
|
// }
|
2011-10-14 16:35:40 -07:00
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
if ([self.visibleFeeds objectForKey:feedIdStr]) {
|
|
|
|
if (maxScore < newLevel) {
|
|
|
|
for (int l=0; l < [activeFolderFeeds count]; l++) {
|
|
|
|
if ([originalFolder objectAtIndex:[[activeFolderFeeds objectAtIndex:l] intValue]] == feedId) {
|
|
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:l inSection:s];
|
|
|
|
[deleteIndexPaths addObject:indexPath];
|
|
|
|
if ([self.stillVisibleFeeds objectForKey:feedIdStr]) {
|
|
|
|
[self.stillVisibleFeeds removeObjectForKey:feedIdStr];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (maxScore >= newLevel) {
|
|
|
|
for (int l=0; l < [activeFolderFeeds count]; l++) {
|
|
|
|
if ([originalFolder objectAtIndex:[[activeFolderFeeds objectAtIndex:l] intValue]] == feedId) {
|
|
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:l inSection:s];
|
2011-10-14 16:35:40 -07:00
|
|
|
[addToVisibleFeeds setObject:[NSNumber numberWithBool:YES] forKey:feedIdStr];
|
2011-08-24 21:44:16 -07:00
|
|
|
[insertIndexPaths addObject:indexPath];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-14 16:35:40 -07:00
|
|
|
for (id feedIdStr in addToVisibleFeeds) {
|
|
|
|
[self.visibleFeeds setObject:[addToVisibleFeeds objectForKey:feedIdStr] forKey:feedIdStr];
|
|
|
|
}
|
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
for (id feedIdStr in [self.stillVisibleFeeds allKeys]) {
|
2012-06-26 12:29:37 -07:00
|
|
|
NSDictionary *feed;
|
|
|
|
if ([appDelegate isSocialFeed:feedIdStr]) {
|
|
|
|
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
|
|
|
|
} else {
|
|
|
|
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
|
|
|
|
}
|
|
|
|
|
2012-06-19 11:48:51 -07:00
|
|
|
int maxScore = [NewsBlurViewController computeMaxScoreForFeed:feed];
|
2011-08-24 21:44:16 -07:00
|
|
|
if (previousLevel != newLevel && maxScore < newLevel) {
|
|
|
|
[deleteIndexPaths addObject:[self.stillVisibleFeeds objectForKey:feedIdStr]];
|
|
|
|
[self.stillVisibleFeeds removeObjectForKey:feedIdStr];
|
|
|
|
[self.visibleFeeds removeObjectForKey:feedIdStr];
|
|
|
|
}
|
2011-08-02 09:16:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newLevel > previousLevel) {
|
2011-10-14 16:35:40 -07:00
|
|
|
[self calculateFeedLocations:NO];
|
2011-08-02 09:16:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
[self.feedTitlesTable beginUpdates];
|
|
|
|
if ([deleteIndexPaths count] > 0) {
|
|
|
|
[self.feedTitlesTable deleteRowsAtIndexPaths:deleteIndexPaths
|
2011-08-24 21:44:16 -07:00
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
2011-08-02 09:16:54 -07:00
|
|
|
}
|
|
|
|
if ([insertIndexPaths count] > 0) {
|
|
|
|
[self.feedTitlesTable insertRowsAtIndexPaths:insertIndexPaths
|
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
}
|
|
|
|
[self.feedTitlesTable endUpdates];
|
2011-10-14 16:35:40 -07:00
|
|
|
|
|
|
|
[self calculateFeedLocations:YES];
|
2011-08-02 10:13:06 -07:00
|
|
|
}
|
|
|
|
|
2011-08-27 15:53:51 -07:00
|
|
|
- (void)redrawUnreadCounts {
|
|
|
|
for (UITableViewCell *cell in self.feedTitlesTable.visibleCells) {
|
|
|
|
[cell setNeedsDisplay];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-24 21:41:44 -07:00
|
|
|
- (void)calculateFeedLocations:(BOOL)markVisible {
|
2012-06-25 15:02:20 -07:00
|
|
|
NSDictionary *feed = [[NSDictionary alloc] init];
|
2011-08-02 10:13:06 -07:00
|
|
|
self.activeFeedLocations = [NSMutableDictionary dictionary];
|
2011-08-24 21:44:16 -07:00
|
|
|
if (markVisible) {
|
|
|
|
self.visibleFeeds = [NSMutableDictionary dictionary];
|
|
|
|
}
|
2012-06-25 15:02:20 -07:00
|
|
|
|
2011-10-04 18:01:35 -07:00
|
|
|
for (NSString *folderName in appDelegate.dictFoldersArray) {
|
|
|
|
NSArray *folder = [appDelegate.dictFolders objectForKey:folderName];
|
2011-08-24 21:44:16 -07:00
|
|
|
NSMutableArray *feedLocations = [NSMutableArray array];
|
2012-06-26 11:45:42 -07:00
|
|
|
for (int f = 0; f < [folder count]; f++) {
|
2011-08-24 21:44:16 -07:00
|
|
|
id feedId = [folder objectAtIndex:f];
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
|
|
|
|
2012-06-26 11:45:42 -07:00
|
|
|
if ([folderName isEqualToString:@""]){
|
2012-06-25 15:02:20 -07:00
|
|
|
feed = [appDelegate.dictSocialFeeds objectForKey:feedIdStr];
|
|
|
|
} else {
|
|
|
|
feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
|
|
|
|
}
|
|
|
|
|
2011-08-24 21:44:16 -07:00
|
|
|
if (self.viewShowingAllFeeds) {
|
|
|
|
NSNumber *location = [NSNumber numberWithInt:f];
|
|
|
|
[feedLocations addObject:location];
|
|
|
|
} else {
|
2012-06-19 11:48:51 -07:00
|
|
|
int maxScore = [NewsBlurViewController computeMaxScoreForFeed:feed];
|
2011-10-14 16:35:40 -07:00
|
|
|
// NSLog(@"Computing score for %@: %d in %d (markVisible: %d)",
|
|
|
|
// [feed objectForKey:@"feed_title"], maxScore, appDelegate.selectedIntelligence, markVisible);
|
2011-08-24 21:44:16 -07:00
|
|
|
if (maxScore >= appDelegate.selectedIntelligence) {
|
|
|
|
NSNumber *location = [NSNumber numberWithInt:f];
|
|
|
|
[feedLocations addObject:location];
|
|
|
|
if (markVisible) {
|
|
|
|
[self.visibleFeeds setObject:[NSNumber numberWithBool:YES] forKey:feedIdStr];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
[self.activeFeedLocations setObject:feedLocations forKey:folderName];
|
|
|
|
}
|
2012-06-25 15:02:20 -07:00
|
|
|
// NSLog(@"Active feed locations %@", self.activeFeedLocations);
|
2011-08-02 09:16:54 -07:00
|
|
|
}
|
|
|
|
|
2011-08-02 18:03:11 -07:00
|
|
|
+ (int)computeMaxScoreForFeed:(NSDictionary *)feed {
|
2011-08-24 21:44:16 -07:00
|
|
|
int maxScore = -2;
|
|
|
|
if ([[feed objectForKey:@"ng"] intValue] > 0) maxScore = -1;
|
|
|
|
if ([[feed objectForKey:@"nt"] intValue] > 0) maxScore = 0;
|
|
|
|
if ([[feed objectForKey:@"ps"] intValue] > 0) maxScore = 1;
|
|
|
|
return maxScore;
|
2011-08-02 18:03:11 -07:00
|
|
|
}
|
|
|
|
|
2011-08-04 17:58:28 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Favicons
|
|
|
|
|
|
|
|
|
|
|
|
- (void)loadFavicons {
|
2011-08-24 21:44:16 -07:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/favicons",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
2012-06-29 10:20:06 -07:00
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
|
|
|
[request setDidFinishSelector:@selector(saveAndDrawFavicons:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
2011-08-04 17:58:28 -07:00
|
|
|
}
|
|
|
|
|
2012-06-26 11:45:42 -07:00
|
|
|
- (void)loadAvatars {
|
|
|
|
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
|
|
|
|
dispatch_async(queue, ^{
|
|
|
|
for (id feed_id in appDelegate.dictSocialFeeds) {
|
|
|
|
NSDictionary *feed = [appDelegate.dictSocialFeeds objectForKey:feed_id];
|
2012-07-11 10:33:39 -07:00
|
|
|
NSURL *imageURL = [NSURL URLWithString:[feed objectForKey:@"photo_url"]];
|
2012-06-26 11:45:42 -07:00
|
|
|
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
|
|
|
|
UIImage *faviconImage = [UIImage imageWithData:imageData];
|
2012-07-02 10:45:25 -07:00
|
|
|
|
|
|
|
faviconImage = [self roundCorneredImage:faviconImage radius:6];
|
|
|
|
|
2012-06-26 11:45:42 -07:00
|
|
|
[Utilities saveImage:faviconImage feedId:feed_id];
|
|
|
|
}
|
|
|
|
|
|
|
|
[Utilities saveimagesToDisk];
|
|
|
|
|
|
|
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
|
|
[self.feedTitlesTable reloadData];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-07-02 10:45:25 -07:00
|
|
|
- (UIImage *)roundCorneredImage: (UIImage*) orig radius:(CGFloat) r {
|
|
|
|
UIGraphicsBeginImageContextWithOptions(orig.size, NO, 0);
|
|
|
|
[[UIBezierPath bezierPathWithRoundedRect:(CGRect){CGPointZero, orig.size}
|
|
|
|
cornerRadius:r] addClip];
|
|
|
|
[orig drawInRect:(CGRect){CGPointZero, orig.size}];
|
|
|
|
UIImage* result = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
|
UIGraphicsEndImageContext();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2011-08-04 17:58:28 -07:00
|
|
|
- (void)saveAndDrawFavicons:(ASIHTTPRequest *)request {
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
initWithDictionary:[responseString JSONValue]];
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2011-10-18 08:56:13 -07:00
|
|
|
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
|
|
|
|
dispatch_async(queue, ^{
|
|
|
|
for (id feed_id in results) {
|
|
|
|
NSDictionary *feed = [appDelegate.dictFeeds objectForKey:feed_id];
|
|
|
|
[feed setValue:[results objectForKey:feed_id] forKey:@"favicon"];
|
|
|
|
[appDelegate.dictFeeds setValue:feed forKey:feed_id];
|
|
|
|
|
|
|
|
NSString *favicon = [feed objectForKey:@"favicon"];
|
|
|
|
if ((NSNull *)favicon != [NSNull null] && [favicon length] > 0) {
|
|
|
|
NSData *imageData = [NSData dataWithBase64EncodedString:favicon];
|
|
|
|
UIImage *faviconImage = [UIImage imageWithData:imageData];
|
|
|
|
[Utilities saveImage:faviconImage feedId:feed_id];
|
|
|
|
}
|
2011-10-14 16:35:40 -07:00
|
|
|
}
|
2011-10-18 08:56:13 -07:00
|
|
|
[Utilities saveimagesToDisk];
|
|
|
|
|
|
|
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
|
|
[results release];
|
|
|
|
[self.feedTitlesTable reloadData];
|
|
|
|
});
|
|
|
|
});
|
2011-08-24 21:44:16 -07:00
|
|
|
|
2011-08-04 17:58:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request {
|
|
|
|
NSError *error = [request error];
|
|
|
|
NSLog(@"Error: %@", error);
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark PullToRefresh
|
|
|
|
|
|
|
|
// called when the user pulls-to-refresh
|
|
|
|
- (void)pullToRefreshViewShouldRefresh:(PullToRefreshView *)view {
|
2012-07-02 11:42:06 -07:00
|
|
|
[self refreshFeedList];
|
|
|
|
}
|
|
|
|
|
2012-06-29 17:37:49 -07:00
|
|
|
|
2012-07-02 11:42:06 -07:00
|
|
|
- (void)refreshFeedList {
|
2012-06-29 17:37:49 -07:00
|
|
|
// refresh the feed
|
|
|
|
NSURL *urlFeedList = [NSURL URLWithString:
|
|
|
|
[NSString stringWithFormat:@"http://%@/reader/refresh_feeds",
|
|
|
|
NEWSBLUR_URL]];
|
|
|
|
|
|
|
|
ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:urlFeedList];
|
|
|
|
[[NSHTTPCookieStorage sharedHTTPCookieStorage]
|
|
|
|
setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request setResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDidFinishSelector:@selector(finishRefreshingFeedList:)];
|
|
|
|
[request setDidFailSelector:@selector(requestFailed:)];
|
|
|
|
[request setTimeOutSeconds:30];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishRefreshingFeedList:(ASIHTTPRequest *)request {
|
2012-07-02 11:42:06 -07:00
|
|
|
[self fetchFeedList:NO refreshFeeds:NO];
|
2011-08-04 17:58:28 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// called when the date shown needs to be updated, optional
|
|
|
|
- (NSDate *)pullToRefreshViewLastUpdated:(PullToRefreshView *)view {
|
2011-08-24 21:44:16 -07:00
|
|
|
return self.lastUpdate;
|
2011-08-04 17:58:28 -07:00
|
|
|
}
|
|
|
|
|
2012-06-29 17:37:49 -07:00
|
|
|
@end
|