2010-06-21 17:17:26 -04:00
|
|
|
//
|
|
|
|
// FeedDetailViewController.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 6/20/10.
|
|
|
|
// Copyright 2010 NewsBlur. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2011-10-26 08:40:31 -07:00
|
|
|
#import <QuartzCore/QuartzCore.h>
|
2010-06-21 17:17:26 -04:00
|
|
|
#import "FeedDetailViewController.h"
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2010-07-15 00:44:38 -04:00
|
|
|
#import "FeedDetailTableCell.h"
|
2011-08-18 09:56:52 -07:00
|
|
|
#import "PullToRefreshView.h"
|
2011-07-24 22:23:38 -07:00
|
|
|
#import "ASIFormDataRequest.h"
|
2011-08-08 09:58:15 -07:00
|
|
|
#import "NSString+HTML.h"
|
2011-10-17 09:28:15 -07:00
|
|
|
#import "MBProgressHUD.h"
|
2011-09-05 22:06:31 -07:00
|
|
|
#import "Base64.h"
|
2010-06-24 00:22:26 -04:00
|
|
|
#import "JSON.h"
|
2011-10-26 08:40:31 -07:00
|
|
|
#import "StringHelper.h"
|
2011-10-17 09:37:16 -07:00
|
|
|
#import "Utilities.h"
|
2010-06-21 17:17:26 -04:00
|
|
|
|
2011-08-03 10:00:41 -07:00
|
|
|
#define kTableViewRowHeight 65;
|
2011-10-26 09:40:04 -07:00
|
|
|
#define kTableViewRiverRowHeight 81;
|
2011-11-05 16:25:04 -07:00
|
|
|
#define kMarkReadActionSheet 1;
|
|
|
|
#define kSettingsActionSheet 2;
|
2010-06-21 17:17:26 -04:00
|
|
|
|
|
|
|
@implementation FeedDetailViewController
|
|
|
|
|
2010-11-22 10:44:52 -05:00
|
|
|
@synthesize storyTitlesTable, feedViewToolbar, feedScoreSlider, feedMarkReadButton;
|
2011-12-05 10:42:25 -08:00
|
|
|
@synthesize settingsButton;
|
2010-06-24 00:22:26 -04:00
|
|
|
@synthesize stories;
|
2010-06-21 17:17:26 -04:00
|
|
|
@synthesize appDelegate;
|
2011-07-20 22:21:11 -07:00
|
|
|
@synthesize feedPage;
|
|
|
|
@synthesize pageFetching;
|
2011-08-21 13:46:43 -07:00
|
|
|
@synthesize pageRefreshing;
|
2011-07-24 16:52:24 -07:00
|
|
|
@synthesize pageFinished;
|
2011-07-29 09:06:17 -07:00
|
|
|
@synthesize intelligenceControl;
|
2011-08-18 09:56:52 -07:00
|
|
|
@synthesize pull;
|
2010-06-21 17:17:26 -04:00
|
|
|
|
|
|
|
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
|
|
|
|
|
2011-03-09 18:23:55 -05:00
|
|
|
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2011-10-05 10:07:26 -07:00
|
|
|
- (void)viewDidLoad {
|
2011-08-18 09:56:52 -07:00
|
|
|
pull = [[PullToRefreshView alloc] initWithScrollView:self.storyTitlesTable];
|
|
|
|
[pull setDelegate:self];
|
|
|
|
[self.storyTitlesTable addSubview:pull];
|
2011-08-25 12:09:41 -07:00
|
|
|
|
2011-08-18 09:56:52 -07:00
|
|
|
[super viewDidLoad];
|
|
|
|
}
|
|
|
|
|
2010-06-24 12:53:50 -04:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
2011-07-24 16:52:24 -07:00
|
|
|
self.pageFinished = NO;
|
2011-10-17 09:28:15 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
2011-08-24 10:24:02 -07:00
|
|
|
|
2011-10-26 10:12:36 -07:00
|
|
|
if (appDelegate.isRiverView) {
|
2011-10-30 18:53:10 -07:00
|
|
|
self.storyTitlesTable.separatorStyle = UITableViewCellSeparatorStyleNone;
|
|
|
|
self.storyTitlesTable.separatorColor = [UIColor clearColor];
|
2011-10-26 10:12:36 -07:00
|
|
|
} else {
|
2011-10-30 18:53:10 -07:00
|
|
|
self.storyTitlesTable.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
|
|
|
|
self.storyTitlesTable.separatorColor = [UIColor colorWithRed:.9 green:.9 blue:.9 alpha:1.0];
|
2011-10-26 10:12:36 -07:00
|
|
|
}
|
2011-08-24 10:24:02 -07:00
|
|
|
|
2011-12-02 16:23:00 -08:00
|
|
|
UIView *titleLabel = [appDelegate makeFeedTitle:appDelegate.activeFeed];
|
2011-08-24 19:36:03 -07:00
|
|
|
self.navigationItem.titleView = titleLabel;
|
2011-10-15 18:43:03 -07:00
|
|
|
|
|
|
|
// Commenting out until training is ready...
|
|
|
|
// UIBarButtonItem *trainBarButton = [UIBarButtonItem alloc];
|
|
|
|
// [trainBarButton setImage:[UIImage imageNamed:@"train.png"]];
|
|
|
|
// [trainBarButton setEnabled:YES];
|
|
|
|
// [self.navigationItem setRightBarButtonItem:trainBarButton animated:YES];
|
|
|
|
// [trainBarButton release];
|
2011-07-24 21:47:58 -07:00
|
|
|
|
|
|
|
NSMutableArray *indexPaths = [NSMutableArray array];
|
|
|
|
for (id i in appDelegate.recentlyReadStories) {
|
|
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[i intValue]
|
|
|
|
inSection:0];
|
2011-08-16 19:55:44 -07:00
|
|
|
// NSLog(@"Read story: %d", [i intValue]);
|
2011-07-24 21:47:58 -07:00
|
|
|
[indexPaths addObject:indexPath];
|
|
|
|
}
|
|
|
|
if ([indexPaths count] > 0) {
|
|
|
|
[self.storyTitlesTable beginUpdates];
|
|
|
|
[self.storyTitlesTable reloadRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
[self.storyTitlesTable endUpdates];
|
|
|
|
}
|
2011-08-08 09:58:15 -07:00
|
|
|
[appDelegate setRecentlyReadStories:[NSMutableArray array]];
|
2011-07-29 09:06:17 -07:00
|
|
|
[self.intelligenceControl setImage:[UIImage imageNamed:@"bullet_red.png"] forSegmentAtIndex:0];
|
|
|
|
[self.intelligenceControl setImage:[UIImage imageNamed:@"bullet_yellow.png"] forSegmentAtIndex:1];
|
|
|
|
[self.intelligenceControl setImage:[UIImage imageNamed:@"bullet_green.png"] forSegmentAtIndex:2];
|
|
|
|
[self.intelligenceControl addTarget:self
|
|
|
|
action:@selector(selectIntelligence)
|
|
|
|
forControlEvents:UIControlEventValueChanged];
|
|
|
|
[self.intelligenceControl setSelectedSegmentIndex:[appDelegate selectedIntelligence]+1];
|
2011-10-30 18:53:10 -07:00
|
|
|
|
2010-06-24 12:53:50 -04:00
|
|
|
[super viewWillAppear:animated];
|
2011-12-01 19:03:26 -08:00
|
|
|
|
|
|
|
BOOL pullFound = NO;
|
|
|
|
for (UIView *view in self.storyTitlesTable.subviews) {
|
|
|
|
if ([view isKindOfClass:[PullToRefreshView class]]) {
|
|
|
|
pullFound = YES;
|
|
|
|
if (appDelegate.isRiverView) {
|
|
|
|
[view removeFromSuperview];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!appDelegate.isRiverView && !pullFound) {
|
|
|
|
[self.storyTitlesTable addSubview:pull];
|
|
|
|
}
|
2011-12-05 10:42:25 -08:00
|
|
|
|
|
|
|
if (appDelegate.isRiverView && [appDelegate.activeFolder isEqualToString:@"Everything"]) {
|
|
|
|
settingsButton.enabled = NO;
|
|
|
|
} else {
|
|
|
|
settingsButton.enabled = YES;
|
|
|
|
}
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
2011-09-05 22:06:31 -07:00
|
|
|
// [[storyTitlesTable cellForRowAtIndexPath:[storyTitlesTable indexPathForSelectedRow]] setSelected:NO]; // TODO: DESELECT CELL --- done, see line below:
|
|
|
|
[self.storyTitlesTable deselectRowAtIndexPath:[storyTitlesTable indexPathForSelectedRow] animated:YES];
|
2011-12-01 19:19:24 -08:00
|
|
|
[pull refreshLastUpdatedDate];
|
2011-10-05 10:07:26 -07:00
|
|
|
|
2010-06-21 17:17:26 -04:00
|
|
|
[super viewDidAppear:animated];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc {
|
2011-08-01 09:43:13 -07:00
|
|
|
[storyTitlesTable release];
|
|
|
|
[feedViewToolbar release];
|
|
|
|
[feedScoreSlider release];
|
|
|
|
[feedMarkReadButton release];
|
2011-12-05 10:42:25 -08:00
|
|
|
[settingsButton release];
|
2010-06-24 00:22:26 -04:00
|
|
|
[stories release];
|
2011-08-01 09:43:13 -07:00
|
|
|
[appDelegate release];
|
2011-07-29 09:06:17 -07:00
|
|
|
[intelligenceControl release];
|
2011-08-18 09:56:52 -07:00
|
|
|
[pull release];
|
2010-06-21 17:17:26 -04:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
2010-06-24 00:22:26 -04:00
|
|
|
#pragma mark Initialization
|
|
|
|
|
2011-09-06 17:51:02 -07:00
|
|
|
- (void)resetFeedDetail {
|
|
|
|
self.pageFetching = NO;
|
|
|
|
self.pageFinished = NO;
|
|
|
|
self.pageRefreshing = NO;
|
|
|
|
self.feedPage = 1;
|
|
|
|
}
|
|
|
|
|
2011-09-05 22:06:31 -07:00
|
|
|
- (void)fetchNextPage:(void(^)())callback {
|
|
|
|
[self fetchFeedDetail:self.feedPage+1 withCallback:callback];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)fetchFeedDetail:(int)page withCallback:(void(^)())callback {
|
2011-07-24 16:52:24 -07:00
|
|
|
if ([appDelegate.activeFeed objectForKey:@"id"] != nil && !self.pageFetching && !self.pageFinished) {
|
2011-07-20 22:21:11 -07:00
|
|
|
self.feedPage = page;
|
|
|
|
self.pageFetching = YES;
|
2011-07-24 16:52:24 -07:00
|
|
|
int storyCount = appDelegate.storyCount;
|
|
|
|
if (storyCount == 0) {
|
|
|
|
[self.storyTitlesTable reloadData];
|
2011-07-22 09:10:13 -07:00
|
|
|
[storyTitlesTable scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
|
|
|
|
}
|
2011-07-20 21:08:57 -07:00
|
|
|
|
2011-08-24 10:24:02 -07:00
|
|
|
NSString *theFeedDetailURL = [NSString stringWithFormat:@"http://%@/reader/feed/%@?page=%d",
|
|
|
|
NEWSBLUR_URL,
|
2011-07-20 22:21:11 -07:00
|
|
|
[appDelegate.activeFeed objectForKey:@"id"],
|
|
|
|
self.feedPage];
|
2011-11-30 09:38:31 -08:00
|
|
|
|
|
|
|
[self cancelRequests];
|
|
|
|
__block ASIHTTPRequest *request = [self requestWithURL:theFeedDetailURL];
|
2011-09-05 22:06:31 -07:00
|
|
|
[request setDelegate:self];
|
|
|
|
[request setResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setFailedBlock:^(void) {
|
2011-11-30 09:38:31 -08:00
|
|
|
[self informError:[request error]];
|
2011-09-05 22:06:31 -07:00
|
|
|
}];
|
|
|
|
[request setCompletionBlock:^(void) {
|
|
|
|
[self finishedLoadingFeed:request];
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
[request setTimeOutSeconds:30];
|
|
|
|
[request setTag:[[[appDelegate activeFeed] objectForKey:@"id"] intValue]];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
2010-07-15 23:32:37 -04:00
|
|
|
}
|
|
|
|
|
2011-09-05 22:06:31 -07:00
|
|
|
- (void)finishedLoadingFeed:(ASIHTTPRequest *)request {
|
2011-11-30 09:38:31 -08:00
|
|
|
if ([request responseStatusCode] >= 500) {
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.15 * NSEC_PER_SEC),
|
|
|
|
dispatch_get_current_queue(), ^{
|
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
|
|
|
});
|
|
|
|
[self informError:@"The server barfed!"];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-09-05 22:06:31 -07:00
|
|
|
NSString *responseString = [request responseString];
|
2010-06-24 12:53:50 -04:00
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
2011-09-05 22:06:31 -07:00
|
|
|
initWithDictionary:[responseString JSONValue]];
|
2011-10-26 20:09:28 -07:00
|
|
|
if (!appDelegate.isRiverView && request.tag != [[results objectForKey:@"feed_id"] intValue]) {
|
|
|
|
[results release];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
[pull finishedLoading];
|
|
|
|
NSArray *newStories = [results objectForKey:@"stories"];
|
|
|
|
NSMutableArray *confirmedNewStories = [NSMutableArray array];
|
|
|
|
if ([appDelegate.activeFeedStories count]) {
|
|
|
|
NSMutableSet *storyIds = [NSMutableSet set];
|
|
|
|
for (id story in appDelegate.activeFeedStories) {
|
|
|
|
[storyIds addObject:[story objectForKey:@"id"]];
|
|
|
|
}
|
|
|
|
for (id story in newStories) {
|
|
|
|
if (![storyIds containsObject:[story objectForKey:@"id"]]) {
|
|
|
|
[confirmedNewStories addObject:story];
|
2011-10-26 09:05:59 -07:00
|
|
|
}
|
|
|
|
}
|
2011-10-26 20:09:28 -07:00
|
|
|
} else {
|
|
|
|
confirmedNewStories = [[newStories copy] autorelease];
|
2011-09-06 17:51:02 -07:00
|
|
|
}
|
2011-10-26 20:09:28 -07:00
|
|
|
[self renderStories:confirmedNewStories];
|
2011-09-06 17:51:02 -07:00
|
|
|
|
2011-08-21 13:46:43 -07:00
|
|
|
[results release];
|
|
|
|
}
|
|
|
|
|
2011-10-25 09:47:55 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark River of News
|
|
|
|
|
|
|
|
- (void)fetchRiverPage:(int)page withCallback:(void(^)())callback {
|
2011-10-26 08:40:31 -07:00
|
|
|
if (!self.pageFetching && !self.pageFinished) {
|
2011-10-25 09:47:55 -07:00
|
|
|
self.feedPage = page;
|
|
|
|
self.pageFetching = YES;
|
|
|
|
int storyCount = appDelegate.storyCount;
|
|
|
|
if (storyCount == 0) {
|
|
|
|
[self.storyTitlesTable reloadData];
|
|
|
|
[storyTitlesTable scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
|
|
|
|
}
|
2011-10-26 09:05:59 -07:00
|
|
|
int readStoriesCount = 0;
|
|
|
|
if (self.feedPage > 1) {
|
|
|
|
for (id story in appDelegate.activeFeedStories) {
|
|
|
|
if ([[story objectForKey:@"read_status"] intValue] == 1) {
|
|
|
|
readStoriesCount += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-10-25 09:47:55 -07:00
|
|
|
|
2011-10-26 09:05:59 -07:00
|
|
|
NSString *theFeedDetailURL = [NSString stringWithFormat:@"http://%@/reader/river_stories/?feeds=%@&page=%d&read_stories_count=%d",
|
2011-10-25 09:47:55 -07:00
|
|
|
NEWSBLUR_URL,
|
2011-10-26 08:40:31 -07:00
|
|
|
[appDelegate.activeFolderFeeds componentsJoinedByString:@"&feeds="],
|
2011-10-26 09:05:59 -07:00
|
|
|
self.feedPage,
|
|
|
|
readStoriesCount];
|
2011-10-25 09:47:55 -07:00
|
|
|
|
2011-11-30 09:38:31 -08:00
|
|
|
[self cancelRequests];
|
|
|
|
__block ASIHTTPRequest *request = [self requestWithURL:theFeedDetailURL];
|
2011-10-25 09:47:55 -07:00
|
|
|
[request setDelegate:self];
|
|
|
|
[request setResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setFailedBlock:^(void) {
|
2011-11-30 09:38:31 -08:00
|
|
|
[self informError:[request error]];
|
2011-10-25 09:47:55 -07:00
|
|
|
}];
|
|
|
|
[request setCompletionBlock:^(void) {
|
|
|
|
[self finishedLoadingFeed:request];
|
|
|
|
if (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
[request setTimeOutSeconds:30];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Stories
|
|
|
|
|
2011-08-21 13:46:43 -07:00
|
|
|
- (void)renderStories:(NSArray *)newStories {
|
2011-07-29 21:27:37 -07:00
|
|
|
NSInteger existingStoriesCount = [[appDelegate activeFeedStoryLocations] count];
|
2011-08-09 17:58:43 -07:00
|
|
|
NSInteger newStoriesCount = [newStories count];
|
2011-07-22 09:10:13 -07:00
|
|
|
|
2011-07-20 22:21:11 -07:00
|
|
|
if (self.feedPage == 1) {
|
2011-07-24 16:52:24 -07:00
|
|
|
[appDelegate setStories:newStories];
|
2011-08-09 17:58:43 -07:00
|
|
|
} else if (newStoriesCount > 0) {
|
2011-07-24 16:52:24 -07:00
|
|
|
[appDelegate addStories:newStories];
|
2011-07-22 09:10:13 -07:00
|
|
|
}
|
2011-07-24 16:52:24 -07:00
|
|
|
|
2011-08-09 17:58:43 -07:00
|
|
|
NSInteger newVisibleStoriesCount = [[appDelegate activeFeedStoryLocations] count] - existingStoriesCount;
|
2011-07-29 21:27:37 -07:00
|
|
|
|
2011-08-16 19:55:44 -07:00
|
|
|
// NSLog(@"Paging: %d/%d", existingStoriesCount, [appDelegate unreadCount]);
|
2011-08-09 17:58:43 -07:00
|
|
|
|
|
|
|
if (existingStoriesCount > 0 && newVisibleStoriesCount > 0) {
|
2011-07-24 16:52:24 -07:00
|
|
|
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
|
2011-08-09 17:58:43 -07:00
|
|
|
for (int i=0; i < newVisibleStoriesCount; i++) {
|
2011-07-29 21:56:54 -07:00
|
|
|
[indexPaths addObject:[NSIndexPath indexPathForRow:(existingStoriesCount+i)
|
|
|
|
inSection:0]];
|
2011-07-22 09:10:13 -07:00
|
|
|
}
|
2011-07-29 21:56:54 -07:00
|
|
|
[self.storyTitlesTable beginUpdates];
|
2011-07-24 16:52:24 -07:00
|
|
|
[self.storyTitlesTable insertRowsAtIndexPaths:indexPaths
|
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
2011-07-29 21:56:54 -07:00
|
|
|
[self.storyTitlesTable endUpdates];
|
2011-07-22 09:10:13 -07:00
|
|
|
[indexPaths release];
|
2011-08-09 17:58:43 -07:00
|
|
|
} else if (newVisibleStoriesCount > 0) {
|
2011-07-22 09:10:13 -07:00
|
|
|
[self.storyTitlesTable reloadData];
|
2011-08-09 17:58:43 -07:00
|
|
|
} else if (newStoriesCount == 0 ||
|
|
|
|
(self.feedPage > 15 &&
|
|
|
|
existingStoriesCount >= [appDelegate unreadCount])) {
|
2011-07-24 16:52:24 -07:00
|
|
|
self.pageFinished = YES;
|
2011-07-24 17:18:05 -07:00
|
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:existingStoriesCount
|
2011-07-24 16:52:24 -07:00
|
|
|
inSection:0];
|
2011-07-24 17:18:05 -07:00
|
|
|
NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
|
|
|
|
[self.storyTitlesTable beginUpdates];
|
2011-07-29 21:56:54 -07:00
|
|
|
[self.storyTitlesTable reloadRowsAtIndexPaths:indexPaths
|
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
2011-07-24 17:18:05 -07:00
|
|
|
[self.storyTitlesTable endUpdates];
|
2011-07-20 22:21:11 -07:00
|
|
|
}
|
2011-07-24 16:52:24 -07:00
|
|
|
|
2011-07-20 22:21:11 -07:00
|
|
|
self.pageFetching = NO;
|
2011-07-24 16:52:24 -07:00
|
|
|
|
2011-07-29 21:56:54 -07:00
|
|
|
[self performSelector:@selector(checkScroll)
|
|
|
|
withObject:nil
|
2011-08-13 23:00:51 -07:00
|
|
|
afterDelay:0.2];
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
|
2011-07-24 20:34:54 -07:00
|
|
|
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
|
2010-07-15 23:32:37 -04:00
|
|
|
[connection release];
|
|
|
|
|
|
|
|
// inform the user
|
2010-11-15 19:40:17 -05:00
|
|
|
NSLog(@"Connection failed! Error - %@",
|
|
|
|
[error localizedDescription]);
|
2011-07-20 22:21:11 -07:00
|
|
|
|
|
|
|
self.pageFetching = NO;
|
2011-08-18 09:56:52 -07:00
|
|
|
|
|
|
|
// User clicking on another link before the page loads is OK.
|
|
|
|
if ([error code] != NSURLErrorCancelled) {
|
2011-10-27 09:44:58 -07:00
|
|
|
[self informError:error];
|
2011-08-18 09:56:52 -07:00
|
|
|
}
|
2010-07-15 23:32:37 -04:00
|
|
|
}
|
|
|
|
|
2011-07-24 16:52:24 -07:00
|
|
|
- (UITableViewCell *)makeLoadingCell {
|
2011-07-24 20:34:54 -07:00
|
|
|
UITableViewCell *cell = [[[UITableViewCell alloc]
|
|
|
|
initWithStyle:UITableViewCellStyleSubtitle
|
|
|
|
reuseIdentifier:@"NoReuse"] autorelease];
|
2011-07-24 16:52:24 -07:00
|
|
|
|
2011-07-24 17:18:05 -07:00
|
|
|
cell.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
|
2011-07-24 16:52:24 -07:00
|
|
|
if (self.pageFinished) {
|
2011-07-24 17:18:05 -07:00
|
|
|
UIView * blue = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 321, 17)];
|
|
|
|
[cell.contentView addSubview:blue];
|
|
|
|
blue.backgroundColor = [UIColor whiteColor];
|
|
|
|
[UIView beginAnimations:nil context:NULL];
|
|
|
|
[UIView setAnimationDuration:0.5f];
|
|
|
|
blue.backgroundColor = [UIColor colorWithRed:.7f green:0.7f blue:0.7f alpha:1.0f];
|
|
|
|
[UIView commitAnimations];
|
|
|
|
[blue release];
|
2011-07-24 16:52:24 -07:00
|
|
|
} else {
|
|
|
|
cell.textLabel.text = @"Loading...";
|
|
|
|
|
|
|
|
UIActivityIndicatorView *spinner = [[[UIActivityIndicatorView alloc]
|
|
|
|
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray] autorelease];
|
|
|
|
UIImage *spacer = [UIImage imageNamed:@"spacer"];
|
2011-07-29 21:56:54 -07:00
|
|
|
UIGraphicsBeginImageContext(spinner.frame.size);
|
2011-07-24 16:52:24 -07:00
|
|
|
[spacer drawInRect:CGRectMake(0,0,spinner.frame.size.width,spinner.frame.size.height)];
|
|
|
|
UIImage* resizedSpacer = UIGraphicsGetImageFromCurrentImageContext();
|
|
|
|
UIGraphicsEndImageContext();
|
|
|
|
cell.imageView.image = resizedSpacer;
|
|
|
|
[cell.imageView addSubview:spinner];
|
|
|
|
[spinner startAnimating];
|
|
|
|
}
|
|
|
|
|
|
|
|
return cell;
|
|
|
|
}
|
2010-06-21 17:17:26 -04:00
|
|
|
|
2010-06-24 00:22:26 -04:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Table View - Feed List
|
2010-06-21 17:17:26 -04:00
|
|
|
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
2011-08-21 13:46:43 -07:00
|
|
|
if (self.pageRefreshing) {
|
|
|
|
// Refreshing feed
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
int storyCount = [[appDelegate activeFeedStoryLocations] count];
|
|
|
|
|
|
|
|
// The +1 is for the finished/loading bar.
|
|
|
|
return storyCount + 1;
|
|
|
|
}
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
|
2011-08-13 17:08:26 -07:00
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView
|
|
|
|
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2011-10-25 09:28:05 -07:00
|
|
|
static NSString *cellIdentifier;
|
|
|
|
|
|
|
|
if (appDelegate.isRiverView) {
|
2011-10-26 20:09:28 -07:00
|
|
|
cellIdentifier = @"FeedRiverDetailCellIdentifier";
|
2011-10-25 09:28:05 -07:00
|
|
|
} else {
|
|
|
|
cellIdentifier = @"FeedDetailCellIdentifier";
|
|
|
|
}
|
|
|
|
|
|
|
|
FeedDetailTableCell *cell = (FeedDetailTableCell *)[tableView
|
|
|
|
dequeueReusableCellWithIdentifier:cellIdentifier];
|
2010-06-21 17:17:26 -04:00
|
|
|
if (cell == nil) {
|
2010-07-15 00:44:38 -04:00
|
|
|
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"FeedDetailTableCell"
|
|
|
|
owner:self
|
|
|
|
options:nil];
|
|
|
|
for (id oneObject in nib) {
|
|
|
|
if ([oneObject isKindOfClass:[FeedDetailTableCell class]]) {
|
2011-10-25 09:28:05 -07:00
|
|
|
if (([(FeedDetailTableCell *)oneObject tag] == 0 && !appDelegate.isRiverView) ||
|
|
|
|
([(FeedDetailTableCell *)oneObject tag] == 1 && appDelegate.isRiverView)) {
|
|
|
|
cell = (FeedDetailTableCell *)oneObject;
|
2011-10-30 16:32:34 -07:00
|
|
|
break;
|
2011-10-25 09:28:05 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 00:44:38 -04:00
|
|
|
}
|
|
|
|
}
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
2010-06-24 00:22:26 -04:00
|
|
|
|
2011-07-29 21:27:37 -07:00
|
|
|
if (indexPath.row >= [[appDelegate activeFeedStoryLocations] count]) {
|
2011-07-24 16:52:24 -07:00
|
|
|
return [self makeLoadingCell];
|
|
|
|
}
|
|
|
|
|
2011-07-29 09:06:17 -07:00
|
|
|
NSDictionary *story = [self getStoryAtRow:indexPath.row];
|
2011-10-26 20:09:28 -07:00
|
|
|
id feedId = [story objectForKey:@"story_feed_id"];
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
|
|
|
NSDictionary *feed = [appDelegate.dictFeeds objectForKey:feedIdStr];
|
|
|
|
|
2010-07-15 00:44:38 -04:00
|
|
|
if ([[story objectForKey:@"story_authors"] class] != [NSNull class]) {
|
2011-08-13 17:08:26 -07:00
|
|
|
cell.storyAuthor.text = [[story objectForKey:@"story_authors"]
|
|
|
|
uppercaseString];
|
2010-07-15 00:44:38 -04:00
|
|
|
} else {
|
|
|
|
cell.storyAuthor.text = @"";
|
|
|
|
}
|
2011-08-13 17:08:26 -07:00
|
|
|
|
2011-10-26 08:40:31 -07:00
|
|
|
BOOL isStoryRead = [[story objectForKey:@"read_status"] intValue] == 1;
|
2011-08-03 10:00:41 -07:00
|
|
|
NSString *title = [story objectForKey:@"story_title"];
|
2011-08-08 09:58:15 -07:00
|
|
|
cell.storyTitle.text = [title stringByDecodingHTMLEntities];
|
2011-06-13 10:44:17 -04:00
|
|
|
cell.storyDate.text = [story objectForKey:@"short_parsed_date"];
|
2011-07-24 20:34:54 -07:00
|
|
|
int score = [NewsBlurAppDelegate computeStoryScore:[story objectForKey:@"intelligence"]];
|
|
|
|
if (score > 0) {
|
|
|
|
cell.storyUnreadIndicator.image = [UIImage imageNamed:@"bullet_green.png"];
|
|
|
|
} else if (score == 0) {
|
|
|
|
cell.storyUnreadIndicator.image = [UIImage imageNamed:@"bullet_yellow.png"];
|
|
|
|
} else if (score < 0) {
|
|
|
|
cell.storyUnreadIndicator.image = [UIImage imageNamed:@"bullet_red.png"];
|
|
|
|
}
|
2010-11-22 10:44:52 -05:00
|
|
|
|
2011-10-25 09:28:05 -07:00
|
|
|
// River view
|
2011-10-30 16:32:34 -07:00
|
|
|
if (appDelegate.isRiverView && cell) {
|
2011-10-28 18:29:33 -07:00
|
|
|
UIView *gradientView = [appDelegate makeFeedTitleGradient:feed
|
2011-10-30 18:53:10 -07:00
|
|
|
withRect:CGRectMake(0, 0, cell.frame.size.width, 21)];
|
2011-10-27 19:05:38 -07:00
|
|
|
[cell.feedGradient addSubview:gradientView];
|
|
|
|
}
|
2011-10-28 18:29:33 -07:00
|
|
|
|
2011-10-26 08:40:31 -07:00
|
|
|
if (!isStoryRead) {
|
2010-11-22 10:44:52 -05:00
|
|
|
// Unread story
|
2011-07-20 21:08:57 -07:00
|
|
|
cell.storyTitle.textColor = [UIColor colorWithRed:0.1f green:0.1f blue:0.1f alpha:1.0];
|
2011-08-03 10:00:41 -07:00
|
|
|
cell.storyTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:13];
|
2011-07-20 21:08:57 -07:00
|
|
|
cell.storyAuthor.textColor = [UIColor colorWithRed:0.58f green:0.58f blue:0.58f alpha:1.0];
|
|
|
|
cell.storyAuthor.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
|
|
|
|
cell.storyDate.textColor = [UIColor colorWithRed:0.14f green:0.18f blue:0.42f alpha:1.0];
|
|
|
|
cell.storyDate.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
|
2011-07-24 20:34:54 -07:00
|
|
|
cell.storyUnreadIndicator.alpha = 1;
|
2010-11-22 10:44:52 -05:00
|
|
|
} else {
|
|
|
|
// Read story
|
2011-07-20 21:08:57 -07:00
|
|
|
cell.storyTitle.textColor = [UIColor colorWithRed:0.15f green:0.25f blue:0.25f alpha:0.9];
|
|
|
|
cell.storyTitle.font = [UIFont fontWithName:@"Helvetica" size:12];
|
|
|
|
cell.storyAuthor.textColor = [UIColor colorWithRed:0.58f green:0.58f blue:0.58f alpha:0.5];
|
|
|
|
cell.storyAuthor.font = [UIFont fontWithName:@"Helvetica-Bold" size:10];
|
|
|
|
cell.storyDate.textColor = [UIColor colorWithRed:0.14f green:0.18f blue:0.42f alpha:0.5];
|
|
|
|
cell.storyDate.font = [UIFont fontWithName:@"Helvetica" size:10];
|
2011-07-24 20:34:54 -07:00
|
|
|
cell.storyUnreadIndicator.alpha = 0.15f;
|
2011-10-28 18:29:33 -07:00
|
|
|
// cell.feedTitle.font = [UIFont fontWithName:@"Helvetica" size:11];
|
|
|
|
// cell.feedTitle.textColor = [UIColor blackColor];
|
|
|
|
// cell.feedTitle.shadowColor = nil;
|
|
|
|
// cell.feedFavicon.alpha = 0.5f;
|
2011-10-30 15:06:25 -07:00
|
|
|
cell.feedGradient.alpha = 0.25f;
|
2011-10-26 20:09:28 -07:00
|
|
|
}
|
2010-07-15 00:44:38 -04:00
|
|
|
|
2010-06-21 17:17:26 -04:00
|
|
|
return cell;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
2011-08-14 10:22:26 -07:00
|
|
|
if (indexPath.row < [appDelegate.activeFeedStoryLocations count]) {
|
2011-07-29 21:56:54 -07:00
|
|
|
int location = [[[appDelegate activeFeedStoryLocations] objectAtIndex:indexPath.row] intValue];
|
|
|
|
[appDelegate setActiveStory:[[appDelegate activeFeedStories] objectAtIndex:location]];
|
2011-08-09 17:58:43 -07:00
|
|
|
[appDelegate setOriginalStoryCount:[appDelegate unreadCount]];
|
2011-07-24 16:52:24 -07:00
|
|
|
[appDelegate loadStoryDetailView];
|
|
|
|
}
|
2010-06-21 17:17:26 -04:00
|
|
|
}
|
|
|
|
|
2010-07-15 00:44:38 -04:00
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
2011-07-29 21:27:37 -07:00
|
|
|
if (indexPath.row >= [[appDelegate activeFeedStoryLocations] count]) {
|
2011-07-29 09:06:17 -07:00
|
|
|
if (self.pageFinished) return 16;
|
|
|
|
else return kTableViewRowHeight;
|
2011-07-24 16:52:24 -07:00
|
|
|
} else {
|
2011-10-25 09:28:05 -07:00
|
|
|
if (appDelegate.isRiverView) {
|
|
|
|
return kTableViewRiverRowHeight;
|
|
|
|
} else {
|
|
|
|
return kTableViewRowHeight;
|
|
|
|
}
|
2011-07-24 16:52:24 -07:00
|
|
|
}
|
2010-07-15 00:44:38 -04:00
|
|
|
}
|
|
|
|
|
2011-07-20 22:21:11 -07:00
|
|
|
- (void)scrollViewDidScroll: (UIScrollView *)scroll {
|
2011-07-29 21:56:54 -07:00
|
|
|
[self checkScroll];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)checkScroll {
|
|
|
|
NSInteger currentOffset = self.storyTitlesTable.contentOffset.y;
|
|
|
|
NSInteger maximumOffset = self.storyTitlesTable.contentSize.height - self.storyTitlesTable.frame.size.height;
|
2011-07-20 22:21:11 -07:00
|
|
|
|
2011-07-24 20:34:54 -07:00
|
|
|
if (maximumOffset - currentOffset <= 60.0) {
|
2011-10-26 08:40:31 -07:00
|
|
|
if (appDelegate.isRiverView) {
|
|
|
|
[self fetchRiverPage:self.feedPage+1 withCallback:nil];
|
|
|
|
} else {
|
|
|
|
[self fetchFeedDetail:self.feedPage+1 withCallback:nil];
|
|
|
|
}
|
2011-07-20 22:21:11 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-07-29 09:06:17 -07:00
|
|
|
- (IBAction)selectIntelligence {
|
|
|
|
NSInteger newLevel = [self.intelligenceControl selectedSegmentIndex] - 1;
|
|
|
|
NSInteger previousLevel = [appDelegate selectedIntelligence];
|
|
|
|
NSMutableArray *insertIndexPaths = [NSMutableArray array];
|
|
|
|
NSMutableArray *deleteIndexPaths = [NSMutableArray array];
|
|
|
|
|
2011-08-02 09:16:54 -07:00
|
|
|
if (newLevel == previousLevel) return;
|
|
|
|
|
2011-07-29 21:27:37 -07:00
|
|
|
if (newLevel < previousLevel) {
|
|
|
|
[appDelegate setSelectedIntelligence:newLevel];
|
|
|
|
[appDelegate calculateStoryLocations];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i=0; i < [[appDelegate activeFeedStoryLocations] count]; i++) {
|
|
|
|
int location = [[[appDelegate activeFeedStoryLocations] objectAtIndex:i] intValue];
|
2011-07-29 09:06:17 -07:00
|
|
|
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
|
2011-07-29 21:27:37 -07:00
|
|
|
NSDictionary *story = [appDelegate.activeFeedStories objectAtIndex:location];
|
2011-07-29 09:06:17 -07:00
|
|
|
int score = [NewsBlurAppDelegate computeStoryScore:[story objectForKey:@"intelligence"]];
|
|
|
|
|
|
|
|
if (previousLevel == -1) {
|
|
|
|
if (newLevel == 0 && score == -1) {
|
|
|
|
[deleteIndexPaths addObject:indexPath];
|
|
|
|
} else if (newLevel == 1 && score < 1) {
|
|
|
|
[deleteIndexPaths addObject:indexPath];
|
|
|
|
}
|
|
|
|
} else if (previousLevel == 0) {
|
|
|
|
if (newLevel == -1 && score == -1) {
|
|
|
|
[insertIndexPaths addObject:indexPath];
|
|
|
|
} else if (newLevel == 1 && score == 0) {
|
|
|
|
[deleteIndexPaths addObject:indexPath];
|
|
|
|
}
|
|
|
|
} else if (previousLevel == 1) {
|
|
|
|
if (newLevel == 0 && score == 0) {
|
|
|
|
[insertIndexPaths addObject:indexPath];
|
|
|
|
} else if (newLevel == -1 && score < 1) {
|
|
|
|
[insertIndexPaths addObject:indexPath];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-07-29 21:27:37 -07:00
|
|
|
|
|
|
|
if (newLevel > previousLevel) {
|
|
|
|
[appDelegate setSelectedIntelligence:newLevel];
|
|
|
|
[appDelegate calculateStoryLocations];
|
|
|
|
}
|
|
|
|
|
2011-07-29 09:06:17 -07:00
|
|
|
[self.storyTitlesTable beginUpdates];
|
2011-07-29 21:27:37 -07:00
|
|
|
if ([deleteIndexPaths count] > 0) {
|
|
|
|
[self.storyTitlesTable deleteRowsAtIndexPaths:deleteIndexPaths
|
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
}
|
|
|
|
if ([insertIndexPaths count] > 0) {
|
|
|
|
[self.storyTitlesTable insertRowsAtIndexPaths:insertIndexPaths
|
|
|
|
withRowAnimation:UITableViewRowAnimationNone];
|
|
|
|
}
|
2011-07-29 09:06:17 -07:00
|
|
|
[self.storyTitlesTable endUpdates];
|
2011-07-29 21:56:54 -07:00
|
|
|
|
|
|
|
[self performSelector:@selector(checkScroll)
|
|
|
|
withObject:nil
|
|
|
|
afterDelay:1.0];
|
2011-07-29 09:06:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)getStoryAtRow:(NSInteger)indexPathRow {
|
2011-07-29 21:27:37 -07:00
|
|
|
int row = [[[appDelegate activeFeedStoryLocations] objectAtIndex:indexPathRow] intValue];
|
2011-07-29 09:06:17 -07:00
|
|
|
return [appDelegate.activeFeedStories objectAtIndex:row];
|
2011-07-24 22:23:38 -07:00
|
|
|
}
|
|
|
|
|
2011-10-17 09:28:15 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Feed Actions
|
|
|
|
|
2011-11-04 08:46:24 -07:00
|
|
|
|
2011-11-09 09:51:42 -08:00
|
|
|
- (void)markFeedsReadWithAllStories:(BOOL)includeHidden {
|
2011-11-29 17:57:20 -08:00
|
|
|
NSLog(@"mark feeds read: %d %d", appDelegate.isRiverView, includeHidden);
|
2011-11-09 09:51:42 -08:00
|
|
|
if (appDelegate.isRiverView && includeHidden) {
|
|
|
|
// Mark folder as read
|
2011-11-29 17:57:20 -08:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/mark_feed_as_read",
|
2011-11-09 09:51:42 -08:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2011-11-29 17:57:20 -08:00
|
|
|
for (id feed_id in [appDelegate.dictFolders objectForKey:appDelegate.activeFolder]) {
|
|
|
|
[request addPostValue:feed_id forKey:@"feed_id"];
|
|
|
|
}
|
2011-11-09 09:51:42 -08:00
|
|
|
[request setDelegate:nil];
|
|
|
|
[request startAsynchronous];
|
2011-11-10 18:28:22 -08:00
|
|
|
|
|
|
|
[appDelegate markActiveFolderAllRead];
|
2011-11-09 09:51:42 -08:00
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
|
|
|
} else if (!appDelegate.isRiverView && includeHidden) {
|
|
|
|
// Mark feed as read
|
2011-11-04 08:46:24 -07:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/mark_feed_as_read",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
|
|
|
[request setPostValue:[appDelegate.activeFeed objectForKey:@"id"] forKey:@"feed_id"];
|
|
|
|
[request setDelegate:nil];
|
|
|
|
[request startAsynchronous];
|
2011-11-10 18:28:22 -08:00
|
|
|
|
2011-11-04 08:46:24 -07:00
|
|
|
[appDelegate markActiveFeedAllRead];
|
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
2011-11-09 09:51:42 -08:00
|
|
|
} else {
|
|
|
|
// Mark visible stories as read
|
2011-11-10 18:28:22 -08:00
|
|
|
NSDictionary *feedsStories = [appDelegate markVisibleStoriesRead];
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"http://%@/reader/mark_feed_stories_as_read",
|
2011-11-09 09:51:42 -08:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2011-11-10 18:28:22 -08:00
|
|
|
[request setPostValue:[feedsStories JSONRepresentation] forKey:@"feeds_stories"];
|
2011-11-09 09:51:42 -08:00
|
|
|
[request setDelegate:nil];
|
|
|
|
[request startAsynchronous];
|
2011-11-10 18:28:22 -08:00
|
|
|
|
2011-11-09 09:51:42 -08:00
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
2011-11-04 08:46:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction)doOpenMarkReadActionSheet:(id)sender {
|
2011-11-29 17:57:20 -08:00
|
|
|
// Individual sites just get marked as read, no action sheet needed.
|
|
|
|
if (!appDelegate.isRiverView) {
|
|
|
|
[self markFeedsReadWithAllStories:YES];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-11-09 09:51:42 -08:00
|
|
|
NSString *title = appDelegate.isRiverView ?
|
|
|
|
appDelegate.activeFolder :
|
|
|
|
[appDelegate.activeFeed objectForKey:@"feed_title"];
|
2011-11-04 08:46:24 -07:00
|
|
|
UIActionSheet *options = [[UIActionSheet alloc]
|
2011-11-09 09:51:42 -08:00
|
|
|
initWithTitle:title
|
2011-11-04 08:46:24 -07:00
|
|
|
delegate:self
|
|
|
|
cancelButtonTitle:nil
|
|
|
|
destructiveButtonTitle:nil
|
|
|
|
otherButtonTitles:nil];
|
|
|
|
|
2011-11-09 09:51:42 -08:00
|
|
|
int visibleUnreadCount = appDelegate.visibleUnreadCount;
|
|
|
|
int totalUnreadCount = [appDelegate unreadCount];
|
|
|
|
NSArray *buttonTitles = nil;
|
2011-12-05 18:10:40 -08:00
|
|
|
BOOL showVisible = YES;
|
|
|
|
BOOL showEntire = YES;
|
|
|
|
if ([appDelegate.activeFolder isEqualToString:@"Everything"]) showEntire = NO;
|
|
|
|
if (visibleUnreadCount >= totalUnreadCount || visibleUnreadCount <= 0) showVisible = NO;
|
|
|
|
NSString *entireText = [NSString stringWithFormat:@"Mark %@ read",
|
|
|
|
appDelegate.isRiverView ?
|
|
|
|
@"entire folder" :
|
|
|
|
@"this site"];
|
|
|
|
NSString *visibleText = [NSString stringWithFormat:@"Mark %@ read",
|
|
|
|
visibleUnreadCount == 1 ? @"this story as" :
|
|
|
|
[NSString stringWithFormat:@"these %d stories",
|
|
|
|
visibleUnreadCount]];
|
|
|
|
if (showVisible && showEntire) {
|
2011-11-09 09:51:42 -08:00
|
|
|
buttonTitles = [NSArray arrayWithObjects:visibleText, entireText, nil];
|
|
|
|
options.destructiveButtonIndex = 1;
|
2011-12-05 18:10:40 -08:00
|
|
|
} else if (showVisible && !showEntire) {
|
|
|
|
buttonTitles = [NSArray arrayWithObjects:visibleText, nil];
|
|
|
|
options.destructiveButtonIndex = -1;
|
|
|
|
} else if (!showVisible && showEntire) {
|
|
|
|
buttonTitles = [NSArray arrayWithObjects:entireText, nil];
|
|
|
|
options.destructiveButtonIndex = 0;
|
2011-11-09 09:51:42 -08:00
|
|
|
}
|
|
|
|
|
2011-11-04 08:46:24 -07:00
|
|
|
for (id title in buttonTitles) {
|
|
|
|
[options addButtonWithTitle:title];
|
|
|
|
}
|
|
|
|
options.cancelButtonIndex = [options addButtonWithTitle:@"Cancel"];
|
|
|
|
|
2011-11-05 16:25:04 -07:00
|
|
|
options.tag = kMarkReadActionSheet;
|
2011-11-04 08:46:24 -07:00
|
|
|
[options showInView:self.view];
|
|
|
|
[options release];
|
|
|
|
}
|
|
|
|
|
2011-10-17 09:28:15 -07:00
|
|
|
- (IBAction)doOpenSettingsActionSheet {
|
2011-12-03 18:22:14 -08:00
|
|
|
NSString *title = appDelegate.isRiverView ?
|
|
|
|
appDelegate.activeFolder :
|
|
|
|
[appDelegate.activeFeed objectForKey:@"feed_title"];
|
2011-10-17 09:28:15 -07:00
|
|
|
UIActionSheet *options = [[UIActionSheet alloc]
|
2011-12-03 18:22:14 -08:00
|
|
|
initWithTitle:title
|
2011-10-17 09:28:15 -07:00
|
|
|
delegate:self
|
|
|
|
cancelButtonTitle:nil
|
|
|
|
destructiveButtonTitle:nil
|
|
|
|
otherButtonTitles:nil];
|
|
|
|
|
2011-12-03 18:22:14 -08:00
|
|
|
if (![title isEqualToString:@"Everything"]) {
|
|
|
|
NSString *deleteText = [NSString stringWithFormat:@"Delete %@",
|
|
|
|
appDelegate.isRiverView ?
|
|
|
|
@"this entire folder" :
|
|
|
|
@"this site"];
|
|
|
|
[options addButtonWithTitle:deleteText];
|
|
|
|
options.destructiveButtonIndex = 0;
|
|
|
|
|
|
|
|
NSString *moveText = @"Move to another folder";
|
|
|
|
[options addButtonWithTitle:moveText];
|
2011-10-17 09:28:15 -07:00
|
|
|
}
|
2011-11-09 09:51:42 -08:00
|
|
|
|
2011-12-03 18:22:14 -08:00
|
|
|
options.cancelButtonIndex = [options addButtonWithTitle:@"Cancel"];
|
2011-11-05 16:25:04 -07:00
|
|
|
options.tag = kSettingsActionSheet;
|
2011-10-17 09:28:15 -07:00
|
|
|
[options showInView:self.view];
|
|
|
|
[options release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
|
2011-12-03 18:22:14 -08:00
|
|
|
// NSLog(@"Action option #%d on %d", buttonIndex, actionSheet.tag);
|
2011-11-05 16:25:04 -07:00
|
|
|
if (actionSheet.tag == 1) {
|
2011-11-09 09:51:42 -08:00
|
|
|
int visibleUnreadCount = appDelegate.visibleUnreadCount;
|
|
|
|
int totalUnreadCount = [appDelegate unreadCount];
|
2011-12-05 18:10:40 -08:00
|
|
|
BOOL showVisible = YES;
|
|
|
|
BOOL showEntire = YES;
|
|
|
|
if ([appDelegate.activeFolder isEqualToString:@"Everything"]) showEntire = NO;
|
|
|
|
if (visibleUnreadCount >= totalUnreadCount || visibleUnreadCount <= 0) showVisible = NO;
|
2011-12-03 18:22:14 -08:00
|
|
|
// NSLog(@"Counts: %d %d = %d", visibleUnreadCount, totalUnreadCount, visibleUnreadCount >= totalUnreadCount || visibleUnreadCount <= 0);
|
2011-12-05 18:10:40 -08:00
|
|
|
|
|
|
|
if (showVisible && showEntire) {
|
2011-11-09 09:51:42 -08:00
|
|
|
if (buttonIndex == 0) {
|
2011-12-05 18:10:40 -08:00
|
|
|
if (buttonIndex == 0) {
|
|
|
|
[self markFeedsReadWithAllStories:NO];
|
|
|
|
} else if (buttonIndex == 1) {
|
|
|
|
[self markFeedsReadWithAllStories:YES];
|
|
|
|
}
|
2011-11-09 09:51:42 -08:00
|
|
|
}
|
2011-12-05 18:10:40 -08:00
|
|
|
} else if (showVisible && !showEntire) {
|
2011-11-09 09:51:42 -08:00
|
|
|
if (buttonIndex == 0) {
|
|
|
|
[self markFeedsReadWithAllStories:NO];
|
2011-12-05 18:10:40 -08:00
|
|
|
}
|
|
|
|
} else if (!showVisible && showEntire) {
|
|
|
|
if (buttonIndex == 0) {
|
2011-11-09 09:51:42 -08:00
|
|
|
[self markFeedsReadWithAllStories:YES];
|
2011-12-05 18:10:40 -08:00
|
|
|
}
|
2011-11-09 09:51:42 -08:00
|
|
|
}
|
2011-11-05 16:25:04 -07:00
|
|
|
} else if (actionSheet.tag == 2) {
|
|
|
|
if (buttonIndex == 0) {
|
|
|
|
[self confirmDeleteSite];
|
2011-12-03 18:22:14 -08:00
|
|
|
} else if (buttonIndex == 1) {
|
|
|
|
[self openMoveView];
|
2011-11-05 16:25:04 -07:00
|
|
|
}
|
2011-10-17 09:28:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)confirmDeleteSite {
|
|
|
|
UIAlertView *deleteConfirm = [[UIAlertView alloc] initWithTitle:@"Positive?" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Delete", nil];
|
|
|
|
[deleteConfirm show];
|
|
|
|
[deleteConfirm setTag:0];
|
|
|
|
[deleteConfirm release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
|
|
|
|
if (alertView.tag == 0) {
|
|
|
|
if (buttonIndex == 0) {
|
|
|
|
return;
|
|
|
|
} else {
|
2011-12-05 09:26:02 -08:00
|
|
|
if (appDelegate.isRiverView) {
|
|
|
|
[self deleteFolder];
|
|
|
|
} else {
|
|
|
|
[self deleteSite];
|
|
|
|
}
|
2011-10-17 09:28:15 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)deleteSite {
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
|
HUD.labelText = @"Deleting...";
|
2011-10-20 09:32:39 -07:00
|
|
|
|
|
|
|
NSString *theFeedDetailURL = [NSString stringWithFormat:@"http://%@/reader/delete_feed",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *urlFeedDetail = [NSURL URLWithString:theFeedDetailURL];
|
|
|
|
|
|
|
|
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlFeedDetail];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request addPostValue:[[appDelegate activeFeed] objectForKey:@"id"] forKey:@"feed_id"];
|
2011-12-04 21:09:16 -08:00
|
|
|
[request addPostValue:[appDelegate extractFolderName:appDelegate.activeFolder] forKey:@"in_folder"];
|
2011-10-20 09:32:39 -07:00
|
|
|
[request setFailedBlock:^(void) {
|
2011-11-30 09:38:31 -08:00
|
|
|
[self informError:[request error]];
|
2011-10-20 09:32:39 -07:00
|
|
|
}];
|
|
|
|
[request setCompletionBlock:^(void) {
|
2011-12-03 18:22:14 -08:00
|
|
|
[appDelegate reloadFeedsView:YES];
|
2011-10-20 09:32:39 -07:00
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
}];
|
|
|
|
[request setTimeOutSeconds:30];
|
|
|
|
[request setTag:[[[appDelegate activeFeed] objectForKey:@"id"] intValue]];
|
|
|
|
[request startAsynchronous];
|
2011-10-17 09:28:15 -07:00
|
|
|
}
|
2011-08-18 09:56:52 -07:00
|
|
|
|
2011-12-05 09:26:02 -08:00
|
|
|
- (void)deleteFolder {
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
|
HUD.labelText = @"Deleting...";
|
|
|
|
|
|
|
|
NSString *theFeedDetailURL = [NSString stringWithFormat:@"http://%@/reader/delete_folder",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *urlFeedDetail = [NSURL URLWithString:theFeedDetailURL];
|
|
|
|
|
|
|
|
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:urlFeedDetail];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request addPostValue:[appDelegate extractFolderName:appDelegate.activeFolder]
|
|
|
|
forKey:@"folder_to_delete"];
|
|
|
|
[request addPostValue:[appDelegate extractFolderName:[appDelegate extractParentFolderName:appDelegate.activeFolder]]
|
|
|
|
forKey:@"in_folder"];
|
|
|
|
[request setFailedBlock:^(void) {
|
|
|
|
[self informError:[request error]];
|
|
|
|
}];
|
|
|
|
[request setCompletionBlock:^(void) {
|
|
|
|
[appDelegate reloadFeedsView:YES];
|
|
|
|
[appDelegate.navigationController
|
|
|
|
popToViewController:[appDelegate.navigationController.viewControllers
|
|
|
|
objectAtIndex:0]
|
|
|
|
animated:YES];
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
}];
|
|
|
|
[request setTimeOutSeconds:30];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
2011-12-03 18:22:14 -08:00
|
|
|
- (void)openMoveView {
|
|
|
|
[appDelegate showMoveSite];
|
|
|
|
}
|
|
|
|
|
2011-08-18 09:56:52 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark PullToRefresh
|
|
|
|
|
|
|
|
// called when the user pulls-to-refresh
|
2011-12-01 19:03:26 -08:00
|
|
|
- (void)pullToRefreshViewShouldRefresh:(PullToRefreshView *)view {
|
|
|
|
if (appDelegate.isRiverView) {
|
|
|
|
[pull finishedLoading];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-08-21 13:46:43 -07:00
|
|
|
NSString *urlString = [NSString
|
2011-08-24 10:24:02 -07:00
|
|
|
stringWithFormat:@"http://%@/reader/refresh_feed/%@",
|
|
|
|
NEWSBLUR_URL,
|
2011-08-21 13:46:43 -07:00
|
|
|
[appDelegate.activeFeed objectForKey:@"id"]];
|
2011-11-30 09:38:31 -08:00
|
|
|
[self cancelRequests];
|
|
|
|
__block ASIHTTPRequest *request = [self requestWithURL:urlString];
|
2011-08-21 13:46:43 -07:00
|
|
|
[request setDelegate:self];
|
|
|
|
[request setResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDidFinishSelector:@selector(finishedRefreshingFeed:)];
|
|
|
|
[request setDidFailSelector:@selector(failRefreshingFeed:)];
|
|
|
|
[request setTimeOutSeconds:60];
|
2011-08-18 21:48:30 -07:00
|
|
|
[request startAsynchronous];
|
2011-08-21 13:46:43 -07:00
|
|
|
|
|
|
|
[appDelegate setStories:nil];
|
|
|
|
self.feedPage = 1;
|
|
|
|
self.pageFetching = YES;
|
|
|
|
self.pageRefreshing = YES;
|
|
|
|
[self.storyTitlesTable reloadData];
|
|
|
|
[storyTitlesTable scrollRectToVisible:CGRectMake(0, 0, 1, 1) animated:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishedRefreshingFeed:(ASIHTTPRequest *)request {
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSDictionary *results = [[NSDictionary alloc]
|
|
|
|
initWithDictionary:[responseString JSONValue]];
|
|
|
|
[pull finishedLoading];
|
|
|
|
self.pageRefreshing = NO;
|
|
|
|
[self renderStories:[results objectForKey:@"stories"]];
|
|
|
|
|
|
|
|
[results release];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)failRefreshingFeed:(ASIHTTPRequest *)request {
|
|
|
|
NSLog(@"Fail: %@", request);
|
|
|
|
self.pageRefreshing = NO;
|
2011-10-27 09:44:58 -07:00
|
|
|
[self informError:[request error]];
|
2011-08-21 13:46:43 -07:00
|
|
|
[pull finishedLoading];
|
2011-09-05 22:06:31 -07:00
|
|
|
[self fetchFeedDetail:1 withCallback:nil];
|
2011-08-18 09:56:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// called when the date shown needs to be updated, optional
|
|
|
|
- (NSDate *)pullToRefreshViewLastUpdated:(PullToRefreshView *)view {
|
2011-12-01 19:19:24 -08:00
|
|
|
// NSLog(@"Updated; %@", [appDelegate.activeFeed objectForKey:@"updated_seconds_ago"]);
|
2011-08-21 13:46:43 -07:00
|
|
|
int seconds = -1 * [[appDelegate.activeFeed objectForKey:@"updated_seconds_ago"] intValue];
|
|
|
|
return [[[NSDate alloc] initWithTimeIntervalSinceNow:seconds] autorelease];
|
2011-08-18 09:56:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-21 17:17:26 -04:00
|
|
|
@end
|