2010-06-17 13:10:45 -04:00
|
|
|
//
|
|
|
|
// NewsBlurAppDelegate.m
|
|
|
|
// NewsBlur
|
|
|
|
//
|
|
|
|
// Created by Samuel Clay on 6/16/10.
|
2010-06-21 17:17:26 -04:00
|
|
|
// Copyright NewsBlur 2010. All rights reserved.
|
2010-06-17 13:10:45 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "NewsBlurAppDelegate.h"
|
2012-06-19 11:48:51 -07:00
|
|
|
#import "NewsBlurViewController.h"
|
2012-07-24 11:44:16 -07:00
|
|
|
#import "NBContainerViewController.h"
|
2010-06-21 17:17:26 -04:00
|
|
|
#import "FeedDetailViewController.h"
|
2012-07-15 15:06:06 -07:00
|
|
|
#import "DashboardViewController.h"
|
2012-06-19 10:55:46 -07:00
|
|
|
#import "FeedsMenuViewController.h"
|
2012-10-12 13:58:26 -04:00
|
|
|
#import "FeedDetailMenuViewController.h"
|
2010-06-25 18:36:01 -04:00
|
|
|
#import "StoryDetailViewController.h"
|
2012-11-05 15:12:42 -08:00
|
|
|
#import "StoryPageControl.h"
|
2012-06-13 18:07:24 -07:00
|
|
|
#import "FirstTimeUserViewController.h"
|
2012-08-12 18:50:32 -07:00
|
|
|
#import "FriendsListViewController.h"
|
2010-10-31 23:02:13 -04:00
|
|
|
#import "LoginViewController.h"
|
2011-12-02 16:23:00 -08:00
|
|
|
#import "AddSiteViewController.h"
|
|
|
|
#import "MoveSiteViewController.h"
|
2012-12-24 23:01:25 -08:00
|
|
|
#import "TrainerViewController.h"
|
2010-11-13 18:32:43 -05:00
|
|
|
#import "OriginalStoryViewController.h"
|
2012-06-21 11:53:48 -07:00
|
|
|
#import "ShareViewController.h"
|
2012-07-01 18:26:39 -07:00
|
|
|
#import "UserProfileViewController.h"
|
2012-07-28 23:31:12 -07:00
|
|
|
#import "AFJSONRequestOperation.h"
|
2013-06-22 19:34:12 -07:00
|
|
|
#import "ASINetworkQueue.h"
|
2012-08-14 17:20:45 -07:00
|
|
|
#import "InteractionsModule.h"
|
|
|
|
#import "ActivityModule.h"
|
2012-08-15 13:04:05 -07:00
|
|
|
#import "FirstTimeUserViewController.h"
|
|
|
|
#import "FirstTimeUserAddSitesViewController.h"
|
|
|
|
#import "FirstTimeUserAddFriendsViewController.h"
|
|
|
|
#import "FirstTimeUserAddNewsBlurViewController.h"
|
2011-10-27 09:44:58 -07:00
|
|
|
#import "MBProgressHUD.h"
|
2011-10-28 18:29:33 -07:00
|
|
|
#import "Utilities.h"
|
2011-12-04 21:09:16 -08:00
|
|
|
#import "StringHelper.h"
|
2013-03-04 20:21:29 -08:00
|
|
|
#import "AuthorizeServicesViewController.h"
|
2013-05-30 18:45:51 -07:00
|
|
|
#import "Reachability.h"
|
2013-06-05 17:11:01 -07:00
|
|
|
#import "FMDatabase.h"
|
2013-06-14 19:21:30 -07:00
|
|
|
#import "FMDatabaseQueue.h"
|
2013-06-16 21:39:38 -07:00
|
|
|
#import "FMDatabaseAdditions.h"
|
2013-06-15 17:33:31 -07:00
|
|
|
#import "JSON.h"
|
2013-06-21 17:48:06 -07:00
|
|
|
#import "IASKAppSettingsViewController.h"
|
2013-07-15 18:25:09 -07:00
|
|
|
#import "OfflineSyncUnreads.h"
|
|
|
|
#import "OfflineFetchStories.h"
|
|
|
|
#import "OfflineFetchImages.h"
|
2013-08-05 18:32:43 -07:00
|
|
|
#import "OfflineCleanImages.h"
|
2013-07-19 15:04:03 -07:00
|
|
|
#import "PocketAPI.h"
|
2014-01-06 20:25:55 -08:00
|
|
|
#import "ADNLogin.h"
|
2014-01-06 17:54:18 -08:00
|
|
|
#import "OvershareKit.h"
|
2014-01-06 18:37:57 -08:00
|
|
|
#import "NBBarButtonItem.h"
|
2014-02-11 16:00:31 -08:00
|
|
|
#import "TMCache.h"
|
2014-02-12 20:09:37 -08:00
|
|
|
#import "StoriesCollection.h"
|
2014-02-18 16:44:41 -08:00
|
|
|
#import "NSString+HTML.h"
|
2014-01-06 14:51:35 -08:00
|
|
|
#import <float.h>
|
2010-06-17 13:10:45 -04:00
|
|
|
|
|
|
|
@implementation NewsBlurAppDelegate
|
|
|
|
|
2013-10-08 16:00:55 -07:00
|
|
|
#define CURRENT_DB_VERSION 31
|
2012-11-01 15:26:50 -07:00
|
|
|
|
2010-06-17 13:10:45 -04:00
|
|
|
@synthesize window;
|
2012-06-09 12:54:32 -07:00
|
|
|
|
2012-07-22 14:23:50 -07:00
|
|
|
@synthesize ftuxNavigationController;
|
2010-06-21 17:17:26 -04:00
|
|
|
@synthesize navigationController;
|
2012-07-31 17:17:02 -07:00
|
|
|
@synthesize modalNavigationController;
|
2012-08-13 18:45:06 -07:00
|
|
|
@synthesize shareNavigationController;
|
2013-03-02 19:15:08 -08:00
|
|
|
@synthesize trainNavigationController;
|
2012-07-28 12:56:51 -07:00
|
|
|
@synthesize userProfileNavigationController;
|
2012-07-24 11:44:16 -07:00
|
|
|
@synthesize masterContainerViewController;
|
2012-07-10 12:34:58 -07:00
|
|
|
@synthesize dashboardViewController;
|
2010-06-21 17:17:26 -04:00
|
|
|
@synthesize feedsViewController;
|
2012-06-19 10:55:46 -07:00
|
|
|
@synthesize feedsMenuViewController;
|
2010-06-24 12:53:50 -04:00
|
|
|
@synthesize feedDetailViewController;
|
2012-10-12 13:58:26 -04:00
|
|
|
@synthesize feedDetailMenuViewController;
|
2012-06-20 09:32:55 -07:00
|
|
|
@synthesize feedDashboardViewController;
|
2012-07-01 18:26:39 -07:00
|
|
|
@synthesize friendsListViewController;
|
2012-06-18 14:31:42 -07:00
|
|
|
@synthesize fontSettingsViewController;
|
2010-06-25 18:36:01 -04:00
|
|
|
@synthesize storyDetailViewController;
|
2012-11-05 15:12:42 -08:00
|
|
|
@synthesize storyPageControl;
|
2012-06-22 18:01:08 -07:00
|
|
|
@synthesize shareViewController;
|
2010-10-31 23:02:13 -04:00
|
|
|
@synthesize loginViewController;
|
2011-12-02 16:23:00 -08:00
|
|
|
@synthesize addSiteViewController;
|
|
|
|
@synthesize moveSiteViewController;
|
2012-12-24 23:01:25 -08:00
|
|
|
@synthesize trainerViewController;
|
2010-11-13 18:32:43 -05:00
|
|
|
@synthesize originalStoryViewController;
|
2013-09-25 17:43:00 -07:00
|
|
|
@synthesize originalStoryViewNavController;
|
2012-07-01 18:26:39 -07:00
|
|
|
@synthesize userProfileViewController;
|
2013-06-21 17:48:06 -07:00
|
|
|
@synthesize preferencesViewController;
|
2010-06-17 13:10:45 -04:00
|
|
|
|
2012-07-22 14:23:50 -07:00
|
|
|
@synthesize firstTimeUserViewController;
|
|
|
|
@synthesize firstTimeUserAddSitesViewController;
|
|
|
|
@synthesize firstTimeUserAddFriendsViewController;
|
|
|
|
@synthesize firstTimeUserAddNewsBlurViewController;
|
|
|
|
|
2012-06-20 08:33:16 -07:00
|
|
|
@synthesize feedDetailPortraitYCoordinate;
|
2014-02-24 18:56:51 -08:00
|
|
|
@synthesize cachedFavicons;
|
|
|
|
@synthesize cachedStoryImages;
|
2010-11-13 18:32:43 -05:00
|
|
|
@synthesize activeUsername;
|
2012-07-03 17:54:36 -07:00
|
|
|
@synthesize activeUserProfileId;
|
2012-07-28 14:15:20 -07:00
|
|
|
@synthesize activeUserProfileName;
|
2012-10-02 15:39:18 -07:00
|
|
|
@synthesize hasNoSites;
|
2012-08-06 19:21:39 -07:00
|
|
|
@synthesize isTryFeedView;
|
2012-08-02 18:00:48 -07:00
|
|
|
|
2012-07-16 22:35:28 -07:00
|
|
|
@synthesize inFindingStoryMode;
|
2013-07-17 19:22:41 -07:00
|
|
|
@synthesize hasLoadedFeedDetail;
|
2012-07-16 19:45:14 -07:00
|
|
|
@synthesize tryFeedStoryId;
|
2012-07-31 23:49:51 -07:00
|
|
|
@synthesize tryFeedCategory;
|
2012-06-19 15:47:51 -07:00
|
|
|
@synthesize popoverHasFeedView;
|
2012-06-29 23:25:56 -07:00
|
|
|
@synthesize inFeedDetail;
|
2012-08-02 18:00:48 -07:00
|
|
|
@synthesize inStoryDetail;
|
2012-06-25 18:05:25 -07:00
|
|
|
@synthesize activeComment;
|
2012-07-27 12:27:13 -07:00
|
|
|
@synthesize activeShareType;
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
@synthesize storiesCollection;
|
2014-02-11 16:55:15 -08:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
@synthesize activeStory;
|
2012-10-17 15:07:53 -07:00
|
|
|
@synthesize savedStoriesCount;
|
2011-08-09 17:58:43 -07:00
|
|
|
@synthesize originalStoryCount;
|
2011-07-29 09:06:17 -07:00
|
|
|
@synthesize selectedIntelligence;
|
2010-11-13 18:32:43 -05:00
|
|
|
@synthesize activeOriginalStoryURL;
|
2011-07-24 21:47:58 -07:00
|
|
|
@synthesize recentlyReadStories;
|
2011-11-03 18:08:24 -07:00
|
|
|
@synthesize recentlyReadFeeds;
|
2011-08-22 18:25:33 -07:00
|
|
|
@synthesize readStories;
|
2013-09-05 12:38:06 -07:00
|
|
|
@synthesize unreadStoryHashes;
|
2012-10-14 17:30:03 -07:00
|
|
|
@synthesize folderCountCache;
|
2010-06-17 13:10:45 -04:00
|
|
|
|
2011-10-04 18:01:35 -07:00
|
|
|
@synthesize dictFolders;
|
|
|
|
@synthesize dictFeeds;
|
2012-06-26 16:24:19 -07:00
|
|
|
@synthesize dictActiveFeeds;
|
2012-06-25 15:02:20 -07:00
|
|
|
@synthesize dictSocialFeeds;
|
2013-03-04 20:21:29 -08:00
|
|
|
@synthesize dictSocialProfile;
|
2012-07-01 18:26:39 -07:00
|
|
|
@synthesize dictUserProfile;
|
2013-03-04 20:21:29 -08:00
|
|
|
@synthesize dictSocialServices;
|
2013-06-29 17:28:41 -07:00
|
|
|
@synthesize dictUnreadCounts;
|
2012-07-26 23:07:47 -07:00
|
|
|
@synthesize userInteractionsArray;
|
|
|
|
@synthesize userActivitiesArray;
|
2011-10-04 18:01:35 -07:00
|
|
|
@synthesize dictFoldersArray;
|
|
|
|
|
2013-06-05 17:11:01 -07:00
|
|
|
@synthesize database;
|
2012-08-14 17:20:45 -07:00
|
|
|
@synthesize categories;
|
|
|
|
@synthesize categoryFeeds;
|
2013-06-23 22:19:08 -07:00
|
|
|
@synthesize activeCachedImages;
|
2013-07-15 18:25:09 -07:00
|
|
|
@synthesize hasQueuedReadStories;
|
|
|
|
@synthesize offlineQueue;
|
2013-08-05 18:32:43 -07:00
|
|
|
@synthesize offlineCleaningQueue;
|
2013-10-17 12:32:19 -07:00
|
|
|
@synthesize backgroundCompletionHandler;
|
2014-02-11 15:20:41 -08:00
|
|
|
@synthesize cacheImagesOperationQueue;
|
2012-08-14 17:20:45 -07:00
|
|
|
|
2014-02-11 16:55:15 -08:00
|
|
|
@synthesize totalUnfetchedStoryCount;
|
|
|
|
@synthesize remainingUnfetchedStoryCount;
|
|
|
|
@synthesize latestFetchedStoryDate;
|
|
|
|
@synthesize latestCachedImageDate;
|
|
|
|
@synthesize totalUncachedImagesCount;
|
|
|
|
@synthesize remainingUncachedImagesCount;
|
|
|
|
|
2011-12-03 18:22:14 -08:00
|
|
|
+ (NewsBlurAppDelegate*) sharedAppDelegate {
|
|
|
|
return (NewsBlurAppDelegate*) [UIApplication sharedApplication].delegate;
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:54:25 -08:00
|
|
|
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
2012-06-30 00:02:08 -07:00
|
|
|
NSString *currentiPhoneVersion = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
|
2013-07-16 18:06:36 -07:00
|
|
|
[self registerDefaultsFromSettingsBundle];
|
2012-06-30 00:02:08 -07:00
|
|
|
|
2013-03-03 14:03:56 -08:00
|
|
|
self.navigationController.delegate = self;
|
2012-07-24 16:03:16 -07:00
|
|
|
self.navigationController.viewControllers = [NSArray arrayWithObject:self.feedsViewController];
|
2014-02-13 17:18:29 -08:00
|
|
|
self.storiesCollection = [StoriesCollection new];
|
2014-02-12 20:09:37 -08:00
|
|
|
|
2012-06-30 00:02:08 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[ASIHTTPRequest setDefaultUserAgentString:[NSString stringWithFormat:@"NewsBlur iPad App v%@",
|
|
|
|
currentiPhoneVersion]];
|
2012-07-24 11:44:16 -07:00
|
|
|
[window addSubview:self.masterContainerViewController.view];
|
|
|
|
self.window.rootViewController = self.masterContainerViewController;
|
2013-12-11 18:06:22 -08:00
|
|
|
[self.masterContainerViewController didRotateFromInterfaceOrientation:nil];
|
2012-06-09 12:54:32 -07:00
|
|
|
} else {
|
2012-07-24 16:03:16 -07:00
|
|
|
[ASIHTTPRequest setDefaultUserAgentString:[NSString stringWithFormat:@"NewsBlur iPhone App v%@",
|
|
|
|
currentiPhoneVersion]];
|
2012-07-01 12:08:30 -07:00
|
|
|
[window addSubview:self.navigationController.view];
|
2012-07-24 16:03:16 -07:00
|
|
|
self.window.rootViewController = self.navigationController;
|
2012-06-09 12:54:32 -07:00
|
|
|
}
|
2013-04-12 10:11:21 -07:00
|
|
|
|
|
|
|
|
2010-06-17 13:10:45 -04:00
|
|
|
[window makeKeyAndVisible];
|
2013-10-08 16:00:55 -07:00
|
|
|
|
2014-02-03 18:54:50 -08:00
|
|
|
[[UINavigationBar appearance] setBarTintColor:UIColorFromRGB(0xE3E6E0)];
|
|
|
|
[[UIToolbar appearance] setBarTintColor: UIColorFromRGB(0xE3E6E0)];
|
2013-09-24 17:18:20 -07:00
|
|
|
[[UISegmentedControl appearance] setTintColor:UIColorFromRGB(0x8F918B)];
|
|
|
|
// [[UISegmentedControl appearance] setBackgroundColor:UIColorFromRGB(0x8F918B)];
|
2013-05-30 16:31:57 -07:00
|
|
|
|
2013-06-14 19:21:30 -07:00
|
|
|
[self createDatabaseConnection];
|
2013-10-17 17:23:52 -07:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
|
|
|
|
(unsigned long)NULL), ^(void) {
|
2014-02-24 18:56:51 -08:00
|
|
|
[self.cachedStoryImages removeAllObjects:^(TMCache *cache) {}];
|
2013-10-17 17:23:52 -07:00
|
|
|
[self.feedsViewController loadOfflineFeeds:NO];
|
2014-02-19 18:59:14 -08:00
|
|
|
// [self setupReachability];
|
2014-02-11 15:20:41 -08:00
|
|
|
cacheImagesOperationQueue = [NSOperationQueue new];
|
2014-02-12 20:41:29 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
cacheImagesOperationQueue.maxConcurrentOperationCount = 2;
|
|
|
|
} else {
|
|
|
|
cacheImagesOperationQueue.maxConcurrentOperationCount = 1;
|
|
|
|
}
|
2013-10-17 17:23:52 -07:00
|
|
|
});
|
2013-10-08 16:00:55 -07:00
|
|
|
|
2013-07-19 15:04:03 -07:00
|
|
|
[[PocketAPI sharedAPI] setConsumerKey:@"16638-05adf4465390446398e53b8b"];
|
2013-05-30 16:31:57 -07:00
|
|
|
// [self showFirstTimeUser];
|
2014-02-24 18:56:51 -08:00
|
|
|
|
2014-02-25 10:49:20 -08:00
|
|
|
cachedFavicons = [[TMCache alloc] initWithName:@"NBFavicons"];
|
|
|
|
cachedStoryImages = [[TMCache alloc] initWithName:@"NBStoryImages"];
|
2013-05-30 19:23:10 -07:00
|
|
|
|
2013-05-30 16:31:57 -07:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2014-03-03 12:12:06 -08:00
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
|
|
self.title = @"All";
|
|
|
|
}
|
2013-10-17 12:32:19 -07:00
|
|
|
|
|
|
|
- (void)application:(UIApplication *)application
|
|
|
|
performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
|
|
|
|
[self createDatabaseConnection];
|
|
|
|
[self.feedsViewController fetchFeedList:NO];
|
|
|
|
backgroundCompletionHandler = completionHandler;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishBackground {
|
|
|
|
if (!backgroundCompletionHandler) return;
|
|
|
|
|
|
|
|
NSLog(@"Background fetch complete. Found data: %d/%d = %d",
|
|
|
|
self.totalUnfetchedStoryCount, self.totalUncachedImagesCount,
|
|
|
|
self.totalUnfetchedStoryCount || self.totalUncachedImagesCount);
|
|
|
|
if (self.totalUnfetchedStoryCount || self.totalUncachedImagesCount) {
|
|
|
|
backgroundCompletionHandler(UIBackgroundFetchResultNewData);
|
|
|
|
} else {
|
|
|
|
backgroundCompletionHandler(UIBackgroundFetchResultNoData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-16 18:06:36 -07:00
|
|
|
- (void)registerDefaultsFromSettingsBundle {
|
|
|
|
NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"];
|
|
|
|
if(!settingsBundle) {
|
|
|
|
NSLog(@"Could not find Settings.bundle");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSDictionary *settings = [NSDictionary dictionaryWithContentsOfFile:[settingsBundle stringByAppendingPathComponent:@"Root.plist"]];
|
|
|
|
NSArray *preferences = [settings objectForKey:@"PreferenceSpecifiers"];
|
|
|
|
|
|
|
|
NSMutableDictionary *defaultsToRegister = [[NSMutableDictionary alloc] initWithCapacity:[preferences count]];
|
|
|
|
for(NSDictionary *prefSpecification in preferences) {
|
|
|
|
NSString *key = [prefSpecification objectForKey:@"Key"];
|
|
|
|
if (key && [[prefSpecification allKeys] containsObject:@"DefaultValue"]) {
|
|
|
|
[defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister];
|
|
|
|
}
|
|
|
|
|
2013-07-19 15:04:03 -07:00
|
|
|
- (BOOL)application:(UIApplication *)application
|
|
|
|
openURL:(NSURL *)url
|
|
|
|
sourceApplication:(NSString *)sourceApplication
|
|
|
|
annotation:(id)annotation {
|
|
|
|
if ([[PocketAPI sharedAPI] handleOpenURL:url]){
|
|
|
|
return YES;
|
|
|
|
} else {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
2013-03-06 16:23:17 -08:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
- (void)didReceiveMemoryWarning {
|
|
|
|
// Releases the view if it doesn't have a superview.
|
|
|
|
[super didReceiveMemoryWarning];
|
|
|
|
|
|
|
|
// Release any cached data, images, etc that aren't in use.
|
2014-02-24 18:56:51 -08:00
|
|
|
[cachedStoryImages removeAllObjects];
|
2014-02-12 20:09:37 -08:00
|
|
|
}
|
|
|
|
|
2013-05-30 18:45:51 -07:00
|
|
|
- (void)setupReachability {
|
2013-06-18 21:23:20 -04:00
|
|
|
Reachability* reach = [Reachability reachabilityWithHostname:NEWSBLUR_HOST];
|
2013-05-30 18:45:51 -07:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
|
|
selector:@selector(reachabilityChanged:)
|
|
|
|
name:kReachabilityChangedNotification
|
|
|
|
object:nil];
|
2014-02-18 17:28:36 -08:00
|
|
|
// reach.reachableBlock = ^(Reachability *reach) {
|
|
|
|
// NSLog(@"Reachable: %@", reach);
|
|
|
|
// };
|
|
|
|
// reach.unreachableBlock = ^(Reachability *reach) {
|
|
|
|
// NSLog(@"Un-Reachable: %@", reach);
|
|
|
|
// };
|
2013-05-30 18:45:51 -07:00
|
|
|
[reach startNotifier];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)reachabilityChanged:(id)something {
|
2014-02-18 17:28:36 -08:00
|
|
|
// NSLog(@"Reachability changed: %@", something);
|
2014-02-12 21:07:18 -08:00
|
|
|
Reachability* reach = [Reachability reachabilityWithHostname:NEWSBLUR_HOST];
|
|
|
|
|
|
|
|
if (reach.isReachable && feedsViewController.isOffline) {
|
|
|
|
[feedsViewController fetchFeedList:NO];
|
|
|
|
}
|
2013-05-30 18:45:51 -07:00
|
|
|
}
|
2013-03-06 16:23:17 -08:00
|
|
|
|
2012-06-29 23:48:47 -07:00
|
|
|
#pragma mark -
|
2012-07-01 12:08:30 -07:00
|
|
|
#pragma mark Social Views
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
- (NSDictionary *)getUser:(NSInteger)userId {
|
2014-02-12 20:09:37 -08:00
|
|
|
for (int i = 0; i < storiesCollection.activeFeedUserProfiles.count; i++) {
|
|
|
|
if ([[[storiesCollection.activeFeedUserProfiles objectAtIndex:i] objectForKey:@"user_id"] intValue] == userId) {
|
|
|
|
return [storiesCollection.activeFeedUserProfiles objectAtIndex:i];
|
2013-09-05 16:34:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check DB if not found in active feed
|
|
|
|
__block NSDictionary *user;
|
|
|
|
[self.database inDatabase:^(FMDatabase *db) {
|
2013-09-25 17:43:00 -07:00
|
|
|
NSString *userSql = [NSString stringWithFormat:@"SELECT * FROM users WHERE user_id = %ld", (long)userId];
|
2013-09-05 16:34:39 -07:00
|
|
|
FMResultSet *cursor = [db executeQuery:userSql];
|
|
|
|
while ([cursor next]) {
|
|
|
|
user = [NSJSONSerialization
|
|
|
|
JSONObjectWithData:[[cursor stringForColumn:@"user_json"]
|
|
|
|
dataUsingEncoding:NSUTF8StringEncoding]
|
|
|
|
options:nil error:nil];
|
|
|
|
if (user) break;
|
|
|
|
}
|
2013-10-03 18:07:39 -07:00
|
|
|
[cursor close];
|
2013-09-05 16:34:39 -07:00
|
|
|
}];
|
|
|
|
|
|
|
|
return user;
|
|
|
|
}
|
|
|
|
|
2012-07-28 12:56:51 -07:00
|
|
|
- (void)showUserProfileModal:(id)sender {
|
2012-08-02 18:00:48 -07:00
|
|
|
UserProfileViewController *newUserProfile = [[UserProfileViewController alloc] init];
|
|
|
|
self.userProfileViewController = newUserProfile;
|
2012-07-12 22:05:23 -07:00
|
|
|
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.userProfileViewController];
|
2012-07-28 12:56:51 -07:00
|
|
|
self.userProfileNavigationController = navController;
|
2013-09-25 12:05:17 -07:00
|
|
|
self.userProfileNavigationController.navigationBar.translucent = NO;
|
2012-07-31 00:53:16 -07:00
|
|
|
|
2012-07-28 12:56:51 -07:00
|
|
|
|
|
|
|
// adding Done button
|
|
|
|
UIBarButtonItem *donebutton = [[UIBarButtonItem alloc]
|
2012-07-28 14:56:40 -07:00
|
|
|
initWithTitle:@"Close"
|
2012-07-28 12:56:51 -07:00
|
|
|
style:UIBarButtonItemStyleDone
|
|
|
|
target:self
|
|
|
|
action:@selector(hideUserProfileModal)];
|
|
|
|
|
2012-08-02 18:00:48 -07:00
|
|
|
newUserProfile.navigationItem.rightBarButtonItem = donebutton;
|
|
|
|
newUserProfile.navigationItem.title = self.activeUserProfileName;
|
|
|
|
newUserProfile.navigationItem.backBarButtonItem.title = self.activeUserProfileName;
|
|
|
|
[newUserProfile getUserProfile];
|
2012-07-25 17:29:29 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-07-28 12:56:51 -07:00
|
|
|
[self.masterContainerViewController showUserProfilePopover:sender];
|
2012-07-25 17:29:29 -07:00
|
|
|
} else {
|
2013-06-17 11:50:13 -07:00
|
|
|
[self.navigationController presentViewController:navController animated:YES completion:nil];
|
2012-07-25 17:29:29 -07:00
|
|
|
}
|
2012-07-31 23:49:51 -07:00
|
|
|
|
2012-07-12 22:05:23 -07:00
|
|
|
}
|
|
|
|
|
2012-07-28 14:15:20 -07:00
|
|
|
- (void)pushUserProfile {
|
|
|
|
UserProfileViewController *userProfileView = [[UserProfileViewController alloc] init];
|
|
|
|
|
|
|
|
|
|
|
|
// adding Done button
|
|
|
|
UIBarButtonItem *donebutton = [[UIBarButtonItem alloc]
|
2012-07-28 14:56:40 -07:00
|
|
|
initWithTitle:@"Close"
|
2012-07-28 14:15:20 -07:00
|
|
|
style:UIBarButtonItemStyleDone
|
|
|
|
target:self
|
|
|
|
action:@selector(hideUserProfileModal)];
|
|
|
|
|
|
|
|
userProfileView.navigationItem.rightBarButtonItem = donebutton;
|
|
|
|
userProfileView.navigationItem.title = self.activeUserProfileName;
|
|
|
|
userProfileView.navigationItem.backBarButtonItem.title = self.activeUserProfileName;
|
2012-07-31 10:24:38 -07:00
|
|
|
[userProfileView getUserProfile];
|
2012-08-13 23:35:11 -07:00
|
|
|
if (self.modalNavigationController.view.window == nil) {
|
|
|
|
[self.userProfileNavigationController pushViewController:userProfileView animated:YES];
|
|
|
|
} else {
|
|
|
|
[self.modalNavigationController pushViewController:userProfileView animated:YES];
|
|
|
|
};
|
|
|
|
|
2012-07-28 14:15:20 -07:00
|
|
|
}
|
|
|
|
|
2012-07-12 22:05:23 -07:00
|
|
|
- (void)hideUserProfileModal {
|
2012-07-28 12:56:51 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-07-31 13:10:26 -07:00
|
|
|
[self.masterContainerViewController hidePopover];
|
2012-07-28 12:56:51 -07:00
|
|
|
} else {
|
2013-06-17 11:50:13 -07:00
|
|
|
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
|
2012-07-28 12:56:51 -07:00
|
|
|
}
|
2012-07-12 22:05:23 -07:00
|
|
|
}
|
|
|
|
|
2013-06-21 17:48:06 -07:00
|
|
|
- (void)showPreferences {
|
|
|
|
if (!preferencesViewController) {
|
|
|
|
preferencesViewController = [[IASKAppSettingsViewController alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
preferencesViewController.delegate = self.feedsViewController;
|
|
|
|
preferencesViewController.showDoneButton = YES;
|
|
|
|
preferencesViewController.showCreditsFooter = NO;
|
|
|
|
preferencesViewController.title = @"Preferences";
|
2013-11-23 13:14:30 -08:00
|
|
|
NSMutableSet *hiddenSet = [NSMutableSet set];
|
|
|
|
BOOL offline_enabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"offline_allowed"];
|
2013-12-13 15:15:17 -08:00
|
|
|
if (!offline_enabled) {
|
2013-11-23 13:14:30 -08:00
|
|
|
[hiddenSet addObjectsFromArray:@[@"offline_image_download",
|
|
|
|
@"offline_download_connection",
|
|
|
|
@"offline_store_limit"]];
|
|
|
|
}
|
|
|
|
BOOL system_font_enabled = [[NSUserDefaults standardUserDefaults] boolForKey:@"use_system_font_size"];
|
|
|
|
if (system_font_enabled) {
|
|
|
|
[hiddenSet addObjectsFromArray:@[@"feed_list_font_size"]];
|
|
|
|
}
|
|
|
|
preferencesViewController.hiddenKeys = hiddenSet;
|
2013-10-08 16:00:55 -07:00
|
|
|
[[NSUserDefaults standardUserDefaults] setObject:@"Delete offline stories..."
|
|
|
|
forKey:@"offline_cache_empty_stories"];
|
2013-06-21 17:48:06 -07:00
|
|
|
|
|
|
|
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:preferencesViewController];
|
|
|
|
self.modalNavigationController = navController;
|
2013-09-25 12:05:17 -07:00
|
|
|
self.modalNavigationController.navigationBar.translucent = NO;
|
2013-06-21 17:48:06 -07:00
|
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
self.modalNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
|
|
|
|
[masterContainerViewController presentViewController:modalNavigationController animated:YES completion:nil];
|
|
|
|
} else {
|
|
|
|
[navigationController presentViewController:modalNavigationController animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-01 12:08:30 -07:00
|
|
|
- (void)showFindFriends {
|
2012-07-31 15:17:51 -07:00
|
|
|
FriendsListViewController *friendsBVC = [[FriendsListViewController alloc] init];
|
2012-07-31 13:10:26 -07:00
|
|
|
UINavigationController *friendsNav = [[UINavigationController alloc] initWithRootViewController:friendsListViewController];
|
|
|
|
|
2013-06-21 17:48:06 -07:00
|
|
|
self.friendsListViewController = friendsBVC;
|
2012-07-31 17:17:02 -07:00
|
|
|
self.modalNavigationController = friendsNav;
|
2013-09-25 12:05:17 -07:00
|
|
|
self.modalNavigationController.navigationBar.translucent = NO;
|
2012-07-01 12:08:30 -07:00
|
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-07-31 17:17:02 -07:00
|
|
|
self.modalNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
|
2013-06-17 11:50:13 -07:00
|
|
|
[masterContainerViewController presentViewController:modalNavigationController animated:YES completion:nil];
|
2012-07-01 12:08:30 -07:00
|
|
|
} else {
|
2013-06-17 11:50:13 -07:00
|
|
|
[navigationController presentViewController:modalNavigationController animated:YES completion:nil];
|
2012-07-01 12:08:30 -07:00
|
|
|
}
|
2012-07-31 00:53:16 -07:00
|
|
|
[self.friendsListViewController loadSuggestedFriendsList];
|
2012-07-01 12:08:30 -07:00
|
|
|
}
|
2012-06-29 23:48:47 -07:00
|
|
|
|
2014-01-06 18:37:57 -08:00
|
|
|
- (void)showSendTo:(UIViewController *)vc sender:(id)sender {
|
2014-01-06 17:54:18 -08:00
|
|
|
NSString *authorName = [activeStory objectForKey:@"story_authors"];
|
|
|
|
NSString *text = [activeStory objectForKey:@"story_content"];
|
2014-02-18 16:44:41 -08:00
|
|
|
NSString *title = [[activeStory objectForKey:@"story_title"] stringByDecodingHTMLEntities];
|
2014-01-06 18:37:57 -08:00
|
|
|
NSArray *images = [activeStory objectForKey:@"image_urls"];
|
2014-01-06 17:54:18 -08:00
|
|
|
NSURL *url = [NSURL URLWithString:[activeStory objectForKey:@"story_permalink"]];
|
|
|
|
NSString *feedId = [NSString stringWithFormat:@"%@", [activeStory objectForKey:@"story_feed_id"]];
|
|
|
|
NSDictionary *feed = [self getFeed:feedId];
|
|
|
|
NSString *feedTitle = [feed objectForKey:@"feed_title"];
|
|
|
|
|
|
|
|
return [self showSendTo:vc
|
2014-01-06 18:37:57 -08:00
|
|
|
sender:sender
|
2014-01-06 17:54:18 -08:00
|
|
|
withUrl:url
|
|
|
|
authorName:authorName
|
|
|
|
text:text
|
|
|
|
title:title
|
|
|
|
feedTitle:feedTitle
|
|
|
|
images:images];
|
|
|
|
}
|
|
|
|
|
2014-01-06 18:37:57 -08:00
|
|
|
- (void)showSendTo:(UIViewController *)vc sender:(id)sender
|
|
|
|
withUrl:(NSURL *)url
|
2014-01-06 17:54:18 -08:00
|
|
|
authorName:(NSString *)authorName
|
|
|
|
text:(NSString *)text
|
|
|
|
title:(NSString *)title
|
|
|
|
feedTitle:(NSString *)feedTitle
|
|
|
|
images:(NSArray *)images {
|
|
|
|
OSKShareableContent *content = [[OSKShareableContent alloc] init];
|
|
|
|
|
2014-01-06 18:37:57 -08:00
|
|
|
text = text ? text : @"";
|
2014-01-06 17:54:18 -08:00
|
|
|
content.title = [NSString stringWithFormat:@"%@", title];
|
|
|
|
|
|
|
|
OSKMicroblogPostContentItem *microblogPost = [[OSKMicroblogPostContentItem alloc] init];
|
2014-01-06 19:53:37 -08:00
|
|
|
microblogPost.text = [NSString stringWithFormat:@"%@ %@", title, [url absoluteString]];
|
2014-01-06 17:54:18 -08:00
|
|
|
microblogPost.images = [activeStory objectForKey:@"story_images"];;
|
|
|
|
content.microblogPostItem = microblogPost;
|
|
|
|
|
|
|
|
OSKCopyToPasteboardContentItem *copyTextToPasteboard = [[OSKCopyToPasteboardContentItem alloc] init];
|
|
|
|
copyTextToPasteboard.text = text;
|
|
|
|
copyTextToPasteboard.alternateActivityName = @"Copy Text";
|
|
|
|
content.pasteboardItem = copyTextToPasteboard;
|
|
|
|
|
|
|
|
OSKCopyToPasteboardContentItem *copyURLToPasteboard = [[OSKCopyToPasteboardContentItem alloc] init];
|
|
|
|
copyURLToPasteboard.text = [url absoluteString];
|
|
|
|
copyURLToPasteboard.alternateActivityName = @"Copy URL";
|
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
|
|
|
|
copyURLToPasteboard.alternateActivityIcon = [UIImage imageNamed:@"osk-copyIcon-purple-76.png"];
|
|
|
|
} else {
|
|
|
|
copyURLToPasteboard.alternateActivityIcon = [UIImage imageNamed:@"osk-copyIcon-purple-60.png"];
|
|
|
|
}
|
|
|
|
|
|
|
|
OSKCopyToPasteboardContentItem *copyTitleToPasteboard = [[OSKCopyToPasteboardContentItem alloc] init];
|
|
|
|
copyTitleToPasteboard.text = title;
|
|
|
|
copyTitleToPasteboard.alternateActivityName = @"Copy Title";
|
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
|
|
|
|
copyURLToPasteboard.alternateActivityIcon = [UIImage imageNamed:@"osk-copyIcon-purple-76.png"];
|
|
|
|
} else {
|
|
|
|
copyURLToPasteboard.alternateActivityIcon = [UIImage imageNamed:@"osk-copyIcon-purple-60.png"];
|
|
|
|
}
|
|
|
|
|
|
|
|
content.additionalItems = @[copyURLToPasteboard, copyTitleToPasteboard];
|
|
|
|
|
|
|
|
OSKEmailContentItem *emailItem = [[OSKEmailContentItem alloc] init];
|
2014-01-06 18:37:57 -08:00
|
|
|
NSString *maybeFeedTitle = feedTitle ? [NSString stringWithFormat:@" via %@", feedTitle] : @"";
|
|
|
|
emailItem.body = [NSString stringWithFormat:@"<br><br><hr style=\"border: none; overflow: hidden; height: 1px;width: 100%%;background-color: #C0C0C0;\"><br><a href=\"%@\">%@</a>%@<br>%@", [url absoluteString], title, maybeFeedTitle, text];
|
2014-01-06 17:54:18 -08:00
|
|
|
emailItem.subject = title;
|
|
|
|
emailItem.isHTML = YES;
|
|
|
|
content.emailItem = emailItem;
|
|
|
|
|
|
|
|
OSKSMSContentItem *smsItem = [[OSKSMSContentItem alloc] init];
|
2014-02-11 13:23:45 -08:00
|
|
|
smsItem.body = [NSString stringWithFormat:@"%@\n%@", title, [url absoluteString]];;
|
2014-01-06 17:54:18 -08:00
|
|
|
content.smsItem = smsItem;
|
|
|
|
|
|
|
|
OSKReadLaterContentItem *readLater = [[OSKReadLaterContentItem alloc] init];
|
|
|
|
readLater.url = url;
|
|
|
|
content.readLaterItem = readLater;
|
|
|
|
|
|
|
|
OSKToDoListEntryContentItem *toDoList = [[OSKToDoListEntryContentItem alloc] init];
|
|
|
|
toDoList.title = [NSString stringWithFormat:@"Read \"%@\"", title];
|
|
|
|
toDoList.notes = [NSString stringWithFormat:@"%@\n\n%@", text, [url absoluteString]];
|
|
|
|
content.toDoListItem = toDoList;
|
|
|
|
|
|
|
|
OSKLinkBookmarkContentItem *linkBookmarking = [[OSKLinkBookmarkContentItem alloc] init];
|
|
|
|
linkBookmarking.url = readLater.url;
|
2014-01-06 20:25:55 -08:00
|
|
|
linkBookmarking.title = title;
|
2014-01-06 17:54:18 -08:00
|
|
|
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"];
|
2014-01-06 20:25:55 -08:00
|
|
|
NSMutableArray *tags = [NSMutableArray arrayWithObject:appName];
|
|
|
|
[tags addObjectsFromArray:[activeStory objectForKey:@"story_tags"]];
|
|
|
|
linkBookmarking.tags = tags;
|
2014-01-06 17:54:18 -08:00
|
|
|
linkBookmarking.markToRead = YES;
|
|
|
|
content.linkBookmarkItem = linkBookmarking;
|
|
|
|
|
|
|
|
OSKWebBrowserContentItem *browserItem = [[OSKWebBrowserContentItem alloc] init];
|
|
|
|
browserItem.url = readLater.url;
|
|
|
|
content.webBrowserItem = browserItem;
|
|
|
|
|
|
|
|
OSKPasswordManagementAppSearchContentItem *passwordSearchItem = [[OSKPasswordManagementAppSearchContentItem alloc] init];
|
|
|
|
passwordSearchItem.query = [url host];
|
|
|
|
content.passwordSearchItem = passwordSearchItem;
|
|
|
|
|
|
|
|
if (images.count) {
|
|
|
|
OSKAirDropContentItem *airDrop = [[OSKAirDropContentItem alloc] init];
|
|
|
|
airDrop.items = images;
|
|
|
|
content.airDropItem = airDrop;
|
|
|
|
}
|
|
|
|
else if ([url absoluteString].length) {
|
|
|
|
OSKAirDropContentItem *airDrop = [[OSKAirDropContentItem alloc] init];
|
|
|
|
airDrop.items = @[[url absoluteString]];
|
|
|
|
content.airDropItem = airDrop;
|
|
|
|
}
|
|
|
|
else if (text.length) {
|
|
|
|
OSKAirDropContentItem *airDrop = [[OSKAirDropContentItem alloc] init];
|
|
|
|
airDrop.items = @[text];
|
|
|
|
content.airDropItem = airDrop;
|
|
|
|
}
|
|
|
|
|
2014-01-06 18:56:41 -08:00
|
|
|
|
|
|
|
OSKActivityCompletionHandler completionHandler = ^(OSKActivity *activity, BOOL successful, NSError *error){
|
2014-01-06 19:05:46 -08:00
|
|
|
if (!successful) return;
|
2014-01-06 18:56:41 -08:00
|
|
|
|
|
|
|
NSString *activityType = [activity.class activityType];
|
|
|
|
NSString *_completedString;
|
|
|
|
|
|
|
|
if ([activityType isEqualToString:OSKActivityType_iOS_Twitter]) {
|
|
|
|
_completedString = @"Posted";
|
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_iOS_Facebook]) {
|
|
|
|
_completedString = @"Posted";
|
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_iOS_Email]) {
|
|
|
|
_completedString = @"Sent";
|
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_iOS_SMS]) {
|
|
|
|
_completedString = @"Sent";
|
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_iOS_CopyToPasteboard]) {
|
|
|
|
_completedString = @"Copied";
|
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_API_Instapaper]) {
|
|
|
|
_completedString = @"Saved to Instapaper";
|
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_API_Pocket]) {
|
|
|
|
_completedString = @"Saved to Pocket";
|
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_API_Readability]) {
|
|
|
|
_completedString = @"Saved to Readability";
|
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_API_Pinboard]) {
|
|
|
|
_completedString = @"Saved to Pinboard";
|
2014-01-06 19:53:37 -08:00
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_iOS_AirDrop]) {
|
|
|
|
_completedString = @"Airdropped";
|
2014-01-06 18:56:41 -08:00
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_iOS_Safari]) {
|
|
|
|
return;
|
|
|
|
} else if ([activityType isEqualToString:OSKActivityType_URLScheme_Chrome]) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
_completedString = @"Saved";
|
|
|
|
}
|
|
|
|
[MBProgressHUD hideHUDForView:vc.view animated:NO];
|
|
|
|
MBProgressHUD *storyHUD = [MBProgressHUD showHUDAddedTo:vc.view animated:YES];
|
|
|
|
storyHUD.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"37x-Checkmark.png"]];
|
|
|
|
storyHUD.mode = MBProgressHUDModeCustomView;
|
|
|
|
storyHUD.removeFromSuperViewOnHide = YES;
|
|
|
|
storyHUD.labelText = _completedString;
|
|
|
|
[storyHUD hide:YES afterDelay:1];
|
|
|
|
};
|
|
|
|
|
2014-01-06 20:25:55 -08:00
|
|
|
[[OSKActivitiesManager sharedInstance] setCustomizationsDelegate:self];
|
|
|
|
|
2014-01-06 18:56:41 -08:00
|
|
|
NSDictionary *options = @{OSKPresentationOption_ActivityCompletionHandler: completionHandler};
|
|
|
|
|
2014-01-06 18:37:57 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[self.masterContainerViewController showSendToPopover:vc];
|
|
|
|
if ([sender isKindOfClass:[UIBarButtonItem class]]) {
|
2014-01-06 18:56:41 -08:00
|
|
|
[[OSKPresentationManager sharedInstance] presentActivitySheetForContent:content presentingViewController:self.masterContainerViewController popoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES options:options];
|
2014-01-06 18:37:57 -08:00
|
|
|
} else {
|
2014-01-06 18:56:41 -08:00
|
|
|
[[OSKPresentationManager sharedInstance] presentActivitySheetForContent:content presentingViewController:vc popoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES options:options];
|
2014-01-06 18:37:57 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
[[OSKPresentationManager sharedInstance] presentActivitySheetForContent:content
|
2014-01-06 18:56:41 -08:00
|
|
|
presentingViewController:vc options:options];
|
2014-01-06 18:37:57 -08:00
|
|
|
}
|
2014-01-06 17:54:18 -08:00
|
|
|
}
|
|
|
|
|
2014-01-06 20:25:55 -08:00
|
|
|
|
|
|
|
- (OSKApplicationCredential *)applicationCredentialForActivityType:(NSString *)activityType {
|
|
|
|
OSKApplicationCredential *appCredential = nil;
|
|
|
|
if ([activityType isEqualToString:OSKActivityType_iOS_Facebook]) {
|
|
|
|
appCredential = [[OSKApplicationCredential alloc]
|
|
|
|
initWithOvershareApplicationKey:@"230426707030569"
|
|
|
|
applicationSecret:@"b819827cab9a66faf41478cf9c405195"
|
|
|
|
appName:@"NewsBlur"];
|
|
|
|
}
|
|
|
|
else if ([activityType isEqualToString:OSKActivityType_API_AppDotNet]) {
|
|
|
|
appCredential = [[OSKApplicationCredential alloc]
|
|
|
|
initWithOvershareApplicationKey:@"7Y482n6JErhDeSDA6TY7Qv29mU22G2v2"
|
|
|
|
applicationSecret:@"4rFFMKG68fWnAQA8W6puxTaYBkupuCBH"
|
|
|
|
appName:@"NewsBlur"];
|
|
|
|
}
|
|
|
|
else if ([activityType isEqualToString:OSKActivityType_API_Pocket]) {
|
|
|
|
appCredential = [[OSKApplicationCredential alloc]
|
|
|
|
initWithOvershareApplicationKey:@"16638-05adf4465390446398e53b8b"
|
|
|
|
applicationSecret:@"16638-05adf4465390446398e53b8b"
|
|
|
|
appName:@"NewsBlur"];
|
|
|
|
}
|
|
|
|
else if ([activityType isEqualToString:OSKActivityType_API_Readability]) {
|
|
|
|
appCredential = [[OSKApplicationCredential alloc]
|
|
|
|
initWithOvershareApplicationKey:@"samuelclay"
|
|
|
|
applicationSecret:@"ktLQc88S9WCE8PfvZ4u4q995Q3HMzg6Q"
|
|
|
|
appName:@"NewsBlur"];
|
|
|
|
}
|
2014-02-27 16:54:25 -08:00
|
|
|
else if ([activityType isEqualToString:OSKActivityType_API_GooglePlus]) {
|
|
|
|
appCredential = [[OSKApplicationCredential alloc]
|
|
|
|
initWithOvershareApplicationKey:@"598270143373.apps.googleusercontent.com"
|
|
|
|
applicationSecret:@"gizh7veBOZS9_SdltRIyOhnB"
|
|
|
|
appName:@"NewsBlur"];
|
|
|
|
}
|
2014-01-06 20:25:55 -08:00
|
|
|
|
|
|
|
return appCredential;
|
|
|
|
}
|
|
|
|
|
2014-02-27 16:10:28 -08:00
|
|
|
- (BOOL)osk_automaticallyShortenURLsWhenRecommended {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
2014-01-06 17:54:18 -08:00
|
|
|
- (void)showShareView:(NSString *)type
|
2012-07-20 15:54:10 -07:00
|
|
|
setUserId:(NSString *)userId
|
|
|
|
setUsername:(NSString *)username
|
2012-07-30 14:58:57 -07:00
|
|
|
setReplyId:(NSString *)replyId {
|
2012-07-23 16:17:49 -07:00
|
|
|
|
2013-03-02 21:27:29 -08:00
|
|
|
[self.shareViewController setCommentType:type];
|
2012-07-12 23:44:14 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-07-25 20:38:44 -07:00
|
|
|
[self.masterContainerViewController transitionToShareView];
|
2012-07-12 23:44:14 -07:00
|
|
|
} else {
|
2012-08-13 18:45:06 -07:00
|
|
|
if (self.shareNavigationController == nil) {
|
2012-11-28 15:21:44 -08:00
|
|
|
UINavigationController *shareNav = [[UINavigationController alloc]
|
|
|
|
initWithRootViewController:self.shareViewController];
|
2012-08-13 18:45:06 -07:00
|
|
|
self.shareNavigationController = shareNav;
|
2013-09-25 12:05:17 -07:00
|
|
|
self.shareNavigationController.navigationBar.translucent = NO;
|
2012-08-13 18:45:06 -07:00
|
|
|
}
|
2013-03-02 21:27:29 -08:00
|
|
|
[self.shareViewController setSiteInfo:type setUserId:userId setUsername:username setReplyId:replyId];
|
2013-06-17 11:50:13 -07:00
|
|
|
[self.navigationController presentViewController:self.shareNavigationController animated:YES completion:nil];
|
2012-07-12 23:44:14 -07:00
|
|
|
}
|
2013-03-02 21:27:29 -08:00
|
|
|
|
2012-11-28 15:21:44 -08:00
|
|
|
[self.shareViewController setSiteInfo:type setUserId:userId setUsername:username setReplyId:replyId];
|
2012-07-12 13:34:41 -07:00
|
|
|
}
|
|
|
|
|
2014-01-06 19:05:46 -08:00
|
|
|
- (void)showSendToManagement {
|
|
|
|
OSKAccountManagementViewController *manager = [[OSKAccountManagementViewController alloc] initWithIgnoredActivityClasses:nil optionalBespokeActivityClasses:nil];
|
|
|
|
OSKNavigationController *navController = [[OSKNavigationController alloc] initWithRootViewController:manager];
|
|
|
|
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
|
|
|
|
[navController setModalPresentationStyle:UIModalPresentationFormSheet];
|
|
|
|
}
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[self.masterContainerViewController presentViewController:navController animated:YES completion:nil];
|
|
|
|
} else {
|
|
|
|
[self.navigationController presentViewController:navController animated:YES completion:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-12 13:34:41 -07:00
|
|
|
- (void)hideShareView:(BOOL)resetComment {
|
|
|
|
if (resetComment) {
|
|
|
|
self.shareViewController.commentField.text = @"";
|
2012-08-13 23:54:10 -07:00
|
|
|
self.shareViewController.currentType = nil;
|
2012-07-12 13:34:41 -07:00
|
|
|
}
|
2012-07-26 11:11:43 -07:00
|
|
|
|
2012-07-23 16:17:49 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-07-25 20:38:44 -07:00
|
|
|
[self.masterContainerViewController transitionFromShareView];
|
2012-07-12 23:44:14 -07:00
|
|
|
} else {
|
2013-06-17 11:50:13 -07:00
|
|
|
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
|
2012-07-26 11:11:43 -07:00
|
|
|
[self.shareViewController.commentField resignFirstResponder];
|
2012-07-12 23:44:14 -07:00
|
|
|
}
|
2012-06-29 23:48:47 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)resetShareComments {
|
|
|
|
[shareViewController clearComments];
|
|
|
|
}
|
|
|
|
|
2010-06-24 00:22:26 -04:00
|
|
|
#pragma mark -
|
2013-06-29 17:28:41 -07:00
|
|
|
#pragma mark View Management
|
2010-06-24 00:22:26 -04:00
|
|
|
|
2010-11-11 23:48:27 -05:00
|
|
|
- (void)showLogin {
|
2012-07-01 23:48:43 -07:00
|
|
|
self.dictFeeds = nil;
|
|
|
|
self.dictSocialFeeds = nil;
|
|
|
|
self.dictFolders = nil;
|
|
|
|
self.dictFoldersArray = nil;
|
2012-08-14 17:20:45 -07:00
|
|
|
self.userActivitiesArray = nil;
|
|
|
|
self.userInteractionsArray = nil;
|
2013-06-29 17:28:41 -07:00
|
|
|
self.dictUnreadCounts = nil;
|
2012-07-01 23:48:43 -07:00
|
|
|
|
|
|
|
[self.feedsViewController.feedTitlesTable reloadData];
|
2012-08-14 17:20:45 -07:00
|
|
|
[self.feedsViewController resetToolbar];
|
|
|
|
|
|
|
|
[self.dashboardViewController.interactionsModule.interactionsTable reloadData];
|
|
|
|
[self.dashboardViewController.activitiesModule.activitiesTable reloadData];
|
|
|
|
|
|
|
|
NSUserDefaults *userPreferences = [NSUserDefaults standardUserDefaults];
|
|
|
|
[userPreferences setInteger:-1 forKey:@"selectedIntelligence"];
|
|
|
|
[userPreferences synchronize];
|
|
|
|
|
2012-06-13 12:19:35 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2013-06-17 11:50:13 -07:00
|
|
|
[self.masterContainerViewController presentViewController:loginViewController animated:NO completion:nil];
|
2012-06-13 12:19:35 -07:00
|
|
|
} else {
|
2013-06-17 11:50:13 -07:00
|
|
|
[feedsMenuViewController dismissViewControllerAnimated:NO completion:nil];
|
|
|
|
[self.navigationController presentViewController:loginViewController animated:NO completion:nil];
|
2012-06-13 12:19:35 -07:00
|
|
|
}
|
2010-11-11 23:48:27 -05:00
|
|
|
}
|
|
|
|
|
2012-06-13 18:07:24 -07:00
|
|
|
- (void)showFirstTimeUser {
|
2012-08-15 13:04:05 -07:00
|
|
|
// [self.feedsViewController changeToAllMode];
|
|
|
|
|
2012-07-22 14:23:50 -07:00
|
|
|
UINavigationController *ftux = [[UINavigationController alloc] initWithRootViewController:self.firstTimeUserViewController];
|
|
|
|
|
|
|
|
self.ftuxNavigationController = ftux;
|
2013-09-25 12:05:17 -07:00
|
|
|
self.ftuxNavigationController.navigationBar.translucent = NO;
|
2012-07-22 14:23:50 -07:00
|
|
|
|
2012-06-13 18:07:24 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-07-22 14:23:50 -07:00
|
|
|
self.ftuxNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
|
2013-06-17 11:50:13 -07:00
|
|
|
[self.masterContainerViewController presentViewController:self.ftuxNavigationController animated:YES completion:nil];
|
2012-08-14 17:20:45 -07:00
|
|
|
|
|
|
|
self.ftuxNavigationController.view.superview.frame = CGRectMake(0, 0, 540, 540);//it's important to do this after
|
|
|
|
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
|
|
|
if (UIInterfaceOrientationIsPortrait(orientation)) {
|
|
|
|
self.ftuxNavigationController.view.superview.center = self.view.center;
|
|
|
|
} else {
|
|
|
|
self.ftuxNavigationController.view.superview.center = CGPointMake(self.view.center.y, self.view.center.x);
|
|
|
|
}
|
|
|
|
|
2012-06-13 18:07:24 -07:00
|
|
|
} else {
|
2013-06-17 11:50:13 -07:00
|
|
|
[self.navigationController presentViewController:self.ftuxNavigationController animated:YES completion:nil];
|
2012-06-13 18:07:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-02 16:23:00 -08:00
|
|
|
- (void)showMoveSite {
|
|
|
|
UINavigationController *navController = self.navigationController;
|
2012-06-08 19:36:23 -07:00
|
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
moveSiteViewController.modalPresentationStyle=UIModalPresentationFormSheet;
|
2013-06-17 11:50:13 -07:00
|
|
|
[navController presentViewController:moveSiteViewController animated:YES completion:nil];
|
2012-06-08 19:36:23 -07:00
|
|
|
} else {
|
2013-06-17 11:50:13 -07:00
|
|
|
[navController presentViewController:moveSiteViewController animated:YES completion:nil];
|
2012-06-08 19:36:23 -07:00
|
|
|
}
|
2011-10-04 18:01:35 -07:00
|
|
|
}
|
|
|
|
|
2012-12-24 23:01:25 -08:00
|
|
|
- (void)openTrainSite {
|
2013-10-02 18:06:31 -07:00
|
|
|
// Needs a delay because the menu will close the popover.
|
|
|
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC),
|
|
|
|
dispatch_get_main_queue(), ^{
|
|
|
|
[self
|
|
|
|
openTrainSiteWithFeedLoaded:YES
|
|
|
|
from:self.feedDetailViewController.settingsBarButton];
|
|
|
|
});
|
2013-10-02 16:05:22 -07:00
|
|
|
}
|
|
|
|
|
2013-10-02 16:28:09 -07:00
|
|
|
- (void)openTrainSiteWithFeedLoaded:(BOOL)feedLoaded from:(id)sender {
|
2012-12-24 23:01:25 -08:00
|
|
|
UINavigationController *navController = self.navigationController;
|
2012-12-27 00:15:26 -08:00
|
|
|
trainerViewController.feedTrainer = YES;
|
|
|
|
trainerViewController.storyTrainer = NO;
|
2013-10-02 16:05:22 -07:00
|
|
|
trainerViewController.feedLoaded = feedLoaded;
|
2012-12-24 23:01:25 -08:00
|
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-12-27 19:34:05 -08:00
|
|
|
// trainerViewController.modalPresentationStyle=UIModalPresentationFormSheet;
|
2013-06-17 11:50:13 -07:00
|
|
|
// [navController presentViewController:trainerViewController animated:YES completion:nil];
|
2013-10-02 16:28:09 -07:00
|
|
|
[self.masterContainerViewController showTrainingPopover:sender];
|
2012-12-27 00:15:26 -08:00
|
|
|
} else {
|
2013-03-02 19:15:08 -08:00
|
|
|
if (self.trainNavigationController == nil) {
|
|
|
|
self.trainNavigationController = [[UINavigationController alloc]
|
|
|
|
initWithRootViewController:self.trainerViewController];
|
|
|
|
}
|
2013-09-25 12:05:17 -07:00
|
|
|
self.trainNavigationController.navigationBar.translucent = NO;
|
2013-06-17 11:50:13 -07:00
|
|
|
[navController presentViewController:self.trainNavigationController animated:YES completion:nil];
|
2012-12-27 00:15:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-27 23:04:25 -08:00
|
|
|
- (void)openTrainStory:(id)sender {
|
2012-12-27 00:15:26 -08:00
|
|
|
UINavigationController *navController = self.navigationController;
|
|
|
|
trainerViewController.feedTrainer = NO;
|
|
|
|
trainerViewController.storyTrainer = YES;
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-12-27 23:04:25 -08:00
|
|
|
[self.masterContainerViewController showTrainingPopover:sender];
|
2012-12-24 23:01:25 -08:00
|
|
|
} else {
|
2013-03-02 19:15:08 -08:00
|
|
|
if (self.trainNavigationController == nil) {
|
|
|
|
self.trainNavigationController = [[UINavigationController alloc]
|
|
|
|
initWithRootViewController:self.trainerViewController];
|
|
|
|
}
|
2013-09-25 12:05:17 -07:00
|
|
|
self.trainNavigationController.navigationBar.translucent = NO;
|
2013-06-17 11:50:13 -07:00
|
|
|
[navController presentViewController:self.trainNavigationController animated:YES completion:nil];
|
2012-12-24 23:01:25 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-03 18:22:14 -08:00
|
|
|
- (void)reloadFeedsView:(BOOL)showLoader {
|
2012-08-09 10:18:15 -07:00
|
|
|
[feedsViewController fetchFeedList:showLoader];
|
2010-11-11 20:05:53 -05:00
|
|
|
}
|
2011-10-06 10:27:37 -07:00
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
- (void)loadFeedDetailView {
|
2014-02-10 19:21:53 -08:00
|
|
|
[self loadFeedDetailView:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadFeedDetailView:(BOOL)transition {
|
2014-02-12 20:09:37 -08:00
|
|
|
[storiesCollection setStories:nil];
|
|
|
|
[storiesCollection setFeedUserProfiles:nil];
|
2013-03-01 15:48:18 -08:00
|
|
|
self.inFeedDetail = YES;
|
2012-06-27 21:28:04 -07:00
|
|
|
popoverHasFeedView = YES;
|
2014-02-19 18:59:14 -08:00
|
|
|
|
2013-07-19 17:20:39 -07:00
|
|
|
[feedDetailViewController resetFeedDetail];
|
2014-02-19 18:59:14 -08:00
|
|
|
if (feedDetailViewController == dashboardViewController.storiesModule) {
|
|
|
|
feedDetailViewController.storiesCollection = dashboardViewController.storiesModule.storiesCollection;
|
|
|
|
} else if (feedDetailViewController == feedDetailViewController) {
|
|
|
|
feedDetailViewController.storiesCollection = storiesCollection;
|
|
|
|
}
|
2013-08-06 18:08:55 -07:00
|
|
|
|
2014-02-10 19:21:53 -08:00
|
|
|
if (transition) {
|
|
|
|
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc]
|
|
|
|
initWithTitle: @"All"
|
|
|
|
style: UIBarButtonItemStyleBordered
|
|
|
|
target: nil
|
|
|
|
action: nil];
|
|
|
|
[feedsViewController.navigationItem setBackBarButtonItem:newBackButton];
|
|
|
|
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[self.masterContainerViewController transitionToFeedDetail];
|
|
|
|
} else {
|
|
|
|
[navigationController pushViewController:feedDetailViewController
|
|
|
|
animated:YES];
|
|
|
|
}
|
2012-07-20 22:00:30 -07:00
|
|
|
}
|
2014-02-12 20:41:29 -08:00
|
|
|
|
|
|
|
[self flushQueuedReadStories:NO withCallback:^{
|
|
|
|
[feedDetailViewController fetchFeedDetail:1 withCallback:nil];
|
|
|
|
}];
|
|
|
|
|
2012-06-19 15:47:51 -07:00
|
|
|
}
|
|
|
|
|
2012-11-09 14:13:44 -08:00
|
|
|
- (void)loadTryFeedDetailView:(NSString *)feedId
|
|
|
|
withStory:(NSString *)contentId
|
|
|
|
isSocial:(BOOL)social
|
|
|
|
withUser:(NSDictionary *)user
|
|
|
|
showFindingStory:(BOOL)showHUD {
|
2012-07-29 20:55:11 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
|
|
[self.navigationController popToRootViewControllerAnimated:NO];
|
2013-06-17 11:50:13 -07:00
|
|
|
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
|
2013-02-21 17:57:32 -08:00
|
|
|
if (self.feedsViewController.popoverController) {
|
|
|
|
[self.feedsViewController.popoverController dismissPopoverAnimated:NO];
|
|
|
|
}
|
2012-07-29 20:55:11 -07:00
|
|
|
}
|
|
|
|
|
2013-10-17 17:23:52 -07:00
|
|
|
NSDictionary *feed = [self getFeed:feedId];
|
2012-07-16 22:35:28 -07:00
|
|
|
|
|
|
|
if (social) {
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.isSocialView = YES;
|
2012-08-01 12:41:02 -07:00
|
|
|
self.inFindingStoryMode = YES;
|
2012-07-29 20:55:11 -07:00
|
|
|
|
2012-07-28 23:31:12 -07:00
|
|
|
if (feed == nil) {
|
|
|
|
feed = user;
|
2012-08-06 19:21:39 -07:00
|
|
|
self.isTryFeedView = YES;
|
2012-07-28 23:31:12 -07:00
|
|
|
}
|
2012-07-16 22:35:28 -07:00
|
|
|
} else {
|
2012-07-28 23:31:12 -07:00
|
|
|
if (feed == nil) {
|
2012-07-29 20:55:11 -07:00
|
|
|
feed = user;
|
2012-08-06 19:21:39 -07:00
|
|
|
self.isTryFeedView = YES;
|
2012-07-29 20:55:11 -07:00
|
|
|
|
2012-07-28 23:31:12 -07:00
|
|
|
}
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.isSocialView = NO;
|
2012-07-16 22:35:28 -07:00
|
|
|
[self setInFindingStoryMode:NO];
|
|
|
|
}
|
2012-07-29 20:55:11 -07:00
|
|
|
|
2012-11-13 12:28:16 -08:00
|
|
|
self.tryFeedStoryId = contentId;
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFeed = feed;
|
|
|
|
storiesCollection.activeFolder = nil;
|
2012-07-16 19:45:14 -07:00
|
|
|
|
|
|
|
[self loadFeedDetailView];
|
2012-11-09 14:13:44 -08:00
|
|
|
|
|
|
|
if (showHUD) {
|
2013-09-11 17:05:47 -07:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[self.storyPageControl showShareHUD:@"Finding story..."];
|
|
|
|
} else {
|
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.feedDetailViewController.view animated:YES];
|
|
|
|
HUD.labelText = @"Finding story...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)loadStarredDetailViewWithStory:(NSString *)contentId
|
|
|
|
showFindingStory:(BOOL)showHUD {
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
|
|
[self.navigationController popToRootViewControllerAnimated:NO];
|
|
|
|
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
if (self.feedsViewController.popoverController) {
|
|
|
|
[self.feedsViewController.popoverController dismissPopoverAnimated:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.inFindingStoryMode = YES;
|
2014-02-21 12:24:53 -08:00
|
|
|
[storiesCollection reset];
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.isRiverView = YES;
|
2013-09-11 17:05:47 -07:00
|
|
|
|
|
|
|
self.tryFeedStoryId = contentId;
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFolder = @"saved_stories";
|
2013-09-11 17:05:47 -07:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
[self loadRiverFeedDetailView:feedDetailViewController withFolder:@"saved_stories"];
|
2013-09-11 17:05:47 -07:00
|
|
|
|
|
|
|
if (showHUD) {
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[self.storyPageControl showShareHUD:@"Finding story..."];
|
|
|
|
} else {
|
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.feedDetailViewController.view animated:YES];
|
|
|
|
HUD.labelText = @"Finding story...";
|
|
|
|
}
|
2012-11-09 14:13:44 -08:00
|
|
|
}
|
2012-07-16 19:45:14 -07:00
|
|
|
}
|
|
|
|
|
2012-06-26 12:12:31 -07:00
|
|
|
- (BOOL)isSocialFeed:(NSString *)feedIdStr {
|
|
|
|
if ([feedIdStr length] > 6) {
|
|
|
|
NSString *feedIdSubStr = [feedIdStr substringToIndex:6];
|
|
|
|
if ([feedIdSubStr isEqualToString:@"social"]) {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NO;
|
|
|
|
}
|
2012-06-26 12:29:37 -07:00
|
|
|
|
2012-07-02 13:10:00 -07:00
|
|
|
- (BOOL)isPortrait {
|
|
|
|
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
|
|
|
|
if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
|
|
|
|
return YES;
|
|
|
|
} else {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-02 11:28:55 -07:00
|
|
|
- (void)confirmLogout {
|
|
|
|
UIAlertView *logoutConfirm = [[UIAlertView alloc] initWithTitle:@"Positive?"
|
|
|
|
message:nil
|
|
|
|
delegate:self
|
|
|
|
cancelButtonTitle:@"Cancel"
|
|
|
|
otherButtonTitles:@"Logout", nil];
|
|
|
|
[logoutConfirm show];
|
|
|
|
[logoutConfirm setTag:1];
|
|
|
|
}
|
|
|
|
|
2013-03-04 20:21:29 -08:00
|
|
|
- (void)showConnectToService:(NSString *)serviceName {
|
2013-03-05 08:49:37 -08:00
|
|
|
AuthorizeServicesViewController *serviceVC = [[AuthorizeServicesViewController alloc] init];
|
|
|
|
serviceVC.url = [NSString stringWithFormat:@"/oauth/%@_connect", serviceName];
|
|
|
|
serviceVC.type = serviceName;
|
|
|
|
serviceVC.fromStory = YES;
|
2013-03-04 20:21:29 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2013-03-05 08:49:37 -08:00
|
|
|
UINavigationController *connectNav = [[UINavigationController alloc]
|
|
|
|
initWithRootViewController:serviceVC];
|
|
|
|
self.modalNavigationController = connectNav;
|
|
|
|
self.modalNavigationController.modalPresentationStyle = UIModalPresentationFormSheet;
|
2013-09-25 12:05:17 -07:00
|
|
|
self.modalNavigationController.navigationBar.translucent = NO;
|
2013-06-17 11:50:13 -07:00
|
|
|
[self.masterContainerViewController presentViewController:modalNavigationController
|
|
|
|
animated:YES completion:nil];
|
2013-03-04 20:21:29 -08:00
|
|
|
} else {
|
2013-03-05 08:49:37 -08:00
|
|
|
[self.shareNavigationController pushViewController:serviceVC animated:YES];
|
2013-03-04 20:21:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)refreshUserProfile:(void(^)())callback {
|
2013-06-18 21:23:20 -04:00
|
|
|
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/social/load_user_profile",
|
2013-03-04 20:21:29 -08:00
|
|
|
NEWSBLUR_URL]];
|
|
|
|
ASIHTTPRequest *_request = [ASIHTTPRequest requestWithURL:url];
|
|
|
|
__weak ASIHTTPRequest *request = _request;
|
|
|
|
[request setResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setFailedBlock:^(void) {
|
|
|
|
NSLog(@"Failed user profile");
|
|
|
|
callback();
|
|
|
|
}];
|
|
|
|
[request setCompletionBlock:^(void) {
|
|
|
|
NSString *responseString = [request responseString];
|
|
|
|
NSData *responseData=[responseString dataUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSError *error;
|
|
|
|
NSDictionary *results = [NSJSONSerialization
|
|
|
|
JSONObjectWithData:responseData
|
|
|
|
options:kNilOptions
|
|
|
|
error:&error];
|
|
|
|
|
|
|
|
self.dictUserProfile = [results objectForKey:@"user_profile"];
|
|
|
|
self.dictSocialServices = [results objectForKey:@"services"];
|
|
|
|
callback();
|
|
|
|
}];
|
|
|
|
[request setTimeOutSeconds:30];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
2012-07-02 11:28:55 -07:00
|
|
|
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
|
|
|
|
if (alertView.tag == 1) { // this is logout
|
|
|
|
if (buttonIndex == 0) {
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
NSLog(@"Logging out...");
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlS = [NSString stringWithFormat:@"%@/reader/logout?api=1",
|
2012-07-02 11:28:55 -07:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlS];
|
|
|
|
|
|
|
|
__block ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request setResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setDefaultResponseEncoding:NSUTF8StringEncoding];
|
|
|
|
[request setFailedBlock:^(void) {
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
}];
|
|
|
|
[request setCompletionBlock:^(void) {
|
|
|
|
NSLog(@"Logout successful");
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
[self showLogin];
|
|
|
|
}];
|
|
|
|
[request setTimeOutSeconds:30];
|
|
|
|
[request startAsynchronous];
|
|
|
|
|
|
|
|
[ASIHTTPRequest setSessionCookies:nil];
|
|
|
|
|
|
|
|
[MBProgressHUD hideHUDForView:self.view animated:YES];
|
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
|
|
|
|
HUD.labelText = @"Logging out...";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
- (void)loadRiverFeedDetailView:(FeedDetailViewController *)feedDetailView withFolder:(NSString *)folder {
|
2014-02-10 19:21:53 -08:00
|
|
|
self.readStories = [NSMutableArray array];
|
|
|
|
NSMutableArray *feeds = [NSMutableArray array];
|
2014-02-18 18:38:07 -08:00
|
|
|
BOOL transferFromDashboard = [folder isEqualToString:@"river_dashboard"];
|
2014-02-10 19:21:53 -08:00
|
|
|
|
2014-02-18 18:38:07 -08:00
|
|
|
self.inFeedDetail = YES;
|
2014-02-19 18:59:14 -08:00
|
|
|
[feedDetailView resetFeedDetail];
|
|
|
|
if (feedDetailView == dashboardViewController.storiesModule) {
|
|
|
|
feedDetailView.storiesCollection = dashboardViewController.storiesModule.storiesCollection;
|
|
|
|
} else if (feedDetailView == feedDetailViewController) {
|
|
|
|
feedDetailView.storiesCollection = storiesCollection;
|
|
|
|
}
|
2014-02-18 16:44:41 -08:00
|
|
|
|
2014-02-21 12:24:53 -08:00
|
|
|
[feedDetailView.storiesCollection reset];
|
|
|
|
|
2014-02-18 18:38:07 -08:00
|
|
|
if (transferFromDashboard) {
|
|
|
|
StoriesCollection *dashboardCollection = dashboardViewController.storiesModule.storiesCollection;
|
2014-02-21 12:24:53 -08:00
|
|
|
[feedDetailView.storiesCollection transferStoriesFromCollection:dashboardCollection];
|
2014-02-12 20:09:37 -08:00
|
|
|
feedDetailView.storiesCollection.isRiverView = YES;
|
2014-02-21 12:24:53 -08:00
|
|
|
feedDetailView.storiesCollection.transferredFromDashboard = YES;
|
2014-02-18 18:38:07 -08:00
|
|
|
[feedDetailView.storiesCollection setActiveFolder:@"everything"];
|
|
|
|
} else {
|
|
|
|
if ([folder isEqualToString:@"river_global"]) {
|
|
|
|
feedDetailView.storiesCollection.isSocialRiverView = YES;
|
|
|
|
feedDetailView.storiesCollection.isRiverView = YES;
|
|
|
|
[feedDetailView.storiesCollection setActiveFolder:@"river_global"];
|
|
|
|
} else if ([folder isEqualToString:@"river_blurblogs"]) {
|
|
|
|
feedDetailView.storiesCollection.isSocialRiverView = YES;
|
|
|
|
feedDetailView.storiesCollection.isRiverView = YES;
|
|
|
|
// add all the feeds from every NON blurblog folder
|
|
|
|
[feedDetailView.storiesCollection setActiveFolder:@"river_blurblogs"];
|
|
|
|
for (NSString *folderName in self.feedsViewController.activeFeedLocations) {
|
|
|
|
if ([folderName isEqualToString:@"river_blurblogs"]) { // remove all blurblugs which is a blank folder name
|
|
|
|
NSArray *originalFolder = [self.dictFolders objectForKey:folderName];
|
|
|
|
NSArray *folderFeeds = [self.feedsViewController.activeFeedLocations objectForKey:folderName];
|
|
|
|
for (int l=0; l < [folderFeeds count]; l++) {
|
|
|
|
[feeds addObject:[originalFolder objectAtIndex:[[folderFeeds objectAtIndex:l] intValue]]];
|
|
|
|
}
|
2014-02-10 19:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 18:38:07 -08:00
|
|
|
} else if ([folder isEqualToString:@"everything"]) {
|
|
|
|
feedDetailView.storiesCollection.isRiverView = YES;
|
|
|
|
// add all the feeds from every NON blurblog folder
|
|
|
|
[feedDetailView.storiesCollection setActiveFolder:@"everything"];
|
|
|
|
for (NSString *folderName in self.feedsViewController.activeFeedLocations) {
|
|
|
|
if (![folderName isEqualToString:@"river_blurblogs"]) {
|
|
|
|
NSArray *originalFolder = [self.dictFolders objectForKey:folderName];
|
|
|
|
NSArray *folderFeeds = [self.feedsViewController.activeFeedLocations objectForKey:folderName];
|
|
|
|
for (int l=0; l < [folderFeeds count]; l++) {
|
|
|
|
[feeds addObject:[originalFolder objectAtIndex:[[folderFeeds objectAtIndex:l] intValue]]];
|
|
|
|
}
|
2014-02-10 19:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 18:38:07 -08:00
|
|
|
[self.folderCountCache removeAllObjects];
|
|
|
|
} else if ([folder isEqualToString:@"saved_stories"]) {
|
|
|
|
feedDetailView.storiesCollection.isRiverView = YES;
|
|
|
|
[feedDetailView.storiesCollection setActiveFolder:folder];
|
|
|
|
} else {
|
|
|
|
feedDetailView.storiesCollection.isRiverView = YES;
|
|
|
|
NSString *folderName = [self.dictFoldersArray objectAtIndex:[folder intValue]];
|
|
|
|
|
|
|
|
[feedDetailView.storiesCollection setActiveFolder:folderName];
|
|
|
|
NSArray *originalFolder = [self.dictFolders objectForKey:folderName];
|
|
|
|
NSArray *activeFeedLocations = [self.feedsViewController.activeFeedLocations objectForKey:folderName];
|
|
|
|
for (int l=0; l < [activeFeedLocations count]; l++) {
|
|
|
|
[feeds addObject:[originalFolder objectAtIndex:[[activeFeedLocations objectAtIndex:l] intValue]]];
|
|
|
|
}
|
|
|
|
|
2014-02-10 19:21:53 -08:00
|
|
|
}
|
2014-02-18 18:38:07 -08:00
|
|
|
feedDetailView.storiesCollection.activeFolderFeeds = feeds;
|
2014-03-04 18:09:43 -08:00
|
|
|
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
|
|
|
|
if (!self.feedsViewController.viewShowingAllFeeds &&
|
|
|
|
[preferences boolForKey:@"show_feeds_after_being_read"]) {
|
2014-02-18 18:38:07 -08:00
|
|
|
for (id feedId in feeds) {
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", feedId];
|
|
|
|
[self.feedsViewController.stillVisibleFeeds setObject:[NSNumber numberWithBool:YES] forKey:feedIdStr];
|
|
|
|
}
|
2014-02-10 19:21:53 -08:00
|
|
|
}
|
|
|
|
}
|
2014-02-18 18:38:07 -08:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
if (feedDetailView.storiesCollection.activeFolder) {
|
|
|
|
[self.folderCountCache removeObjectForKey:feedDetailView.storiesCollection.activeFolder];
|
|
|
|
}
|
2013-08-06 18:08:55 -07:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
if (feedDetailView == feedDetailViewController) {
|
2014-03-03 12:12:06 -08:00
|
|
|
UIBarButtonItem *newBackButton = [[UIBarButtonItem alloc] initWithTitle: @"All"
|
|
|
|
style: UIBarButtonItemStyleBordered
|
|
|
|
target: nil
|
|
|
|
action: nil];
|
|
|
|
[feedsViewController.navigationItem setBackBarButtonItem: newBackButton];
|
2014-02-10 19:21:53 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[self.masterContainerViewController transitionToFeedDetail];
|
|
|
|
} else {
|
|
|
|
UINavigationController *navController = self.navigationController;
|
|
|
|
[navController pushViewController:feedDetailViewController animated:YES];
|
|
|
|
}
|
|
|
|
}
|
2014-02-27 17:51:56 -08:00
|
|
|
|
|
|
|
if (!transferFromDashboard) {
|
|
|
|
[self flushQueuedReadStories:NO withCallback:^{
|
|
|
|
[feedDetailView fetchRiver];
|
|
|
|
}];
|
|
|
|
} else {
|
|
|
|
[feedDetailView reloadData];
|
|
|
|
}
|
2014-02-10 19:21:53 -08:00
|
|
|
}
|
|
|
|
|
2014-02-18 18:38:07 -08:00
|
|
|
- (void)openDashboardRiverForStory:(NSString *)contentId
|
|
|
|
showFindingStory:(BOOL)showHUD {
|
2014-02-10 19:21:53 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
|
|
[self.navigationController popToRootViewControllerAnimated:NO];
|
|
|
|
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
|
|
|
|
if (self.feedsViewController.popoverController) {
|
|
|
|
[self.feedsViewController.popoverController dismissPopoverAnimated:NO];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
self.inFindingStoryMode = YES;
|
2014-02-21 12:24:53 -08:00
|
|
|
[storiesCollection reset];
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.isRiverView = YES;
|
2014-02-10 19:21:53 -08:00
|
|
|
|
|
|
|
self.tryFeedStoryId = contentId;
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFolder = @"everything";
|
2014-02-10 19:21:53 -08:00
|
|
|
|
2014-02-18 18:38:07 -08:00
|
|
|
[self loadRiverFeedDetailView:feedDetailViewController withFolder:@"river_dashboard"];
|
2014-02-10 19:21:53 -08:00
|
|
|
|
|
|
|
if (showHUD) {
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[self.storyPageControl showShareHUD:@"Finding story..."];
|
|
|
|
} else {
|
|
|
|
MBProgressHUD *HUD = [MBProgressHUD showHUDAddedTo:self.feedDetailViewController.view animated:YES];
|
|
|
|
HUD.labelText = @"Finding story...";
|
|
|
|
}
|
2012-07-24 16:03:16 -07:00
|
|
|
}
|
2012-06-20 07:39:49 -07:00
|
|
|
}
|
|
|
|
|
2012-06-29 21:15:43 -07:00
|
|
|
- (void)adjustStoryDetailWebView {
|
2012-07-12 13:34:41 -07:00
|
|
|
// change UIWebView
|
2012-11-07 17:54:16 -08:00
|
|
|
[storyPageControl.currentPage changeWebViewWidth];
|
|
|
|
[storyPageControl.nextPage changeWebViewWidth];
|
2012-11-14 17:31:52 -08:00
|
|
|
[storyPageControl.previousPage changeWebViewWidth];
|
2012-07-23 15:27:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)calibrateStoryTitles {
|
|
|
|
[self.feedDetailViewController checkScroll];
|
|
|
|
[self.feedDetailViewController changeActiveFeedDetailRow];
|
|
|
|
|
|
|
|
}
|
2012-07-12 13:34:41 -07:00
|
|
|
|
2012-12-12 15:08:24 -08:00
|
|
|
- (void)recalculateIntelligenceScores:(id)feedId {
|
2012-12-13 12:12:00 -08:00
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", feedId];
|
|
|
|
NSMutableArray *newFeedStories = [NSMutableArray array];
|
2012-12-12 15:08:24 -08:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
for (NSDictionary *story in storiesCollection.activeFeedStories) {
|
2012-12-13 12:12:00 -08:00
|
|
|
NSString *storyFeedId = [NSString stringWithFormat:@"%@",
|
|
|
|
[story objectForKey:@"story_feed_id"]];
|
|
|
|
if (![storyFeedId isEqualToString:feedIdStr]) {
|
|
|
|
[newFeedStories addObject:story];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableDictionary *newStory = [story mutableCopy];
|
|
|
|
|
|
|
|
// If the story is visible, mark it as sticky so it doesn;t go away on page loads.
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger score = [NewsBlurAppDelegate computeStoryScore:[story objectForKey:@"intelligence"]];
|
2012-12-13 12:12:00 -08:00
|
|
|
if (score >= self.selectedIntelligence) {
|
|
|
|
[newStory setObject:[NSNumber numberWithBool:YES] forKey:@"sticky"];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSNumber *zero = [NSNumber numberWithInt:0];
|
|
|
|
NSMutableDictionary *intelligence = [NSMutableDictionary
|
|
|
|
dictionaryWithObjects:[NSArray arrayWithObjects:
|
|
|
|
[zero copy], [zero copy],
|
|
|
|
[zero copy], [zero copy], nil]
|
|
|
|
forKeys:[NSArray arrayWithObjects:
|
|
|
|
@"author", @"feed", @"tags", @"title", nil]];
|
2014-02-12 20:09:37 -08:00
|
|
|
NSDictionary *classifiers = [storiesCollection.activeClassifiers objectForKey:feedIdStr];
|
2012-12-13 12:12:00 -08:00
|
|
|
|
|
|
|
for (NSString *title in [classifiers objectForKey:@"titles"]) {
|
|
|
|
if ([[intelligence objectForKey:@"title"] intValue] <= 0 &&
|
|
|
|
[[story objectForKey:@"story_title"] containsString:title]) {
|
|
|
|
int score = [[[classifiers objectForKey:@"titles"] objectForKey:title] intValue];
|
|
|
|
[intelligence setObject:[NSNumber numberWithInt:score] forKey:@"title"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (NSString *author in [classifiers objectForKey:@"authors"]) {
|
|
|
|
if ([[intelligence objectForKey:@"author"] intValue] <= 0 &&
|
2012-12-28 11:34:06 -08:00
|
|
|
[[story objectForKey:@"story_authors"] class] != [NSNull class] &&
|
2012-12-13 12:12:00 -08:00
|
|
|
[[story objectForKey:@"story_authors"] containsString:author]) {
|
|
|
|
int score = [[[classifiers objectForKey:@"authors"] objectForKey:author] intValue];
|
|
|
|
[intelligence setObject:[NSNumber numberWithInt:score] forKey:@"author"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (NSString *tag in [classifiers objectForKey:@"tags"]) {
|
|
|
|
if ([[intelligence objectForKey:@"tags"] intValue] <= 0 &&
|
2012-12-28 11:34:06 -08:00
|
|
|
[[story objectForKey:@"story_tags"] class] != [NSNull class] &&
|
2012-12-13 12:12:00 -08:00
|
|
|
[[story objectForKey:@"story_tags"] containsObject:tag]) {
|
|
|
|
int score = [[[classifiers objectForKey:@"tags"] objectForKey:tag] intValue];
|
|
|
|
[intelligence setObject:[NSNumber numberWithInt:score] forKey:@"tags"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (NSString *feed in [classifiers objectForKey:@"feeds"]) {
|
|
|
|
if ([[intelligence objectForKey:@"feed"] intValue] <= 0 &&
|
2012-12-27 18:37:05 -08:00
|
|
|
[storyFeedId isEqualToString:feed]) {
|
2012-12-13 12:12:00 -08:00
|
|
|
int score = [[[classifiers objectForKey:@"feeds"] objectForKey:feed] intValue];
|
|
|
|
[intelligence setObject:[NSNumber numberWithInt:score] forKey:@"feed"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[newStory setObject:intelligence forKey:@"intelligence"];
|
|
|
|
[newFeedStories addObject:newStory];
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFeedStories = newFeedStories;
|
2012-12-12 15:08:24 -08:00
|
|
|
}
|
|
|
|
|
2012-06-20 19:18:29 -07:00
|
|
|
- (void)changeActiveFeedDetailRow {
|
|
|
|
[feedDetailViewController changeActiveFeedDetailRow];
|
2012-06-18 16:45:36 -07:00
|
|
|
}
|
|
|
|
|
2010-06-25 18:36:01 -04:00
|
|
|
- (void)loadStoryDetailView {
|
2014-02-24 18:35:35 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
|
|
|
|
UINavigationController *navController = self.navigationController;
|
|
|
|
[navController pushViewController:storyPageControl animated:YES];
|
|
|
|
navController.navigationItem.hidesBackButton = YES;
|
2011-10-27 09:44:58 -07:00
|
|
|
}
|
2012-07-20 19:55:38 -07:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
NSInteger activeStoryLocation = [storiesCollection locationOfActiveStory];
|
2012-12-18 17:29:23 -08:00
|
|
|
if (activeStoryLocation >= 0) {
|
|
|
|
BOOL animated = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad &&
|
|
|
|
!self.tryFeedCategory);
|
|
|
|
[self.storyPageControl changePage:activeStoryLocation animated:animated];
|
2014-02-24 18:35:35 -08:00
|
|
|
[self.storyPageControl animateIntoPlace:YES];
|
2012-06-09 12:54:32 -07:00
|
|
|
}
|
2014-02-24 18:35:35 -08:00
|
|
|
|
2013-09-11 17:05:47 -07:00
|
|
|
[MBProgressHUD hideHUDForView:self.storyPageControl.view animated:YES];
|
2012-06-11 16:56:38 -07:00
|
|
|
}
|
|
|
|
|
2011-08-25 12:09:41 -07:00
|
|
|
- (void)navigationController:(UINavigationController *)navController
|
|
|
|
willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
|
2013-03-03 14:03:56 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[viewController viewWillAppear:animated];
|
2011-08-25 12:09:41 -07:00
|
|
|
}
|
2010-06-24 00:22:26 -04:00
|
|
|
}
|
|
|
|
|
2013-03-03 14:03:56 -08:00
|
|
|
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[viewController viewDidAppear:animated];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-11 23:48:27 -05:00
|
|
|
- (void)setTitle:(NSString *)title {
|
|
|
|
UILabel *label = [[UILabel alloc] init];
|
|
|
|
[label setFont:[UIFont boldSystemFontOfSize:16.0]];
|
|
|
|
[label setBackgroundColor:[UIColor clearColor]];
|
2013-02-14 15:36:21 -08:00
|
|
|
[label setTextColor:UIColorFromRGB(0x404040)];
|
2010-11-11 23:48:27 -05:00
|
|
|
[label setText:title];
|
2012-11-13 14:49:53 -08:00
|
|
|
[label setShadowOffset:CGSizeMake(0, -1)];
|
2013-02-14 15:36:21 -08:00
|
|
|
[label setShadowColor:UIColorFromRGB(0xFAFAFA)];
|
2010-11-11 23:48:27 -05:00
|
|
|
[label sizeToFit];
|
|
|
|
[navigationController.navigationBar.topItem setTitleView:label];
|
|
|
|
}
|
2010-06-24 00:22:26 -04:00
|
|
|
|
2012-06-14 10:19:36 -07:00
|
|
|
- (void)showOriginalStory:(NSURL *)url {
|
2013-12-12 15:35:22 -08:00
|
|
|
NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
|
|
|
|
|
|
|
|
if ([[preferences stringForKey:@"story_browser"] isEqualToString:@"safari"]) {
|
|
|
|
[[UIApplication sharedApplication] openURL:url];
|
|
|
|
return;
|
|
|
|
} else if ([[preferences stringForKey:@"story_browser"] isEqualToString:@"chrome"] &&
|
|
|
|
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"googlechrome-x-callback://"]]) {
|
|
|
|
NSString *openingURL = [url.absoluteString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSURL *callbackURL = [NSURL URLWithString:@"newsblur://"];
|
|
|
|
NSString *callback = [callbackURL.absoluteString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
NSString *sourceName = [[[NSBundle mainBundle]objectForInfoDictionaryKey:@"CFBundleName"] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
NSURL *activityURL = [NSURL URLWithString:
|
|
|
|
[NSString stringWithFormat:@"googlechrome-x-callback://x-callback-url/open/?url=%@&x-success=%@&x-source=%@",
|
|
|
|
openingURL,
|
|
|
|
callback,
|
|
|
|
sourceName]];
|
|
|
|
|
|
|
|
[[UIApplication sharedApplication] openURL:activityURL];
|
|
|
|
return;
|
2012-06-29 10:46:26 -07:00
|
|
|
} else {
|
2013-12-12 15:35:22 -08:00
|
|
|
self.activeOriginalStoryURL = url;
|
2014-01-07 18:26:17 -08:00
|
|
|
|
2013-12-12 15:35:22 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2014-01-07 18:26:17 -08:00
|
|
|
[self.masterContainerViewController transitionToOriginalView];
|
2013-12-12 15:35:22 -08:00
|
|
|
} else {
|
2014-01-16 17:15:29 -08:00
|
|
|
if ([[navigationController viewControllers]
|
|
|
|
containsObject:originalStoryViewController]) {
|
2014-01-07 18:26:17 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
[navigationController pushViewController:originalStoryViewController
|
|
|
|
animated:YES];
|
2014-02-05 17:50:19 -08:00
|
|
|
[originalStoryViewController view]; // Force viewDidLoad
|
2014-01-16 17:15:29 -08:00
|
|
|
[originalStoryViewController loadInitialStory];
|
2013-12-12 15:35:22 -08:00
|
|
|
}
|
2012-06-29 10:46:26 -07:00
|
|
|
}
|
2010-11-13 18:32:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)closeOriginalStory {
|
2014-01-07 18:26:17 -08:00
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
|
|
|
[self.masterContainerViewController transitionFromOriginalView];
|
|
|
|
} else {
|
|
|
|
if ([[navigationController viewControllers] containsObject:originalStoryViewController]) {
|
|
|
|
[navigationController popToViewController:storyPageControl animated:YES];
|
|
|
|
}
|
2013-03-04 17:15:50 -08:00
|
|
|
}
|
2010-11-13 18:32:43 -05:00
|
|
|
}
|
2010-06-24 00:22:26 -04:00
|
|
|
|
2012-07-10 12:34:58 -07:00
|
|
|
- (void)hideStoryDetailView {
|
|
|
|
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
|
2012-07-24 16:03:16 -07:00
|
|
|
[self.masterContainerViewController transitionFromFeedDetail];
|
2012-07-11 18:08:07 -07:00
|
|
|
} else {
|
|
|
|
[self.navigationController popViewControllerAnimated:YES];
|
2012-07-10 12:34:58 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-29 17:28:41 -07:00
|
|
|
#pragma mark - Unread Counts
|
|
|
|
|
|
|
|
- (void)populateDictUnreadCounts {
|
|
|
|
self.dictUnreadCounts = [NSMutableDictionary dictionary];
|
|
|
|
|
|
|
|
[self.database inDatabase:^(FMDatabase *db) {
|
|
|
|
FMResultSet *cursor = [db executeQuery:@"SELECT * FROM unread_counts"];
|
|
|
|
|
|
|
|
while ([cursor next]) {
|
|
|
|
NSDictionary *unreadCounts = [cursor resultDictionary];
|
|
|
|
[self.dictUnreadCounts setObject:unreadCounts forKey:[unreadCounts objectForKey:@"feed_id"]];
|
|
|
|
}
|
2013-10-03 18:07:39 -07:00
|
|
|
|
|
|
|
[cursor close];
|
2013-06-29 17:28:41 -07:00
|
|
|
}];
|
|
|
|
}
|
2013-06-21 18:35:06 -07:00
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
- (NSInteger)unreadCount {
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isRiverView || storiesCollection.isSocialRiverView) {
|
2011-10-31 10:10:38 -07:00
|
|
|
return [self unreadCountForFolder:nil];
|
|
|
|
} else {
|
|
|
|
return [self unreadCountForFeed:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
- (NSInteger)allUnreadCount {
|
|
|
|
NSInteger total = 0;
|
2012-07-29 22:14:08 -07:00
|
|
|
for (id key in self.dictSocialFeeds) {
|
|
|
|
NSDictionary *feed = [self.dictSocialFeeds objectForKey:key];
|
2013-09-25 17:43:00 -07:00
|
|
|
total += [[feed objectForKey:@"ps"] integerValue];
|
|
|
|
total += [[feed objectForKey:@"nt"] integerValue];
|
2012-07-29 22:14:08 -07:00
|
|
|
NSLog(@"feed title and number is %@ %i", [feed objectForKey:@"feed_title"], ([[feed objectForKey:@"ps"] intValue] + [[feed objectForKey:@"nt"] intValue]));
|
2013-09-25 17:43:00 -07:00
|
|
|
NSLog(@"total is %ld", (long)total);
|
2012-07-29 22:14:08 -07:00
|
|
|
}
|
|
|
|
|
2013-06-29 17:28:41 -07:00
|
|
|
for (id key in self.dictUnreadCounts) {
|
|
|
|
NSDictionary *feed = [self.dictUnreadCounts objectForKey:key];
|
2012-07-29 22:14:08 -07:00
|
|
|
total += [[feed objectForKey:@"ps"] intValue];
|
|
|
|
total += [[feed objectForKey:@"nt"] intValue];
|
2013-06-29 17:28:41 -07:00
|
|
|
// NSLog(@"feed title and number is %@ %i", [feed objectForKey:@"feed_title"], ([[feed objectForKey:@"ps"] intValue] + [[feed objectForKey:@"nt"] intValue]));
|
|
|
|
// NSLog(@"total is %i", total);
|
2012-07-29 22:14:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
- (NSInteger)unreadCountForFeed:(NSString *)feedId {
|
|
|
|
NSInteger total = 0;
|
2011-10-31 10:10:38 -07:00
|
|
|
NSDictionary *feed;
|
|
|
|
|
|
|
|
if (feedId) {
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
2012-10-07 15:47:21 -04:00
|
|
|
if ([feedIdStr containsString:@"social:"]) {
|
2012-08-01 12:41:02 -07:00
|
|
|
feed = [self.dictSocialFeeds objectForKey:feedIdStr];
|
|
|
|
} else {
|
2013-06-29 17:28:41 -07:00
|
|
|
feed = [self.dictUnreadCounts objectForKey:feedIdStr];
|
2012-08-01 12:41:02 -07:00
|
|
|
}
|
|
|
|
|
2011-10-31 10:10:38 -07:00
|
|
|
} else {
|
2014-02-12 20:09:37 -08:00
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [storiesCollection.activeFeed objectForKey:@"id"]];
|
2013-07-16 19:09:46 -07:00
|
|
|
feed = [self.dictUnreadCounts objectForKey:feedIdStr];
|
2011-10-31 10:10:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
total += [[feed objectForKey:@"ps"] intValue];
|
2011-08-09 17:58:43 -07:00
|
|
|
if ([self selectedIntelligence] <= 0) {
|
2011-10-31 10:10:38 -07:00
|
|
|
total += [[feed objectForKey:@"nt"] intValue];
|
2011-08-09 17:58:43 -07:00
|
|
|
}
|
|
|
|
if ([self selectedIntelligence] <= -1) {
|
2011-10-31 10:10:38 -07:00
|
|
|
total += [[feed objectForKey:@"ng"] intValue];
|
2011-08-09 17:58:43 -07:00
|
|
|
}
|
2011-10-31 10:10:38 -07:00
|
|
|
|
2011-08-09 17:58:43 -07:00
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
- (NSInteger)unreadCountForFolder:(NSString *)folderName {
|
|
|
|
NSInteger total = 0;
|
2011-10-31 10:10:38 -07:00
|
|
|
NSArray *folder;
|
|
|
|
|
2013-02-06 15:15:43 -08:00
|
|
|
if ([folderName isEqual:@"river_blurblogs"] ||
|
2014-02-12 20:09:37 -08:00
|
|
|
(!folderName && [storiesCollection.activeFolder isEqual:@"river_blurblogs"])) {
|
2012-08-13 17:07:26 -07:00
|
|
|
for (id feedId in self.dictSocialFeeds) {
|
|
|
|
total += [self unreadCountForFeed:feedId];
|
|
|
|
}
|
2013-02-06 15:15:43 -08:00
|
|
|
} else if ([folderName isEqual:@"river_global"] ||
|
2014-02-12 20:09:37 -08:00
|
|
|
(!folderName && [storiesCollection.activeFolder isEqual:@"river_global"])) {
|
2012-12-07 15:17:22 -08:00
|
|
|
total = 0;
|
2013-02-06 15:15:43 -08:00
|
|
|
} else if ([folderName isEqual:@"everything"] ||
|
2014-02-12 20:09:37 -08:00
|
|
|
(!folderName && [storiesCollection.activeFolder isEqual:@"everything"])) {
|
2013-06-29 17:28:41 -07:00
|
|
|
for (id feedId in self.dictUnreadCounts) {
|
2011-12-01 09:01:18 -08:00
|
|
|
total += [self unreadCountForFeed:feedId];
|
|
|
|
}
|
2011-10-31 10:10:38 -07:00
|
|
|
} else {
|
2011-12-01 09:01:18 -08:00
|
|
|
if (!folderName) {
|
2014-02-12 20:09:37 -08:00
|
|
|
folder = [self.dictFolders objectForKey:storiesCollection.activeFolder];
|
2011-12-01 09:01:18 -08:00
|
|
|
} else {
|
|
|
|
folder = [self.dictFolders objectForKey:folderName];
|
|
|
|
}
|
2011-10-31 10:10:38 -07:00
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
for (id feedId in folder) {
|
|
|
|
total += [self unreadCountForFeed:feedId];
|
|
|
|
}
|
2011-10-31 10:10:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return total;
|
2011-07-26 08:37:10 -07:00
|
|
|
}
|
|
|
|
|
2012-10-07 15:47:21 -04:00
|
|
|
|
2012-10-12 15:33:40 -04:00
|
|
|
- (UnreadCounts *)splitUnreadCountForFeed:(NSString *)feedId {
|
|
|
|
UnreadCounts *counts = [UnreadCounts alloc];
|
2013-06-29 17:28:41 -07:00
|
|
|
NSDictionary *feedCounts;
|
2012-10-07 15:47:21 -04:00
|
|
|
|
2013-06-29 17:28:41 -07:00
|
|
|
if (!feedId) {
|
2014-02-12 20:09:37 -08:00
|
|
|
feedId = [storiesCollection.activeFeed objectForKey:@"id"];
|
2012-10-07 15:47:21 -04:00
|
|
|
}
|
2013-06-29 17:28:41 -07:00
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", feedId];
|
|
|
|
feedCounts = [self.dictUnreadCounts objectForKey:feedIdStr];
|
2012-10-07 15:47:21 -04:00
|
|
|
|
2013-06-29 17:28:41 -07:00
|
|
|
counts.ps += [[feedCounts objectForKey:@"ps"] intValue];
|
|
|
|
counts.nt += [[feedCounts objectForKey:@"nt"] intValue];
|
|
|
|
counts.ng += [[feedCounts objectForKey:@"ng"] intValue];
|
2012-10-07 15:47:21 -04:00
|
|
|
|
|
|
|
return counts;
|
|
|
|
}
|
|
|
|
|
2012-10-12 15:33:40 -04:00
|
|
|
- (UnreadCounts *)splitUnreadCountForFolder:(NSString *)folderName {
|
|
|
|
UnreadCounts *counts = [UnreadCounts alloc];
|
2012-10-07 15:47:21 -04:00
|
|
|
NSArray *folder;
|
|
|
|
|
2012-10-14 17:30:03 -07:00
|
|
|
if ([[self.folderCountCache objectForKey:folderName] boolValue]) {
|
|
|
|
counts.ps = [[self.folderCountCache objectForKey:[NSString stringWithFormat:@"%@-ps", folderName]] intValue];
|
|
|
|
counts.nt = [[self.folderCountCache objectForKey:[NSString stringWithFormat:@"%@-nt", folderName]] intValue];
|
|
|
|
counts.ng = [[self.folderCountCache objectForKey:[NSString stringWithFormat:@"%@-ng", folderName]] intValue];
|
|
|
|
return counts;
|
|
|
|
}
|
|
|
|
|
2013-02-06 15:15:43 -08:00
|
|
|
if ([folderName isEqual:@"river_blurblogs"] ||
|
2014-02-12 20:09:37 -08:00
|
|
|
(!folderName && [storiesCollection.activeFolder isEqual:@"river_blurblogs"])) {
|
2012-10-07 15:47:21 -04:00
|
|
|
for (id feedId in self.dictSocialFeeds) {
|
|
|
|
[counts addCounts:[self splitUnreadCountForFeed:feedId]];
|
|
|
|
}
|
2013-02-06 15:15:43 -08:00
|
|
|
} else if ([folderName isEqual:@"river_global"] ||
|
2014-02-12 20:09:37 -08:00
|
|
|
(!folderName && [storiesCollection.activeFolder isEqual:@"river_global"])) {
|
2012-12-07 15:17:22 -08:00
|
|
|
// Nothing for global
|
2013-02-06 15:15:43 -08:00
|
|
|
} else if ([folderName isEqual:@"everything"] ||
|
2014-02-12 20:09:37 -08:00
|
|
|
(!folderName && [storiesCollection.activeFolder isEqual:@"everything"])) {
|
2013-02-21 12:19:15 -08:00
|
|
|
for (NSArray *folder in [self.dictFolders allValues]) {
|
|
|
|
for (id feedId in folder) {
|
|
|
|
[counts addCounts:[self splitUnreadCountForFeed:feedId]];
|
|
|
|
}
|
2012-10-07 15:47:21 -04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!folderName) {
|
2014-02-12 20:09:37 -08:00
|
|
|
folder = [self.dictFolders objectForKey:storiesCollection.activeFolder];
|
2012-10-07 15:47:21 -04:00
|
|
|
} else {
|
|
|
|
folder = [self.dictFolders objectForKey:folderName];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (id feedId in folder) {
|
|
|
|
[counts addCounts:[self splitUnreadCountForFeed:feedId]];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-14 17:30:03 -07:00
|
|
|
if (!self.folderCountCache) {
|
|
|
|
self.folderCountCache = [[NSMutableDictionary alloc] init];
|
|
|
|
}
|
|
|
|
[self.folderCountCache setObject:[NSNumber numberWithBool:YES] forKey:folderName];
|
|
|
|
[self.folderCountCache setObject:[NSNumber numberWithInt:counts.ps] forKey:[NSString stringWithFormat:@"%@-ps", folderName]];
|
|
|
|
[self.folderCountCache setObject:[NSNumber numberWithInt:counts.nt] forKey:[NSString stringWithFormat:@"%@-nt", folderName]];
|
|
|
|
[self.folderCountCache setObject:[NSNumber numberWithInt:counts.ng] forKey:[NSString stringWithFormat:@"%@-ng", folderName]];
|
|
|
|
|
2012-10-07 15:47:21 -04:00
|
|
|
return counts;
|
|
|
|
}
|
|
|
|
|
2013-06-29 17:28:41 -07:00
|
|
|
#pragma mark - Story Management
|
|
|
|
|
2011-07-24 20:34:54 -07:00
|
|
|
- (void)markActiveStoryRead {
|
2014-02-12 20:09:37 -08:00
|
|
|
NSInteger activeLocation = [storiesCollection locationOfActiveStory];
|
2011-08-08 09:58:15 -07:00
|
|
|
if (activeLocation == -1) {
|
|
|
|
return;
|
|
|
|
}
|
2012-07-29 20:55:11 -07:00
|
|
|
|
|
|
|
// changes the story layout in story feed detail
|
|
|
|
[self.feedDetailViewController changeActiveStoryTitleCellLayout];
|
2012-08-07 11:27:00 -07:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
NSInteger activeIndex = [[storiesCollection.activeFeedStoryLocations
|
|
|
|
objectAtIndex:activeLocation] intValue];
|
2012-06-29 12:54:52 -07:00
|
|
|
NSDictionary *feed;
|
2012-08-07 11:27:00 -07:00
|
|
|
NSDictionary *friendFeed;
|
2012-07-29 13:24:03 -07:00
|
|
|
id feedId;
|
2012-06-29 13:48:00 -07:00
|
|
|
NSString *feedIdStr;
|
2014-02-12 20:09:37 -08:00
|
|
|
NSDictionary *story = [storiesCollection.activeFeedStories objectAtIndex:activeIndex];
|
2012-08-10 18:10:07 -07:00
|
|
|
NSMutableArray *otherFriendShares = [[self.activeStory objectForKey:@"shared_by_friends"] mutableCopy];
|
|
|
|
NSMutableArray *otherFriendComments = [[self.activeStory objectForKey:@"commented_by_friends"] mutableCopy];
|
2012-06-29 12:54:52 -07:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isSocialView) {
|
2012-06-29 13:48:00 -07:00
|
|
|
feedId = [self.activeStory objectForKey:@"social_user_id"];
|
|
|
|
feedIdStr = [NSString stringWithFormat:@"social:%@",feedId];
|
|
|
|
feed = [self.dictSocialFeeds objectForKey:feedIdStr];
|
|
|
|
|
2012-08-10 18:10:07 -07:00
|
|
|
[otherFriendShares removeObject:feedId];
|
|
|
|
NSLog(@"otherFriendFeeds is %@", otherFriendShares);
|
|
|
|
[otherFriendComments removeObject:feedId];
|
|
|
|
NSLog(@"otherFriendFeeds is %@", otherFriendComments);
|
|
|
|
|
|
|
|
// make sure we set the active feed
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFeed = feed;
|
|
|
|
} else if (storiesCollection.isSocialRiverView &&
|
|
|
|
[[self.activeStory objectForKey:@"friend_user_ids"] count]) {
|
2013-07-24 17:18:46 -07:00
|
|
|
feedId = [[self.activeStory objectForKey:@"friend_user_ids"] objectAtIndex:0];
|
|
|
|
feedIdStr = [NSString stringWithFormat:@"social:%@",feedId];
|
|
|
|
feed = [self.dictSocialFeeds objectForKey:feedIdStr];
|
|
|
|
|
|
|
|
[otherFriendShares removeObject:feedId];
|
|
|
|
NSLog(@"otherFriendFeeds is %@", otherFriendShares);
|
|
|
|
[otherFriendComments removeObject:feedId];
|
|
|
|
NSLog(@"otherFriendFeeds is %@", otherFriendComments);
|
|
|
|
|
|
|
|
// make sure we set the active feed
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFeed = feed;
|
2012-06-29 12:54:52 -07:00
|
|
|
} else {
|
2012-06-29 13:48:00 -07:00
|
|
|
feedId = [self.activeStory objectForKey:@"story_feed_id"];
|
|
|
|
feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
2012-06-29 12:54:52 -07:00
|
|
|
feed = [self.dictFeeds objectForKey:feedIdStr];
|
2012-08-08 12:02:54 -07:00
|
|
|
|
|
|
|
// make sure we set the active feed
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFeed = feed;
|
2011-11-15 09:25:50 -08:00
|
|
|
}
|
2012-06-29 13:48:00 -07:00
|
|
|
|
2012-08-07 11:27:00 -07:00
|
|
|
// decrement all other friend feeds if they have the same story
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isSocialView || storiesCollection.isSocialRiverView) {
|
2012-08-10 18:10:07 -07:00
|
|
|
for (int i = 0; i < otherFriendShares.count; i++) {
|
|
|
|
feedIdStr = [NSString stringWithFormat:@"social:%@",
|
|
|
|
[otherFriendShares objectAtIndex:i]];
|
|
|
|
friendFeed = [self.dictSocialFeeds objectForKey:feedIdStr];
|
2014-02-20 18:23:58 -08:00
|
|
|
[storiesCollection markStoryRead:story feed:friendFeed];
|
2012-08-10 18:10:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < otherFriendComments.count; i++) {
|
2012-06-29 13:48:00 -07:00
|
|
|
feedIdStr = [NSString stringWithFormat:@"social:%@",
|
2012-08-10 18:10:07 -07:00
|
|
|
[otherFriendComments objectAtIndex:i]];
|
2012-08-07 11:27:00 -07:00
|
|
|
friendFeed = [self.dictSocialFeeds objectForKey:feedIdStr];
|
2014-02-20 18:23:58 -08:00
|
|
|
[storiesCollection markStoryRead:story feed:friendFeed];
|
2012-06-29 13:48:00 -07:00
|
|
|
}
|
|
|
|
}
|
2012-06-29 17:37:49 -07:00
|
|
|
|
2014-02-20 18:23:58 -08:00
|
|
|
[storiesCollection markStoryRead:story feed:feed];
|
2014-03-05 14:13:49 -08:00
|
|
|
[storiesCollection syncStoryAsRead:story];
|
2014-02-12 20:09:37 -08:00
|
|
|
self.activeStory = [storiesCollection.activeFeedStories objectAtIndex:activeIndex];
|
2012-10-16 17:24:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markActiveStoryUnread {
|
2014-02-12 20:09:37 -08:00
|
|
|
NSInteger activeLocation = [storiesCollection locationOfActiveStory];
|
2012-10-16 17:24:01 -07:00
|
|
|
if (activeLocation == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// changes the story layout in story feed detail
|
|
|
|
[self.feedDetailViewController changeActiveStoryTitleCellLayout];
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
NSInteger activeIndex = [[storiesCollection.activeFeedStoryLocations
|
|
|
|
objectAtIndex:activeLocation] intValue];
|
2012-10-16 17:24:01 -07:00
|
|
|
NSDictionary *feed;
|
|
|
|
NSDictionary *friendFeed;
|
|
|
|
id feedId;
|
|
|
|
NSString *feedIdStr;
|
2014-02-12 20:09:37 -08:00
|
|
|
NSDictionary *story = [storiesCollection.activeFeedStories objectAtIndex:activeIndex];
|
2012-10-16 17:24:01 -07:00
|
|
|
NSMutableArray *otherFriendShares = [[self.activeStory objectForKey:@"shared_by_friends"] mutableCopy];
|
|
|
|
NSMutableArray *otherFriendComments = [[self.activeStory objectForKey:@"commented_by_friends"] mutableCopy];
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isSocialView) {
|
2012-10-16 17:24:01 -07:00
|
|
|
feedId = [self.activeStory objectForKey:@"social_user_id"];
|
|
|
|
feedIdStr = [NSString stringWithFormat:@"social:%@",feedId];
|
|
|
|
feed = [self.dictSocialFeeds objectForKey:feedIdStr];
|
|
|
|
|
|
|
|
[otherFriendShares removeObject:feedId];
|
|
|
|
NSLog(@"otherFriendFeeds is %@", otherFriendShares);
|
|
|
|
[otherFriendComments removeObject:feedId];
|
|
|
|
NSLog(@"otherFriendFeeds is %@", otherFriendComments);
|
|
|
|
|
|
|
|
// make sure we set the active feed
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFeed = feed;
|
|
|
|
} else if (storiesCollection.isSocialRiverView &&
|
|
|
|
[[self.activeStory objectForKey:@"friend_user_ids"] count]) {
|
2012-10-16 17:24:01 -07:00
|
|
|
feedId = [[self.activeStory objectForKey:@"friend_user_ids"] objectAtIndex:0];
|
|
|
|
feedIdStr = [NSString stringWithFormat:@"social:%@",feedId];
|
|
|
|
feed = [self.dictSocialFeeds objectForKey:feedIdStr];
|
|
|
|
|
|
|
|
[otherFriendShares removeObject:feedId];
|
|
|
|
NSLog(@"otherFriendFeeds is %@", otherFriendShares);
|
|
|
|
[otherFriendComments removeObject:feedId];
|
|
|
|
NSLog(@"otherFriendFeeds is %@", otherFriendComments);
|
|
|
|
|
|
|
|
// make sure we set the active feed
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFeed = feed;
|
2012-10-16 17:24:01 -07:00
|
|
|
} else {
|
|
|
|
feedId = [self.activeStory objectForKey:@"story_feed_id"];
|
|
|
|
feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
|
|
|
feed = [self.dictFeeds objectForKey:feedIdStr];
|
|
|
|
|
|
|
|
// make sure we set the active feed
|
2014-02-12 20:09:37 -08:00
|
|
|
storiesCollection.activeFeed = feed;
|
2012-10-16 17:24:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// decrement all other friend feeds if they have the same story
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isSocialView || storiesCollection.isSocialRiverView) {
|
2012-10-16 17:24:01 -07:00
|
|
|
for (int i = 0; i < otherFriendShares.count; i++) {
|
|
|
|
feedIdStr = [NSString stringWithFormat:@"social:%@",
|
|
|
|
[otherFriendShares objectAtIndex:i]];
|
|
|
|
friendFeed = [self.dictSocialFeeds objectForKey:feedIdStr];
|
2014-02-20 18:23:58 -08:00
|
|
|
[storiesCollection markStoryUnread:story feed:friendFeed];
|
2012-10-16 17:24:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < otherFriendComments.count; i++) {
|
|
|
|
feedIdStr = [NSString stringWithFormat:@"social:%@",
|
|
|
|
[otherFriendComments objectAtIndex:i]];
|
|
|
|
friendFeed = [self.dictSocialFeeds objectForKey:feedIdStr];
|
2014-02-20 18:23:58 -08:00
|
|
|
[storiesCollection markStoryUnread:story feed:friendFeed];
|
2012-10-16 17:24:01 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-20 18:23:58 -08:00
|
|
|
[storiesCollection markStoryUnread:story feed:feed];
|
2012-10-16 17:24:01 -07:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
self.activeStory = [storiesCollection.activeFeedStories objectAtIndex:activeIndex];
|
2011-11-10 18:28:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDictionary *)markVisibleStoriesRead {
|
|
|
|
NSMutableDictionary *feedsStories = [NSMutableDictionary dictionary];
|
2014-02-12 20:09:37 -08:00
|
|
|
for (NSDictionary *story in storiesCollection.activeFeedStories) {
|
2011-11-10 18:28:22 -08:00
|
|
|
if ([[story objectForKey:@"read_status"] intValue] != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",[story objectForKey:@"story_feed_id"]];
|
2013-10-17 17:23:52 -07:00
|
|
|
NSDictionary *feed = [self getFeed:feedIdStr];
|
2011-11-10 18:28:22 -08:00
|
|
|
if (![feedsStories objectForKey:feedIdStr]) {
|
|
|
|
[feedsStories setObject:[NSMutableArray array] forKey:feedIdStr];
|
|
|
|
}
|
|
|
|
NSMutableArray *stories = [feedsStories objectForKey:feedIdStr];
|
2013-08-06 18:08:55 -07:00
|
|
|
[stories addObject:[story objectForKey:@"story_hash"]];
|
2014-02-20 18:23:58 -08:00
|
|
|
[storiesCollection markStoryRead:story feed:feed];
|
2011-11-10 18:28:22 -08:00
|
|
|
}
|
|
|
|
return feedsStories;
|
|
|
|
}
|
|
|
|
|
2013-09-30 16:18:11 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Mark as read
|
2011-07-24 22:23:38 -07:00
|
|
|
|
2011-12-01 09:01:18 -08:00
|
|
|
- (void)markActiveFolderAllRead {
|
2014-02-12 20:09:37 -08:00
|
|
|
if ([storiesCollection.activeFolder isEqual:@"everything"]) {
|
2011-12-01 09:01:18 -08:00
|
|
|
for (NSString *folderName in self.dictFoldersArray) {
|
|
|
|
for (id feedId in [self.dictFolders objectForKey:folderName]) {
|
|
|
|
[self markFeedAllRead:feedId];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2014-02-12 20:09:37 -08:00
|
|
|
for (id feedId in [self.dictFolders objectForKey:storiesCollection.activeFolder]) {
|
2011-12-01 09:01:18 -08:00
|
|
|
[self markFeedAllRead:feedId];
|
|
|
|
}
|
2011-11-09 09:51:42 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-10 18:28:22 -08:00
|
|
|
- (void)markFeedAllRead:(id)feedId {
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@",feedId];
|
2013-06-29 17:28:41 -07:00
|
|
|
NSMutableDictionary *unreadCounts = [NSMutableDictionary dictionary];
|
2011-11-10 18:28:22 -08:00
|
|
|
|
2013-06-29 17:28:41 -07:00
|
|
|
[unreadCounts setValue:[NSNumber numberWithInt:0] forKey:@"ps"];
|
|
|
|
[unreadCounts setValue:[NSNumber numberWithInt:0] forKey:@"nt"];
|
|
|
|
[unreadCounts setValue:[NSNumber numberWithInt:0] forKey:@"ng"];
|
|
|
|
|
|
|
|
[self.dictUnreadCounts setObject:unreadCounts forKey:feedIdStr];
|
2013-09-30 16:18:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markFeedReadInCache:(NSArray *)feedIds {
|
|
|
|
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
|
|
|
|
dispatch_async(queue, ^{
|
|
|
|
[self.database inTransaction:^(FMDatabase *db, BOOL *rollback) {
|
|
|
|
[db executeUpdate:[NSString
|
|
|
|
stringWithFormat:@"UPDATE unread_counts SET ps = 0, nt = 0, ng = 0 "
|
|
|
|
"WHERE feed_id IN (\"%@\")",
|
|
|
|
[feedIds componentsJoinedByString:@"\",\""]]];
|
|
|
|
[db executeUpdate:[NSString
|
|
|
|
stringWithFormat:@"DELETE FROM unread_hashes "
|
|
|
|
"WHERE story_feed_id IN (\"%@\")",
|
|
|
|
[feedIds componentsJoinedByString:@"\",\""]]];
|
|
|
|
}];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-10-08 19:33:11 -07:00
|
|
|
- (void)markFeedReadInCache:(NSArray *)feedIds cutoffTimestamp:(NSInteger)cutoff {
|
|
|
|
for (NSString *feedId in feedIds) {
|
|
|
|
NSDictionary *unreadCounts = [self.dictUnreadCounts objectForKey:feedId];
|
|
|
|
NSMutableDictionary *newUnreadCounts = [unreadCounts mutableCopy];
|
|
|
|
NSMutableArray *stories = [NSMutableArray array];
|
|
|
|
|
|
|
|
[self.database inDatabase:^(FMDatabase *db) {
|
|
|
|
NSString *sql = [NSString stringWithFormat:@"SELECT * FROM stories s "
|
|
|
|
"INNER JOIN unread_hashes uh ON s.story_hash = uh.story_hash "
|
|
|
|
"WHERE s.story_feed_id = %@ AND s.story_timestamp < %ld",
|
|
|
|
feedId, (long)cutoff];
|
|
|
|
FMResultSet *cursor = [db executeQuery:sql];
|
|
|
|
|
|
|
|
while ([cursor next]) {
|
|
|
|
NSDictionary *story = [cursor resultDictionary];
|
|
|
|
[stories addObject:[NSJSONSerialization
|
|
|
|
JSONObjectWithData:[[story objectForKey:@"story_json"]
|
|
|
|
dataUsingEncoding:NSUTF8StringEncoding]
|
|
|
|
options:nil error:nil]];
|
|
|
|
}
|
|
|
|
|
|
|
|
[cursor close];
|
|
|
|
}];
|
|
|
|
|
|
|
|
for (NSDictionary *story in stories) {
|
|
|
|
NSInteger score = [NewsBlurAppDelegate computeStoryScore:[story objectForKey:@"intelligence"]];
|
|
|
|
if (score > 0) {
|
|
|
|
int unreads = MAX(0, [[newUnreadCounts objectForKey:@"ps"] intValue] - 1);
|
|
|
|
[newUnreadCounts setValue:[NSNumber numberWithInt:unreads] forKey:@"ps"];
|
|
|
|
} else if (score == 0) {
|
|
|
|
int unreads = MAX(0, [[newUnreadCounts objectForKey:@"nt"] intValue] - 1);
|
|
|
|
[newUnreadCounts setValue:[NSNumber numberWithInt:unreads] forKey:@"nt"];
|
|
|
|
} else if (score < 0) {
|
|
|
|
int unreads = MAX(0, [[newUnreadCounts objectForKey:@"ng"] intValue] - 1);
|
|
|
|
[newUnreadCounts setValue:[NSNumber numberWithInt:unreads] forKey:@"ng"];
|
|
|
|
}
|
|
|
|
[self.dictUnreadCounts setObject:newUnreadCounts forKey:feedId];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self.database inTransaction:^(FMDatabase *db, BOOL *rollback) {
|
|
|
|
for (NSDictionary *story in stories) {
|
|
|
|
NSMutableDictionary *newStory = [story mutableCopy];
|
|
|
|
[newStory setObject:[NSNumber numberWithInt:1] forKey:@"read_status"];
|
|
|
|
NSString *storyHash = [newStory objectForKey:@"story_hash"];
|
|
|
|
[db executeUpdate:@"UPDATE stories SET story_json = ? WHERE story_hash = ?",
|
|
|
|
[newStory JSONRepresentation],
|
|
|
|
storyHash];
|
|
|
|
}
|
|
|
|
NSString *deleteSql = [NSString
|
|
|
|
stringWithFormat:@"DELETE FROM unread_hashes "
|
|
|
|
"WHERE story_feed_id = \"%@\" "
|
|
|
|
"AND story_timestamp < %ld",
|
|
|
|
feedId, (long)cutoff];
|
|
|
|
[db executeUpdate:deleteSql];
|
|
|
|
[db executeUpdate:@"UPDATE unread_counts SET ps = ?, nt = ?, ng = ? WHERE feed_id = ?",
|
|
|
|
[newUnreadCounts objectForKey:@"ps"],
|
|
|
|
[newUnreadCounts objectForKey:@"nt"],
|
|
|
|
[newUnreadCounts objectForKey:@"ng"],
|
|
|
|
feedId];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)markStoriesRead:(NSDictionary *)stories inFeeds:(NSArray *)feeds cutoffTimestamp:(NSInteger)cutoff {
|
2013-09-30 16:18:11 -07:00
|
|
|
// Must be offline and marking all as read, so load all stories.
|
|
|
|
|
|
|
|
if (stories && [[stories allKeys] count]) {
|
|
|
|
[self queueReadStories:stories];
|
|
|
|
}
|
2013-06-29 17:28:41 -07:00
|
|
|
|
2013-09-30 16:18:11 -07:00
|
|
|
if ([feeds count]) {
|
|
|
|
NSMutableDictionary *feedsStories = [NSMutableDictionary dictionary];
|
|
|
|
|
|
|
|
[self.database inDatabase:^(FMDatabase *db) {
|
|
|
|
NSString *sql = [NSString stringWithFormat:@"SELECT u.story_feed_id, u.story_hash "
|
|
|
|
"FROM unread_hashes u WHERE u.story_feed_id IN (\"%@\")",
|
|
|
|
[feeds componentsJoinedByString:@"\",\""]];
|
2013-10-08 19:33:11 -07:00
|
|
|
if (cutoff) {
|
|
|
|
sql = [NSString stringWithFormat:@"%@ AND u.story_timestamp < %ld", sql, (long)cutoff];
|
|
|
|
}
|
2013-09-30 16:18:11 -07:00
|
|
|
FMResultSet *cursor = [db executeQuery:sql];
|
|
|
|
|
|
|
|
while ([cursor next]) {
|
|
|
|
NSDictionary *story = [cursor resultDictionary];
|
|
|
|
NSString *feedIdStr = [story objectForKey:@"story_feed_id"];
|
|
|
|
NSString *storyHash = [story objectForKey:@"story_hash"];
|
|
|
|
|
|
|
|
if (![feedsStories objectForKey:feedIdStr]) {
|
|
|
|
[feedsStories setObject:[NSMutableArray array] forKey:feedIdStr];
|
|
|
|
}
|
|
|
|
|
|
|
|
NSMutableArray *stories = [feedsStories objectForKey:feedIdStr];
|
|
|
|
[stories addObject:storyHash];
|
|
|
|
}
|
2013-10-03 18:07:39 -07:00
|
|
|
|
|
|
|
[cursor close];
|
2013-09-30 16:18:11 -07:00
|
|
|
}];
|
|
|
|
[self queueReadStories:feedsStories];
|
2013-10-08 19:33:11 -07:00
|
|
|
if (cutoff) {
|
|
|
|
[self markFeedReadInCache:[feedsStories allKeys] cutoffTimestamp:cutoff];
|
|
|
|
} else {
|
|
|
|
for (NSString *feedId in [feedsStories allKeys]) {
|
|
|
|
[self markFeedAllRead:feedId];
|
|
|
|
}
|
|
|
|
[self markFeedReadInCache:[feedsStories allKeys]];
|
2013-09-30 16:18:11 -07:00
|
|
|
}
|
|
|
|
}
|
2011-11-10 18:28:22 -08:00
|
|
|
}
|
|
|
|
|
2013-09-30 16:18:11 -07:00
|
|
|
- (void)requestFailedMarkStoryRead:(ASIFormDataRequest *)request {
|
|
|
|
// [self informError:@"Failed to mark story as read"];
|
|
|
|
NSArray *feedIds = [request.userInfo objectForKey:@"feeds"];
|
|
|
|
NSDictionary *stories = [request.userInfo objectForKey:@"stories"];
|
|
|
|
|
2013-10-08 19:33:11 -07:00
|
|
|
[self markStoriesRead:stories inFeeds:feedIds cutoffTimestamp:nil];
|
2013-09-30 16:18:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishMarkAllAsRead:(ASIFormDataRequest *)request {
|
|
|
|
if (request.responseStatusCode != 200) {
|
|
|
|
[self requestFailedMarkStoryRead:request];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 14:13:49 -08:00
|
|
|
- (void)finishMarkAsRead:(NSDictionary *)story {
|
|
|
|
for (StoryDetailViewController *page in @[storyPageControl.previousPage,
|
|
|
|
storyPageControl.currentPage,
|
|
|
|
storyPageControl.nextPage]) {
|
2014-03-05 15:20:31 -08:00
|
|
|
if ([[page.activeStory objectForKey:@"story_hash"]
|
|
|
|
isEqualToString:[story objectForKey:@"story_hash"]]) {
|
2014-03-05 14:13:49 -08:00
|
|
|
page.isRecentlyUnread = NO;
|
|
|
|
[storyPageControl refreshHeaders];
|
|
|
|
}
|
2014-03-03 16:21:26 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 14:13:49 -08:00
|
|
|
- (void)finishMarkAsUnread:(NSDictionary *)story {
|
|
|
|
for (StoryDetailViewController *page in @[storyPageControl.previousPage,
|
|
|
|
storyPageControl.currentPage,
|
|
|
|
storyPageControl.nextPage]) {
|
2014-03-05 15:20:31 -08:00
|
|
|
if ([[page.activeStory objectForKey:@"story_hash"]
|
|
|
|
isEqualToString:[story objectForKey:@"story_hash"]]) {
|
2014-03-05 14:13:49 -08:00
|
|
|
page.isRecentlyUnread = YES;
|
|
|
|
[storyPageControl refreshHeaders];
|
|
|
|
}
|
|
|
|
}
|
2014-03-05 15:29:22 -08:00
|
|
|
[storyPageControl setNextPreviousButtons];
|
|
|
|
originalStoryCount += 1;
|
2014-03-05 14:13:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)failedMarkAsUnread:(ASIFormDataRequest *)request {
|
|
|
|
if (![storyPageControl failedMarkAsUnread:request]) {
|
|
|
|
[feedDetailViewController failedMarkAsUnread:request];
|
|
|
|
}
|
|
|
|
[feedDetailViewController reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishMarkAsSaved:(ASIFormDataRequest *)request {
|
|
|
|
[storyPageControl finishMarkAsSaved:request];
|
|
|
|
[feedDetailViewController finishMarkAsSaved:request];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)failedMarkAsSaved:(ASIFormDataRequest *)request {
|
|
|
|
if (![storyPageControl failedMarkAsSaved:request]) {
|
|
|
|
[feedDetailViewController failedMarkAsSaved:request];
|
|
|
|
}
|
|
|
|
[feedDetailViewController reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)finishMarkAsUnsaved:(ASIFormDataRequest *)request {
|
|
|
|
[storyPageControl finishMarkAsUnsaved:request];
|
|
|
|
[feedDetailViewController finishMarkAsUnsaved:request];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)failedMarkAsUnsaved:(ASIFormDataRequest *)request {
|
|
|
|
if (![storyPageControl failedMarkAsUnsaved:request]) {
|
|
|
|
[feedDetailViewController failedMarkAsUnsaved:request];
|
2014-03-03 16:21:26 -08:00
|
|
|
}
|
2014-03-05 14:13:49 -08:00
|
|
|
[feedDetailViewController reloadData];
|
2014-03-03 16:21:26 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-30 16:18:11 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Story functions
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
+ (NSInteger)computeStoryScore:(NSDictionary *)intelligence {
|
|
|
|
NSInteger score = 0;
|
2011-07-26 08:37:10 -07:00
|
|
|
int title = [[intelligence objectForKey:@"title"] intValue];
|
|
|
|
int author = [[intelligence objectForKey:@"author"] intValue];
|
|
|
|
int tags = [[intelligence objectForKey:@"tags"] intValue];
|
|
|
|
|
|
|
|
int score_max = MAX(title, MAX(author, tags));
|
|
|
|
int score_min = MIN(title, MIN(author, tags));
|
2011-07-24 20:07:38 -07:00
|
|
|
|
|
|
|
if (score_max > 0) score = score_max;
|
|
|
|
else if (score_min < 0) score = score_min;
|
2010-11-22 10:44:52 -05:00
|
|
|
|
2011-07-24 20:07:38 -07:00
|
|
|
if (score == 0) score = [[intelligence objectForKey:@"feed"] integerValue];
|
|
|
|
|
2011-07-29 09:06:17 -07:00
|
|
|
// NSLog(@"%d/%d -- %d: %@", score_max, score_min, score, intelligence);
|
2010-11-22 10:44:52 -05:00
|
|
|
return score;
|
|
|
|
}
|
|
|
|
|
2013-06-29 17:28:41 -07:00
|
|
|
#pragma mark - Feed Management
|
2011-12-04 21:09:16 -08:00
|
|
|
|
|
|
|
- (NSString *)extractParentFolderName:(NSString *)folderName {
|
2012-10-15 14:57:20 -07:00
|
|
|
if ([folderName containsString:@"Top Level"] ||
|
2013-02-06 15:15:43 -08:00
|
|
|
[folderName isEqual:@"everything"]) {
|
2011-12-04 21:09:16 -08:00
|
|
|
folderName = @"";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([folderName containsString:@" - "]) {
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger lastFolderLoc = [folderName rangeOfString:@" - "
|
|
|
|
options:NSBackwardsSearch].location;
|
2011-12-04 21:09:16 -08:00
|
|
|
folderName = [folderName substringToIndex:lastFolderLoc];
|
|
|
|
} else {
|
|
|
|
folderName = @"— Top Level —";
|
|
|
|
}
|
|
|
|
|
|
|
|
return folderName;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)extractFolderName:(NSString *)folderName {
|
2012-10-15 14:57:20 -07:00
|
|
|
if ([folderName containsString:@"Top Level"] ||
|
2013-02-06 15:15:43 -08:00
|
|
|
[folderName isEqual:@"everything"]) {
|
2011-12-04 21:09:16 -08:00
|
|
|
folderName = @"";
|
|
|
|
}
|
|
|
|
if ([folderName containsString:@" - "]) {
|
2013-09-25 17:43:00 -07:00
|
|
|
NSInteger folder_loc = [folderName rangeOfString:@" - "
|
|
|
|
options:NSBackwardsSearch].location;
|
2011-12-04 21:09:16 -08:00
|
|
|
folderName = [folderName substringFromIndex:(folder_loc + 3)];
|
|
|
|
}
|
|
|
|
|
|
|
|
return folderName;
|
|
|
|
}
|
|
|
|
|
2012-12-28 11:34:06 -08:00
|
|
|
- (NSDictionary *)getFeed:(NSString *)feedId {
|
|
|
|
NSDictionary *feed;
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isSocialView ||
|
|
|
|
storiesCollection.isSocialRiverView ||
|
|
|
|
[feedId startsWith:@"social:"]) {
|
2012-12-28 11:34:06 -08:00
|
|
|
feed = [self.dictActiveFeeds objectForKey:feedId];
|
|
|
|
// this is to catch when a user is already subscribed
|
2013-12-12 18:03:56 -08:00
|
|
|
if (!feed) {
|
|
|
|
feed = [self.dictSocialFeeds objectForKey:feedId];
|
|
|
|
}
|
2012-12-28 11:34:06 -08:00
|
|
|
if (!feed) {
|
|
|
|
feed = [self.dictFeeds objectForKey:feedId];
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
feed = [self.dictFeeds objectForKey:feedId];
|
|
|
|
}
|
|
|
|
|
|
|
|
return feed;
|
|
|
|
}
|
|
|
|
|
2014-03-05 14:13:49 -08:00
|
|
|
- (NSDictionary *)getStory:(NSString *)storyHash {
|
|
|
|
for (NSDictionary *story in storiesCollection.activeFeedStories) {
|
|
|
|
if ([[story objectForKey:@"story_hash"] isEqualToString:storyHash]) {
|
|
|
|
return story;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2011-12-04 21:09:16 -08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Feed Templates
|
|
|
|
|
2013-02-21 12:19:15 -08:00
|
|
|
+ (void)fillGradient:(CGRect)r startColor:(UIColor *)startColor endColor:(UIColor *)endColor {
|
|
|
|
CGContextRef context = UIGraphicsGetCurrentContext();
|
|
|
|
UIGraphicsPushContext(context);
|
|
|
|
|
|
|
|
CGGradientRef gradient;
|
2013-02-14 15:36:21 -08:00
|
|
|
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
|
|
|
|
CGFloat locations[2] = {0.0f, 1.0f};
|
|
|
|
CGFloat startRed, startGreen, startBlue, startAlpha;
|
|
|
|
CGFloat endRed, endGreen, endBlue, endAlpha;
|
|
|
|
|
|
|
|
[startColor getRed:&startRed green:&startGreen blue:&startBlue alpha:&startAlpha];
|
|
|
|
[endColor getRed:&endRed green:&endGreen blue:&endBlue alpha:&endAlpha];
|
|
|
|
|
|
|
|
CGFloat components[8] = {
|
|
|
|
startRed, startGreen, startBlue, startAlpha,
|
|
|
|
endRed, endGreen, endBlue, endAlpha
|
|
|
|
};
|
2013-02-21 12:19:15 -08:00
|
|
|
gradient = CGGradientCreateWithColorComponents(colorSpace, components, locations, 2);
|
2013-02-14 15:36:21 -08:00
|
|
|
CGColorSpaceRelease(colorSpace);
|
2013-02-15 16:41:20 -08:00
|
|
|
|
2013-02-14 15:36:21 -08:00
|
|
|
CGPoint startPoint = CGPointMake(CGRectGetMinX(r), r.origin.y);
|
|
|
|
CGPoint endPoint = CGPointMake(startPoint.x, r.origin.y + r.size.height);
|
|
|
|
|
|
|
|
CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, 0);
|
2013-02-21 12:19:15 -08:00
|
|
|
CGGradientRelease(gradient);
|
2013-02-14 15:36:21 -08:00
|
|
|
UIGraphicsPopContext();
|
|
|
|
}
|
|
|
|
|
2011-10-27 19:05:38 -07:00
|
|
|
+ (UIView *)makeGradientView:(CGRect)rect startColor:(NSString *)start endColor:(NSString *)end {
|
2012-07-15 15:06:06 -07:00
|
|
|
UIView *gradientView = [[UIView alloc] initWithFrame:rect];
|
2011-10-27 19:05:38 -07:00
|
|
|
|
|
|
|
CAGradientLayer *gradient = [CAGradientLayer layer];
|
2011-10-30 18:53:10 -07:00
|
|
|
gradient.frame = CGRectMake(0, 1, rect.size.width, rect.size.height-1);
|
2012-06-10 13:21:07 -07:00
|
|
|
gradient.opacity = 0.7;
|
2011-10-27 19:05:38 -07:00
|
|
|
unsigned int color = 0;
|
|
|
|
unsigned int colorFade = 0;
|
|
|
|
if ([start class] == [NSNull class]) {
|
|
|
|
start = @"505050";
|
|
|
|
}
|
|
|
|
if ([end class] == [NSNull class]) {
|
|
|
|
end = @"303030";
|
|
|
|
}
|
|
|
|
NSScanner *scanner = [NSScanner scannerWithString:start];
|
|
|
|
[scanner scanHexInt:&color];
|
|
|
|
NSScanner *scannerFade = [NSScanner scannerWithString:end];
|
|
|
|
[scannerFade scanHexInt:&colorFade];
|
|
|
|
gradient.colors = [NSArray arrayWithObjects:(id)[UIColorFromRGB(color) CGColor], (id)[UIColorFromRGB(colorFade) CGColor], nil];
|
2011-10-28 18:29:33 -07:00
|
|
|
|
|
|
|
CALayer *whiteBackground = [CALayer layer];
|
2011-10-30 18:53:10 -07:00
|
|
|
whiteBackground.frame = CGRectMake(0, 1, rect.size.width, rect.size.height-1);
|
2012-06-10 13:21:07 -07:00
|
|
|
whiteBackground.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.7].CGColor;
|
2011-10-28 18:29:33 -07:00
|
|
|
[gradientView.layer addSublayer:whiteBackground];
|
|
|
|
|
2011-10-27 19:05:38 -07:00
|
|
|
[gradientView.layer addSublayer:gradient];
|
2011-10-28 18:29:33 -07:00
|
|
|
|
|
|
|
CALayer *topBorder = [CALayer layer];
|
2011-10-30 18:53:10 -07:00
|
|
|
topBorder.frame = CGRectMake(0, 1, rect.size.width, 1);
|
2012-06-10 13:21:07 -07:00
|
|
|
topBorder.backgroundColor = [UIColorFromRGB(colorFade) colorWithAlphaComponent:0.7].CGColor;
|
2011-10-30 15:06:25 -07:00
|
|
|
topBorder.opacity = 1;
|
2011-10-28 18:29:33 -07:00
|
|
|
[gradientView.layer addSublayer:topBorder];
|
|
|
|
|
|
|
|
CALayer *bottomBorder = [CALayer layer];
|
|
|
|
bottomBorder.frame = CGRectMake(0, rect.size.height-1, rect.size.width, 1);
|
2012-06-10 13:21:07 -07:00
|
|
|
bottomBorder.backgroundColor = [UIColorFromRGB(colorFade) colorWithAlphaComponent:0.7].CGColor;
|
2011-10-30 15:06:25 -07:00
|
|
|
bottomBorder.opacity = 1;
|
2011-10-28 18:29:33 -07:00
|
|
|
[gradientView.layer addSublayer:bottomBorder];
|
|
|
|
|
|
|
|
return gradientView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIView *)makeFeedTitleGradient:(NSDictionary *)feed withRect:(CGRect)rect {
|
|
|
|
UIView *gradientView;
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isRiverView ||
|
|
|
|
storiesCollection.isSocialView ||
|
|
|
|
storiesCollection.isSocialRiverView) {
|
2011-10-28 18:29:33 -07:00
|
|
|
gradientView = [NewsBlurAppDelegate
|
|
|
|
makeGradientView:rect
|
2012-06-30 21:28:48 -07:00
|
|
|
startColor:[feed objectForKey:@"favicon_fade"]
|
|
|
|
endColor:[feed objectForKey:@"favicon_color"]];
|
2011-10-28 18:29:33 -07:00
|
|
|
|
2012-07-15 15:06:06 -07:00
|
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
2011-10-28 18:29:33 -07:00
|
|
|
titleLabel.text = [feed objectForKey:@"feed_title"];
|
|
|
|
titleLabel.backgroundColor = [UIColor clearColor];
|
2013-06-17 11:50:13 -07:00
|
|
|
titleLabel.textAlignment = NSTextAlignmentLeft;
|
|
|
|
titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
2011-12-04 21:09:16 -08:00
|
|
|
titleLabel.numberOfLines = 1;
|
2011-10-28 18:29:33 -07:00
|
|
|
titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:11.0];
|
|
|
|
titleLabel.shadowOffset = CGSizeMake(0, 1);
|
|
|
|
if ([[feed objectForKey:@"favicon_text_color"] class] != [NSNull class]) {
|
2011-11-30 18:46:11 -08:00
|
|
|
titleLabel.textColor = [[feed objectForKey:@"favicon_text_color"]
|
|
|
|
isEqualToString:@"white"] ?
|
2012-06-30 21:28:48 -07:00
|
|
|
[UIColor whiteColor] :
|
|
|
|
[UIColor blackColor];
|
2011-11-30 18:46:11 -08:00
|
|
|
titleLabel.shadowColor = [[feed objectForKey:@"favicon_text_color"]
|
|
|
|
isEqualToString:@"white"] ?
|
2012-06-30 21:28:48 -07:00
|
|
|
UIColorFromRGB(0x202020) :
|
|
|
|
UIColorFromRGB(0xd0d0d0);
|
2011-10-28 18:29:33 -07:00
|
|
|
} else {
|
|
|
|
titleLabel.textColor = [UIColor whiteColor];
|
|
|
|
titleLabel.shadowColor = [UIColor blackColor];
|
|
|
|
}
|
2011-12-04 21:09:16 -08:00
|
|
|
titleLabel.frame = CGRectMake(32, 1, rect.size.width-32, 20);
|
2011-10-28 18:29:33 -07:00
|
|
|
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [feed objectForKey:@"id"]];
|
2014-02-24 18:56:51 -08:00
|
|
|
UIImage *titleImage = [self getFavicon:feedIdStr];
|
2011-10-28 18:29:33 -07:00
|
|
|
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:titleImage];
|
2011-10-30 18:53:10 -07:00
|
|
|
titleImageView.frame = CGRectMake(8, 3, 16.0, 16.0);
|
2011-10-28 18:29:33 -07:00
|
|
|
[titleLabel addSubview:titleImageView];
|
|
|
|
|
|
|
|
[gradientView addSubview:titleLabel];
|
|
|
|
[gradientView addSubview:titleImageView];
|
|
|
|
} else {
|
|
|
|
gradientView = [NewsBlurAppDelegate
|
2012-11-06 17:26:08 -08:00
|
|
|
makeGradientView:CGRectMake(0, -1, rect.size.width, 10)
|
2012-06-22 21:53:45 -07:00
|
|
|
// hard coding the 1024 as a hack for window.frame.size.width
|
2012-06-30 21:28:48 -07:00
|
|
|
startColor:[feed objectForKey:@"favicon_fade"]
|
|
|
|
endColor:[feed objectForKey:@"favicon_color"]];
|
2011-10-28 18:29:33 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gradientView.opaque = YES;
|
|
|
|
|
2011-10-27 19:05:38 -07:00
|
|
|
return gradientView;
|
|
|
|
}
|
2011-08-18 09:56:52 -07:00
|
|
|
|
2011-12-02 16:23:00 -08:00
|
|
|
- (UIView *)makeFeedTitle:(NSDictionary *)feed {
|
2012-07-15 15:06:06 -07:00
|
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isSocialRiverView &&
|
|
|
|
[storiesCollection.activeFolder isEqualToString:@"river_blurblogs"]) {
|
2012-10-03 15:46:02 -07:00
|
|
|
titleLabel.text = [NSString stringWithFormat:@" All Shared Stories"];
|
2014-02-12 20:09:37 -08:00
|
|
|
} else if (storiesCollection.isSocialRiverView &&
|
|
|
|
[storiesCollection.activeFolder isEqualToString:@"river_global"]) {
|
2012-12-07 15:17:22 -08:00
|
|
|
titleLabel.text = [NSString stringWithFormat:@" Global Shared Stories"];
|
2014-02-12 20:09:37 -08:00
|
|
|
} else if (storiesCollection.isRiverView &&
|
|
|
|
[storiesCollection.activeFolder isEqualToString:@"everything"]) {
|
2012-10-03 15:46:02 -07:00
|
|
|
titleLabel.text = [NSString stringWithFormat:@" All Stories"];
|
2014-02-12 20:09:37 -08:00
|
|
|
} else if (storiesCollection.isRiverView &&
|
|
|
|
[storiesCollection.activeFolder isEqualToString:@"saved_stories"]) {
|
2012-10-17 15:07:53 -07:00
|
|
|
titleLabel.text = [NSString stringWithFormat:@" Saved Stories"];
|
2014-02-12 20:09:37 -08:00
|
|
|
} else if (storiesCollection.isRiverView) {
|
|
|
|
titleLabel.text = [NSString stringWithFormat:@" %@", storiesCollection.activeFolder];
|
|
|
|
} else if (storiesCollection.isSocialView) {
|
2012-07-12 22:05:23 -07:00
|
|
|
titleLabel.text = [NSString stringWithFormat:@" %@", [feed objectForKey:@"feed_title"]];
|
2011-12-02 16:23:00 -08:00
|
|
|
} else {
|
|
|
|
titleLabel.text = [NSString stringWithFormat:@" %@", [feed objectForKey:@"feed_title"]];
|
|
|
|
}
|
|
|
|
titleLabel.backgroundColor = [UIColor clearColor];
|
2013-06-17 11:50:13 -07:00
|
|
|
titleLabel.textAlignment = NSTextAlignmentLeft;
|
2011-12-02 16:23:00 -08:00
|
|
|
titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0];
|
2013-09-24 17:18:20 -07:00
|
|
|
titleLabel.textColor = UIColorFromRGB(0x4D4C4A);
|
2013-06-17 11:50:13 -07:00
|
|
|
titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
|
2011-12-04 21:09:16 -08:00
|
|
|
titleLabel.numberOfLines = 1;
|
2013-09-24 17:18:20 -07:00
|
|
|
titleLabel.shadowColor = UIColorFromRGB(0xF0F0F0);
|
|
|
|
titleLabel.shadowOffset = CGSizeMake(0, 1);
|
2012-07-12 22:05:23 -07:00
|
|
|
titleLabel.center = CGPointMake(0, -2);
|
2014-02-12 20:09:37 -08:00
|
|
|
if (!storiesCollection.isSocialView) {
|
2012-07-12 22:05:23 -07:00
|
|
|
titleLabel.center = CGPointMake(28, -2);
|
|
|
|
NSString *feedIdStr = [NSString stringWithFormat:@"%@", [feed objectForKey:@"id"]];
|
|
|
|
UIImage *titleImage;
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isSocialRiverView &&
|
|
|
|
[storiesCollection.activeFolder isEqualToString:@"river_global"]) {
|
2013-02-21 12:19:15 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"ak-icon-global.png"];
|
2014-02-12 20:09:37 -08:00
|
|
|
} else if (storiesCollection.isSocialRiverView &&
|
|
|
|
[storiesCollection.activeFolder isEqualToString:@"river_blurblogs"]) {
|
2013-02-21 12:19:15 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"ak-icon-blurblogs.png"];
|
2014-02-12 20:09:37 -08:00
|
|
|
} else if (storiesCollection.isRiverView &&
|
|
|
|
[storiesCollection.activeFolder isEqualToString:@"everything"]) {
|
2013-02-21 12:19:15 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"ak-icon-allstories.png"];
|
2014-02-12 20:09:37 -08:00
|
|
|
} else if (storiesCollection.isRiverView &&
|
|
|
|
[storiesCollection.activeFolder isEqualToString:@"saved_stories"]) {
|
2013-03-07 10:55:23 -05:00
|
|
|
titleImage = [UIImage imageNamed:@"clock.png"];
|
2014-02-12 20:09:37 -08:00
|
|
|
} else if (storiesCollection.isRiverView) {
|
2013-02-21 14:44:34 -08:00
|
|
|
titleImage = [UIImage imageNamed:@"g_icn_folder.png"];
|
2012-07-12 22:05:23 -07:00
|
|
|
} else {
|
2014-02-24 18:56:51 -08:00
|
|
|
titleImage = [self getFavicon:feedIdStr];
|
2012-07-12 22:05:23 -07:00
|
|
|
}
|
|
|
|
UIImageView *titleImageView = [[UIImageView alloc] initWithImage:titleImage];
|
|
|
|
titleImageView.frame = CGRectMake(0.0, 2.0, 16.0, 16.0);
|
|
|
|
[titleLabel addSubview:titleImageView];
|
|
|
|
}
|
2013-10-11 17:46:09 -07:00
|
|
|
[titleLabel sizeToFit];
|
2012-07-12 22:05:23 -07:00
|
|
|
|
2013-10-11 17:46:09 -07:00
|
|
|
return titleLabel;
|
2011-12-02 16:23:00 -08:00
|
|
|
}
|
|
|
|
|
2014-02-24 18:56:51 -08:00
|
|
|
- (void)saveFavicon:(UIImage *)image feedId:(NSString *)filename {
|
|
|
|
if (image && filename && ![image isKindOfClass:[NSNull class]] &&
|
|
|
|
[filename class] != [NSNull class]) {
|
2014-03-03 22:36:40 -08:00
|
|
|
[self.cachedFavicons setObject:image forKey:filename];
|
2014-02-24 18:56:51 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIImage *)getFavicon:(NSString *)filename {
|
|
|
|
return [self getFavicon:filename isSocial:NO];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (UIImage *)getFavicon:(NSString *)filename isSocial:(BOOL)isSocial {
|
|
|
|
UIImage *image = [self.cachedFavicons objectForKey:filename];
|
|
|
|
|
|
|
|
if (image) {
|
|
|
|
return image;
|
|
|
|
} else {
|
|
|
|
if (isSocial) {
|
|
|
|
// return [UIImage imageNamed:@"user_light.png"];
|
|
|
|
return nil;
|
|
|
|
} else {
|
|
|
|
return [UIImage imageNamed:@"world.png"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-27 18:37:05 -08:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Classifiers
|
|
|
|
|
|
|
|
- (void)toggleAuthorClassifier:(NSString *)author feedId:(NSString *)feedId {
|
2014-02-12 20:09:37 -08:00
|
|
|
int authorScore = [[[[storiesCollection.activeClassifiers objectForKey:feedId]
|
2012-12-27 18:37:05 -08:00
|
|
|
objectForKey:@"authors"]
|
|
|
|
objectForKey:author] intValue];
|
|
|
|
if (authorScore > 0) {
|
|
|
|
authorScore = -1;
|
|
|
|
} else if (authorScore < 0) {
|
|
|
|
authorScore = 0;
|
|
|
|
} else {
|
|
|
|
authorScore = 1;
|
|
|
|
}
|
2014-02-12 20:09:37 -08:00
|
|
|
NSMutableDictionary *feedClassifiers = [[storiesCollection.activeClassifiers objectForKey:feedId]
|
2012-12-27 18:37:05 -08:00
|
|
|
mutableCopy];
|
2013-09-05 17:07:21 -07:00
|
|
|
if (!feedClassifiers) feedClassifiers = [NSMutableDictionary dictionary];
|
2012-12-27 18:37:05 -08:00
|
|
|
NSMutableDictionary *authors = [[feedClassifiers objectForKey:@"authors"] mutableCopy];
|
2013-09-05 17:07:21 -07:00
|
|
|
if (!authors) authors = [NSMutableDictionary dictionary];
|
2012-12-27 18:37:05 -08:00
|
|
|
[authors setObject:[NSNumber numberWithInt:authorScore] forKey:author];
|
|
|
|
[feedClassifiers setObject:authors forKey:@"authors"];
|
2014-02-12 20:09:37 -08:00
|
|
|
[storiesCollection.activeClassifiers setObject:feedClassifiers forKey:feedId];
|
2012-12-27 18:37:05 -08:00
|
|
|
[self.storyPageControl refreshHeaders];
|
|
|
|
[self.trainerViewController refresh];
|
|
|
|
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/classifier/save",
|
2012-12-27 18:37:05 -08:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2013-09-05 17:07:21 -07:00
|
|
|
__weak ASIFormDataRequest *_request = request;
|
2012-12-27 18:37:05 -08:00
|
|
|
[request setPostValue:author
|
|
|
|
forKey:authorScore >= 1 ? @"like_author" :
|
|
|
|
authorScore <= -1 ? @"dislike_author" :
|
|
|
|
@"remove_like_author"];
|
|
|
|
[request setPostValue:feedId forKey:@"feed_id"];
|
|
|
|
[request setCompletionBlock:^{
|
2013-09-05 17:07:21 -07:00
|
|
|
[self requestClassifierResponse:_request withFeed:feedId];
|
|
|
|
}];
|
|
|
|
[request setFailedBlock:^{
|
|
|
|
[self requestClassifierResponse:_request withFeed:feedId];
|
2012-12-27 18:37:05 -08:00
|
|
|
}];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
|
|
|
|
[self recalculateIntelligenceScores:feedId];
|
|
|
|
[self.feedDetailViewController.storyTitlesTable reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleTagClassifier:(NSString *)tag feedId:(NSString *)feedId {
|
|
|
|
NSLog(@"toggleTagClassifier: %@", tag);
|
2014-02-12 20:09:37 -08:00
|
|
|
int tagScore = [[[[storiesCollection.activeClassifiers objectForKey:feedId]
|
2012-12-27 18:37:05 -08:00
|
|
|
objectForKey:@"tags"]
|
|
|
|
objectForKey:tag] intValue];
|
|
|
|
|
|
|
|
if (tagScore > 0) {
|
|
|
|
tagScore = -1;
|
|
|
|
} else if (tagScore < 0) {
|
|
|
|
tagScore = 0;
|
|
|
|
} else {
|
|
|
|
tagScore = 1;
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
NSMutableDictionary *feedClassifiers = [[storiesCollection.activeClassifiers objectForKey:feedId]
|
2012-12-27 18:37:05 -08:00
|
|
|
mutableCopy];
|
2013-09-05 17:07:21 -07:00
|
|
|
if (!feedClassifiers) feedClassifiers = [NSMutableDictionary dictionary];
|
2012-12-27 18:37:05 -08:00
|
|
|
NSMutableDictionary *tags = [[feedClassifiers objectForKey:@"tags"] mutableCopy];
|
2013-09-05 17:07:21 -07:00
|
|
|
if (!tags) tags = [NSMutableDictionary dictionary];
|
2012-12-27 18:37:05 -08:00
|
|
|
[tags setObject:[NSNumber numberWithInt:tagScore] forKey:tag];
|
|
|
|
[feedClassifiers setObject:tags forKey:@"tags"];
|
2014-02-12 20:09:37 -08:00
|
|
|
[storiesCollection.activeClassifiers setObject:feedClassifiers forKey:feedId];
|
2012-12-27 18:37:05 -08:00
|
|
|
[self.storyPageControl refreshHeaders];
|
|
|
|
[self.trainerViewController refresh];
|
|
|
|
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/classifier/save",
|
2012-12-27 18:37:05 -08:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2013-09-05 17:07:21 -07:00
|
|
|
__weak ASIFormDataRequest *_request = request;
|
2012-12-27 18:37:05 -08:00
|
|
|
[request setPostValue:tag
|
|
|
|
forKey:tagScore >= 1 ? @"like_tag" :
|
|
|
|
tagScore <= -1 ? @"dislike_tag" :
|
|
|
|
@"remove_like_tag"];
|
|
|
|
[request setPostValue:feedId forKey:@"feed_id"];
|
|
|
|
[request setCompletionBlock:^{
|
2013-09-05 17:07:21 -07:00
|
|
|
[self requestClassifierResponse:_request withFeed:feedId];
|
|
|
|
}];
|
|
|
|
[request setFailedBlock:^{
|
|
|
|
[self requestClassifierResponse:_request withFeed:feedId];
|
2012-12-27 18:37:05 -08:00
|
|
|
}];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
|
|
|
|
[self recalculateIntelligenceScores:feedId];
|
|
|
|
[self.feedDetailViewController.storyTitlesTable reloadData];
|
|
|
|
}
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
- (void)toggleTitleClassifier:(NSString *)title feedId:(NSString *)feedId score:(NSInteger)score {
|
|
|
|
NSLog(@"toggle Title: %@ (%@) / %ld", title, feedId, (long)score);
|
2014-02-12 20:09:37 -08:00
|
|
|
NSInteger titleScore = [[[[storiesCollection.activeClassifiers objectForKey:feedId]
|
2013-09-25 17:43:00 -07:00
|
|
|
objectForKey:@"titles"]
|
|
|
|
objectForKey:title] intValue];
|
2012-12-27 18:37:05 -08:00
|
|
|
|
|
|
|
if (score) {
|
|
|
|
titleScore = score;
|
|
|
|
} else {
|
|
|
|
if (titleScore > 0) {
|
|
|
|
titleScore = -1;
|
|
|
|
} else if (titleScore < 0) {
|
|
|
|
titleScore = 0;
|
|
|
|
} else {
|
|
|
|
titleScore = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
NSMutableDictionary *feedClassifiers = [[storiesCollection.activeClassifiers objectForKey:feedId]
|
2012-12-27 18:37:05 -08:00
|
|
|
mutableCopy];
|
2013-09-05 17:07:21 -07:00
|
|
|
if (!feedClassifiers) feedClassifiers = [NSMutableDictionary dictionary];
|
2012-12-27 18:37:05 -08:00
|
|
|
NSMutableDictionary *titles = [[feedClassifiers objectForKey:@"titles"] mutableCopy];
|
2013-09-05 17:07:21 -07:00
|
|
|
if (!titles) titles = [NSMutableDictionary dictionary];
|
2013-09-25 17:43:00 -07:00
|
|
|
[titles setObject:[NSNumber numberWithInteger:titleScore] forKey:title];
|
2012-12-27 18:37:05 -08:00
|
|
|
[feedClassifiers setObject:titles forKey:@"titles"];
|
2014-02-12 20:09:37 -08:00
|
|
|
[storiesCollection.activeClassifiers setObject:feedClassifiers forKey:feedId];
|
2012-12-27 18:37:05 -08:00
|
|
|
[self.storyPageControl refreshHeaders];
|
|
|
|
[self.trainerViewController refresh];
|
|
|
|
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/classifier/save",
|
2012-12-27 18:37:05 -08:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2013-09-05 17:07:21 -07:00
|
|
|
__weak ASIFormDataRequest *_request = request;
|
2012-12-27 18:37:05 -08:00
|
|
|
[request setPostValue:title
|
|
|
|
forKey:titleScore >= 1 ? @"like_title" :
|
|
|
|
titleScore <= -1 ? @"dislike_title" :
|
|
|
|
@"remove_like_title"];
|
|
|
|
[request setPostValue:feedId forKey:@"feed_id"];
|
|
|
|
[request setCompletionBlock:^{
|
2013-09-05 17:07:21 -07:00
|
|
|
[self requestClassifierResponse:_request withFeed:feedId];
|
|
|
|
}];
|
|
|
|
[request setFailedBlock:^{
|
|
|
|
[self requestClassifierResponse:_request withFeed:feedId];
|
2012-12-27 18:37:05 -08:00
|
|
|
}];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
|
|
|
|
[self recalculateIntelligenceScores:feedId];
|
|
|
|
[self.feedDetailViewController.storyTitlesTable reloadData];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)toggleFeedClassifier:(NSString *)feedId {
|
2014-02-12 20:09:37 -08:00
|
|
|
int feedScore = [[[[storiesCollection.activeClassifiers objectForKey:feedId]
|
2012-12-27 18:37:05 -08:00
|
|
|
objectForKey:@"feeds"]
|
|
|
|
objectForKey:feedId] intValue];
|
|
|
|
|
|
|
|
if (feedScore > 0) {
|
|
|
|
feedScore = -1;
|
|
|
|
} else if (feedScore < 0) {
|
|
|
|
feedScore = 0;
|
|
|
|
} else {
|
|
|
|
feedScore = 1;
|
|
|
|
}
|
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
NSMutableDictionary *feedClassifiers = [[storiesCollection.activeClassifiers objectForKey:feedId]
|
2012-12-27 18:37:05 -08:00
|
|
|
mutableCopy];
|
2013-09-05 17:07:21 -07:00
|
|
|
if (!feedClassifiers) feedClassifiers = [NSMutableDictionary dictionary];
|
2012-12-27 18:37:05 -08:00
|
|
|
NSMutableDictionary *feeds = [[feedClassifiers objectForKey:@"feeds"] mutableCopy];
|
|
|
|
[feeds setObject:[NSNumber numberWithInt:feedScore] forKey:feedId];
|
|
|
|
[feedClassifiers setObject:feeds forKey:@"feeds"];
|
2014-02-12 20:09:37 -08:00
|
|
|
[storiesCollection.activeClassifiers setObject:feedClassifiers forKey:feedId];
|
2012-12-27 18:37:05 -08:00
|
|
|
[self.storyPageControl refreshHeaders];
|
|
|
|
[self.trainerViewController refresh];
|
|
|
|
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/classifier/save",
|
2012-12-27 18:37:05 -08:00
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
__block ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2013-09-05 17:07:21 -07:00
|
|
|
__weak ASIFormDataRequest *_request = request;
|
2012-12-27 18:37:05 -08:00
|
|
|
[request setPostValue:feedId
|
|
|
|
forKey:feedScore >= 1 ? @"like_feed" :
|
|
|
|
feedScore <= -1 ? @"dislike_feed" :
|
|
|
|
@"remove_like_feed"];
|
|
|
|
[request setPostValue:feedId forKey:@"feed_id"];
|
|
|
|
[request setCompletionBlock:^{
|
2013-09-05 17:07:21 -07:00
|
|
|
[self requestClassifierResponse:_request withFeed:feedId];
|
|
|
|
}];
|
|
|
|
[request setFailedBlock:^{
|
|
|
|
[self requestClassifierResponse:_request withFeed:feedId];
|
2012-12-27 18:37:05 -08:00
|
|
|
}];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request startAsynchronous];
|
|
|
|
|
|
|
|
[self recalculateIntelligenceScores:feedId];
|
|
|
|
[self.feedDetailViewController.storyTitlesTable reloadData];
|
|
|
|
}
|
|
|
|
|
2013-09-05 17:07:21 -07:00
|
|
|
- (void)requestClassifierResponse:(ASIHTTPRequest *)request withFeed:(NSString *)feedId {
|
|
|
|
BaseViewController *view;
|
|
|
|
if (self.trainerViewController.isViewLoaded && self.trainerViewController.view.window) {
|
|
|
|
view = self.trainerViewController;
|
|
|
|
} else {
|
|
|
|
view = self.storyPageControl.currentPage;
|
|
|
|
}
|
|
|
|
if ([request responseStatusCode] == 503) {
|
|
|
|
return [view informError:@"In maintenance mode"];
|
|
|
|
} else if ([request responseStatusCode] != 200) {
|
|
|
|
return [view informError:@"The server barfed!"];
|
|
|
|
}
|
|
|
|
|
|
|
|
[self.feedsViewController refreshFeedList:feedId];
|
|
|
|
}
|
|
|
|
|
2013-03-06 14:29:40 -08:00
|
|
|
- (void)requestFailed:(ASIHTTPRequest *)request {
|
|
|
|
NSError *error = [request error];
|
|
|
|
NSLog(@"Error: %@", error);
|
|
|
|
[self informError:error];
|
|
|
|
}
|
|
|
|
|
2013-05-30 18:45:51 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Storing Stories for Offline
|
|
|
|
|
2013-09-25 17:43:00 -07:00
|
|
|
- (NSInteger)databaseSchemaVersion:(FMDatabase *)db {
|
2013-06-05 17:11:01 -07:00
|
|
|
int version = 0;
|
2013-06-14 19:21:30 -07:00
|
|
|
FMResultSet *resultSet = [db executeQuery:@"PRAGMA user_version"];
|
2013-06-05 17:11:01 -07:00
|
|
|
if ([resultSet next]) {
|
|
|
|
version = [resultSet intForColumnIndex:0];
|
|
|
|
}
|
2013-10-03 18:07:39 -07:00
|
|
|
[resultSet close];
|
2013-06-05 17:11:01 -07:00
|
|
|
return version;
|
|
|
|
}
|
|
|
|
|
2013-06-14 19:21:30 -07:00
|
|
|
- (void)createDatabaseConnection {
|
2013-10-08 16:00:55 -07:00
|
|
|
NSError *error;
|
|
|
|
|
|
|
|
// Remove the deletion of old sqlite dbs past version 3.1, once everybody's
|
|
|
|
// upgraded and removed the old files.
|
|
|
|
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
|
|
|
NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *oldDBPath = [documentPaths objectAtIndex:0];
|
|
|
|
NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:oldDBPath error:&error];
|
|
|
|
int removed = 0;
|
|
|
|
|
|
|
|
if (error == nil) {
|
|
|
|
for (NSString *path in directoryContents) {
|
|
|
|
NSString *fullPath = [oldDBPath stringByAppendingPathComponent:path];
|
|
|
|
if ([fullPath hasSuffix:@".sqlite"]) {
|
|
|
|
[fileManager removeItemAtPath:fullPath error:&error];
|
|
|
|
removed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (removed) {
|
|
|
|
NSLog(@"Deleted %d sql dbs.", removed);
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *dbPath = [cachePaths objectAtIndex:0];
|
2013-06-18 21:23:20 -04:00
|
|
|
NSString *dbName = [NSString stringWithFormat:@"%@.sqlite", NEWSBLUR_HOST];
|
2013-10-08 16:00:55 -07:00
|
|
|
NSString *path = [dbPath stringByAppendingPathComponent:dbName];
|
2013-06-05 17:11:01 -07:00
|
|
|
|
2013-06-14 19:21:30 -07:00
|
|
|
database = [FMDatabaseQueue databaseQueueWithPath:path];
|
|
|
|
[database inDatabase:^(FMDatabase *db) {
|
|
|
|
[self setupDatabase:db];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setupDatabase:(FMDatabase *)db {
|
|
|
|
if ([self databaseSchemaVersion:db] < CURRENT_DB_VERSION) {
|
2013-06-05 17:11:01 -07:00
|
|
|
// FMDB cannot execute this query because FMDB tries to use prepared statements
|
2013-06-21 22:18:54 -07:00
|
|
|
[db closeOpenResultSets];
|
|
|
|
[db executeUpdate:@"drop table if exists `stories`"];
|
|
|
|
[db executeUpdate:@"drop table if exists `unread_hashes`"];
|
|
|
|
[db executeUpdate:@"drop table if exists `accounts`"];
|
2013-06-29 17:28:41 -07:00
|
|
|
[db executeUpdate:@"drop table if exists `unread_counts`"];
|
2013-06-22 19:34:12 -07:00
|
|
|
[db executeUpdate:@"drop table if exists `cached_images`"];
|
2013-09-05 16:34:39 -07:00
|
|
|
[db executeUpdate:@"drop table if exists `users`"];
|
2013-07-11 18:36:09 -07:00
|
|
|
// [db executeUpdate:@"drop table if exists `queued_read_hashes`"]; // Nope, don't clear this.
|
2013-10-04 12:37:51 -07:00
|
|
|
// [db executeUpdate:@"drop table if exists `queued_saved_hashes`"]; // Nope, don't clear this.
|
2013-06-14 19:21:30 -07:00
|
|
|
NSLog(@"Dropped db: %@", [db lastErrorMessage]);
|
|
|
|
sqlite3_exec(db.sqliteHandle, [[NSString stringWithFormat:@"PRAGMA user_version = %d", CURRENT_DB_VERSION] UTF8String], NULL, NULL, NULL);
|
|
|
|
}
|
2013-06-21 22:18:54 -07:00
|
|
|
NSString *createAccountsTable = [NSString stringWithFormat:@"create table if not exists accounts "
|
2013-06-20 19:25:57 -07:00
|
|
|
"("
|
|
|
|
" username varchar(36),"
|
|
|
|
" download_date date,"
|
|
|
|
" feeds_json text,"
|
|
|
|
" UNIQUE(username) ON CONFLICT REPLACE"
|
|
|
|
")"];
|
2013-06-21 22:18:54 -07:00
|
|
|
[db executeUpdate:createAccountsTable];
|
|
|
|
|
2013-06-29 17:28:41 -07:00
|
|
|
NSString *createCountsTable = [NSString stringWithFormat:@"create table if not exists unread_counts "
|
2013-06-21 22:18:54 -07:00
|
|
|
"("
|
2013-06-29 17:28:41 -07:00
|
|
|
" feed_id varchar(20),"
|
2013-06-21 22:18:54 -07:00
|
|
|
" ps number,"
|
|
|
|
" nt number,"
|
|
|
|
" ng number,"
|
|
|
|
" UNIQUE(feed_id) ON CONFLICT REPLACE"
|
|
|
|
")"];
|
2013-06-29 17:28:41 -07:00
|
|
|
[db executeUpdate:createCountsTable];
|
2013-06-20 19:25:57 -07:00
|
|
|
|
2013-06-14 19:21:30 -07:00
|
|
|
NSString *createStoryTable = [NSString stringWithFormat:@"create table if not exists stories "
|
|
|
|
"("
|
2013-10-03 18:07:39 -07:00
|
|
|
" story_feed_id varchar(20),"
|
2013-06-14 19:21:30 -07:00
|
|
|
" story_hash varchar(24),"
|
|
|
|
" story_timestamp number,"
|
|
|
|
" story_json text,"
|
|
|
|
" UNIQUE(story_hash) ON CONFLICT REPLACE"
|
|
|
|
")"];
|
|
|
|
[db executeUpdate:createStoryTable];
|
2013-06-26 16:22:44 -07:00
|
|
|
NSString *indexStoriesFeed = @"CREATE INDEX IF NOT EXISTS stories_story_feed_id ON stories (story_feed_id)";
|
|
|
|
[db executeUpdate:indexStoriesFeed];
|
2013-06-14 19:21:30 -07:00
|
|
|
|
|
|
|
NSString *createUnreadHashTable = [NSString stringWithFormat:@"create table if not exists unread_hashes "
|
|
|
|
"("
|
2013-10-03 18:07:39 -07:00
|
|
|
" story_feed_id varchar(20),"
|
2013-06-14 19:21:30 -07:00
|
|
|
" story_hash varchar(24),"
|
2013-06-16 21:39:38 -07:00
|
|
|
" story_timestamp number,"
|
2013-06-14 19:21:30 -07:00
|
|
|
" UNIQUE(story_hash) ON CONFLICT IGNORE"
|
|
|
|
")"];
|
|
|
|
[db executeUpdate:createUnreadHashTable];
|
2013-06-26 16:22:44 -07:00
|
|
|
NSString *indexUnreadHashes = @"CREATE INDEX IF NOT EXISTS unread_hashes_story_feed_id ON unread_hashes (story_feed_id)";
|
|
|
|
[db executeUpdate:indexUnreadHashes];
|
|
|
|
NSString *indexUnreadTimestamp = @"CREATE INDEX IF NOT EXISTS unread_hashes_timestamp ON stories (story_timestamp)";
|
|
|
|
[db executeUpdate:indexUnreadTimestamp];
|
2013-06-14 19:21:30 -07:00
|
|
|
|
|
|
|
NSString *createReadTable = [NSString stringWithFormat:@"create table if not exists queued_read_hashes "
|
|
|
|
"("
|
2013-10-03 18:07:39 -07:00
|
|
|
" story_feed_id varchar(20),"
|
2013-06-14 19:21:30 -07:00
|
|
|
" story_hash varchar(24),"
|
|
|
|
" UNIQUE(story_hash) ON CONFLICT IGNORE"
|
|
|
|
")"];
|
|
|
|
[db executeUpdate:createReadTable];
|
2013-09-05 16:34:39 -07:00
|
|
|
|
2013-10-04 12:37:51 -07:00
|
|
|
NSString *createSavedTable = [NSString stringWithFormat:@"create table if not exists queued_saved_hashes "
|
|
|
|
"("
|
|
|
|
" story_feed_id varchar(20),"
|
|
|
|
" story_hash varchar(24),"
|
|
|
|
" UNIQUE(story_hash) ON CONFLICT IGNORE"
|
|
|
|
")"];
|
|
|
|
[db executeUpdate:createSavedTable];
|
|
|
|
|
2013-06-22 19:34:12 -07:00
|
|
|
NSString *createImagesTable = [NSString stringWithFormat:@"create table if not exists cached_images "
|
|
|
|
"("
|
2013-10-03 18:07:39 -07:00
|
|
|
" story_feed_id varchar(20),"
|
2013-06-22 19:34:12 -07:00
|
|
|
" story_hash varchar(24),"
|
|
|
|
" image_url varchar(1024),"
|
2013-07-18 18:24:38 -07:00
|
|
|
" image_cached boolean,"
|
2013-07-11 18:36:09 -07:00
|
|
|
" failed boolean"
|
2013-06-22 19:34:12 -07:00
|
|
|
")"];
|
|
|
|
[db executeUpdate:createImagesTable];
|
2013-06-26 16:22:44 -07:00
|
|
|
NSString *indexImagesFeedId = @"CREATE INDEX IF NOT EXISTS cached_images_story_feed_id ON cached_images (story_feed_id)";
|
|
|
|
[db executeUpdate:indexImagesFeedId];
|
|
|
|
NSString *indexImagesStoryHash = @"CREATE INDEX IF NOT EXISTS cached_images_story_hash ON cached_images (story_hash)";
|
|
|
|
[db executeUpdate:indexImagesStoryHash];
|
2013-06-22 19:34:12 -07:00
|
|
|
|
2013-09-05 16:34:39 -07:00
|
|
|
|
|
|
|
NSString *createUsersTable = [NSString stringWithFormat:@"create table if not exists users "
|
|
|
|
"("
|
|
|
|
" user_id number,"
|
|
|
|
" username varchar(64),"
|
|
|
|
" location varchar(128),"
|
|
|
|
" image_url varchar(1024),"
|
|
|
|
" image_cached boolean,"
|
|
|
|
" user_json text,"
|
|
|
|
" UNIQUE(user_id) ON CONFLICT REPLACE"
|
|
|
|
")"];
|
|
|
|
[db executeUpdate:createUsersTable];
|
|
|
|
NSString *indexUsersUserId = @"CREATE INDEX IF NOT EXISTS users_user_id ON users (user_id)";
|
|
|
|
[db executeUpdate:indexUsersUserId];
|
|
|
|
|
2014-02-25 12:37:22 -08:00
|
|
|
NSError *error;
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *storyImagesDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"story_images"];
|
|
|
|
if (![[NSFileManager defaultManager] fileExistsAtPath:storyImagesDirectory]) {
|
|
|
|
[[NSFileManager defaultManager] createDirectoryAtPath:storyImagesDirectory
|
|
|
|
withIntermediateDirectories:NO
|
|
|
|
attributes:nil
|
|
|
|
error:&error];
|
|
|
|
}
|
|
|
|
|
2014-02-11 11:52:32 -08:00
|
|
|
// NSLog(@"Create db %d: %@", [db lastErrorCode], [db lastErrorMessage]);
|
2013-05-30 18:45:51 -07:00
|
|
|
}
|
|
|
|
|
2013-07-18 18:24:38 -07:00
|
|
|
- (void)cancelOfflineQueue {
|
|
|
|
if (offlineQueue) {
|
|
|
|
[offlineQueue cancelAllOperations];
|
|
|
|
}
|
2013-08-05 18:32:43 -07:00
|
|
|
if (offlineCleaningQueue) {
|
|
|
|
[offlineCleaningQueue cancelAllOperations];
|
|
|
|
}
|
2013-07-18 18:24:38 -07:00
|
|
|
}
|
|
|
|
|
2013-07-15 18:25:09 -07:00
|
|
|
- (void)startOfflineQueue {
|
|
|
|
if (!offlineQueue) {
|
|
|
|
offlineQueue = [NSOperationQueue new];
|
|
|
|
}
|
|
|
|
offlineQueue.name = @"Offline Queue";
|
2014-02-11 11:52:32 -08:00
|
|
|
// NSLog(@"Operation queue: %lu", (unsigned long)offlineQueue.operationCount);
|
2013-07-15 18:25:09 -07:00
|
|
|
[offlineQueue cancelAllOperations];
|
|
|
|
[offlineQueue setMaxConcurrentOperationCount:1];
|
|
|
|
OfflineSyncUnreads *operationSyncUnreads = [[OfflineSyncUnreads alloc] init];
|
|
|
|
|
|
|
|
[offlineQueue addOperation:operationSyncUnreads];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startOfflineFetchStories {
|
|
|
|
OfflineFetchStories *operationFetchStories = [[OfflineFetchStories alloc] init];
|
|
|
|
|
|
|
|
[offlineQueue addOperation:operationFetchStories];
|
2013-07-16 18:06:36 -07:00
|
|
|
|
2014-02-11 11:52:32 -08:00
|
|
|
// NSLog(@"Done start offline fetch stories");
|
2013-07-15 18:25:09 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)startOfflineFetchImages {
|
|
|
|
OfflineFetchImages *operationFetchImages = [[OfflineFetchImages alloc] init];
|
|
|
|
|
|
|
|
[offlineQueue addOperation:operationFetchImages];
|
|
|
|
}
|
|
|
|
|
2013-09-04 15:56:37 -07:00
|
|
|
- (BOOL)isReachabileForOffline {
|
|
|
|
Reachability *reachability = [Reachability reachabilityForInternetConnection];
|
|
|
|
NetworkStatus remoteHostStatus = [reachability currentReachabilityStatus];
|
|
|
|
|
|
|
|
NSString *connection = [[NSUserDefaults standardUserDefaults]
|
|
|
|
stringForKey:@"offline_download_connection"];
|
|
|
|
|
2013-10-08 12:36:43 -07:00
|
|
|
// NSLog(@"Reachable via: %d / %d", remoteHostStatus == ReachableViaWWAN, remoteHostStatus == ReachableViaWiFi);
|
2013-09-04 15:56:37 -07:00
|
|
|
if ([connection isEqualToString:@"wifi"] && remoteHostStatus != ReachableViaWiFi) {
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
2013-07-15 18:25:09 -07:00
|
|
|
|
2013-09-05 16:34:39 -07:00
|
|
|
- (void)storeUserProfiles:(NSArray *)userProfiles {
|
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
|
|
|
|
(unsigned long)NULL), ^(void) {
|
|
|
|
[self.database inTransaction:^(FMDatabase *db, BOOL *rollback) {
|
|
|
|
for (NSDictionary *user in userProfiles) {
|
|
|
|
[db executeUpdate:@"INSERT INTO users "
|
|
|
|
"(user_id, username, location, image_url, user_json) VALUES "
|
|
|
|
"(?, ?, ?, ?, ?)",
|
|
|
|
[user objectForKey:@"user_id"],
|
|
|
|
[user objectForKey:@"username"],
|
|
|
|
[user objectForKey:@"location"],
|
|
|
|
[user objectForKey:@"photo_url"],
|
|
|
|
[user JSONRepresentation]
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-08-06 18:08:55 -07:00
|
|
|
- (void)queueReadStories:(NSDictionary *)feedsStories {
|
2013-09-05 16:34:39 -07:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,
|
|
|
|
(unsigned long)NULL), ^(void) {
|
|
|
|
[self.database inTransaction:^(FMDatabase *db, BOOL *rollback) {
|
|
|
|
for (NSString *feedIdStr in [feedsStories allKeys]) {
|
|
|
|
for (NSString *storyHash in [feedsStories objectForKey:feedIdStr]) {
|
|
|
|
[db executeUpdate:@"INSERT INTO queued_read_hashes "
|
|
|
|
"(story_feed_id, story_hash) VALUES "
|
|
|
|
"(?, ?)", feedIdStr, storyHash];
|
|
|
|
}
|
2013-08-06 18:08:55 -07:00
|
|
|
}
|
2013-09-05 16:34:39 -07:00
|
|
|
}];
|
|
|
|
});
|
2013-08-06 18:08:55 -07:00
|
|
|
self.hasQueuedReadStories = YES;
|
|
|
|
}
|
|
|
|
|
2013-10-03 18:07:39 -07:00
|
|
|
- (BOOL)dequeueReadStoryHash:(NSString *)storyHash inFeed:(NSString *)storyFeedId {
|
|
|
|
__block BOOL storyQueued = NO;
|
|
|
|
|
|
|
|
[self.database inDatabase:^(FMDatabase *db) {
|
|
|
|
FMResultSet *stories = [db executeQuery:@"SELECT * FROM queued_read_hashes "
|
|
|
|
"WHERE story_hash = ? AND story_feed_id = ? LIMIT 1",
|
|
|
|
storyHash, storyFeedId];
|
|
|
|
while ([stories next]) {
|
|
|
|
storyQueued = YES;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
[stories close];
|
|
|
|
if (storyQueued) {
|
|
|
|
[db executeUpdate:@"DELETE FROM queued_read_hashes "
|
|
|
|
"WHERE story_hash = ? AND story_feed_id = ?",
|
|
|
|
storyHash, storyFeedId];
|
|
|
|
}
|
|
|
|
}];
|
|
|
|
|
|
|
|
return storyQueued;
|
|
|
|
}
|
|
|
|
|
2013-06-21 22:18:54 -07:00
|
|
|
- (void)flushQueuedReadStories:(BOOL)forceCheck withCallback:(void(^)())callback {
|
2013-07-15 18:25:09 -07:00
|
|
|
if (self.hasQueuedReadStories || forceCheck) {
|
2014-02-03 18:54:50 -08:00
|
|
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW,
|
2013-07-31 15:23:00 -07:00
|
|
|
(unsigned long)NULL), ^(void) {
|
2013-06-21 22:18:54 -07:00
|
|
|
[self.database inTransaction:^(FMDatabase *db, BOOL *rollback) {
|
|
|
|
NSMutableDictionary *hashes = [NSMutableDictionary dictionary];
|
|
|
|
FMResultSet *stories = [db executeQuery:@"SELECT * FROM queued_read_hashes"];
|
|
|
|
while ([stories next]) {
|
|
|
|
NSString *storyFeedId = [NSString stringWithFormat:@"%@", [stories objectForColumnName:@"story_feed_id"]];
|
|
|
|
NSString *storyHash = [stories objectForColumnName:@"story_hash"];
|
|
|
|
if (![hashes objectForKey:storyFeedId]) {
|
|
|
|
[hashes setObject:[NSMutableArray array] forKey:storyFeedId];
|
|
|
|
}
|
|
|
|
[[hashes objectForKey:storyFeedId] addObject:storyHash];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([[hashes allKeys] count]) {
|
2013-07-15 18:25:09 -07:00
|
|
|
self.hasQueuedReadStories = NO;
|
2013-06-21 22:18:54 -07:00
|
|
|
[self syncQueuedReadStories:db withStories:hashes withCallback:callback];
|
|
|
|
} else {
|
|
|
|
if (callback) callback();
|
|
|
|
}
|
2013-10-03 18:07:39 -07:00
|
|
|
[stories close];
|
2013-06-21 22:18:54 -07:00
|
|
|
}];
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (callback) callback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)syncQueuedReadStories:(FMDatabase *)db withStories:(NSDictionary *)hashes withCallback:(void(^)())callback {
|
|
|
|
NSString *urlString = [NSString stringWithFormat:@"%@/reader/mark_feed_stories_as_read",
|
|
|
|
NEWSBLUR_URL];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlString];
|
|
|
|
NSMutableArray *completedHashes = [NSMutableArray array];
|
|
|
|
for (NSArray *storyHashes in [hashes allValues]) {
|
|
|
|
[completedHashes addObjectsFromArray:storyHashes];
|
|
|
|
}
|
|
|
|
NSString *completedHashesStr = [completedHashes componentsJoinedByString:@"\",\""];
|
|
|
|
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
|
2013-08-06 18:08:55 -07:00
|
|
|
__weak ASIHTTPRequest *_request = request;
|
2013-06-21 22:18:54 -07:00
|
|
|
[request setPostValue:[hashes JSONRepresentation] forKey:@"feeds_stories"];
|
|
|
|
[request setDelegate:self];
|
|
|
|
[request setCompletionBlock:^{
|
2013-08-06 18:08:55 -07:00
|
|
|
if ([_request responseStatusCode] == 200) {
|
|
|
|
NSLog(@"Completed clearing %@ hashes", completedHashesStr);
|
|
|
|
[db executeUpdate:[NSString stringWithFormat:@"DELETE FROM queued_read_hashes "
|
|
|
|
"WHERE story_hash in (\"%@\")", completedHashesStr]];
|
|
|
|
} else {
|
|
|
|
NSLog(@"Failed mark read queued.");
|
|
|
|
self.hasQueuedReadStories = YES;
|
|
|
|
}
|
2013-06-21 22:18:54 -07:00
|
|
|
if (callback) callback();
|
|
|
|
}];
|
|
|
|
[request setFailedBlock:^{
|
|
|
|
NSLog(@"Failed mark read queued.");
|
2013-07-15 18:25:09 -07:00
|
|
|
self.hasQueuedReadStories = YES;
|
2013-06-21 22:18:54 -07:00
|
|
|
if (callback) callback();
|
|
|
|
}];
|
|
|
|
[request startAsynchronous];
|
|
|
|
}
|
|
|
|
|
2013-07-15 18:25:09 -07:00
|
|
|
- (void)prepareActiveCachedImages:(FMDatabase *)db {
|
|
|
|
activeCachedImages = [NSMutableDictionary dictionary];
|
|
|
|
NSArray *feedIds;
|
2013-07-18 18:24:38 -07:00
|
|
|
int cached = 0;
|
2013-06-16 21:39:38 -07:00
|
|
|
|
2014-02-12 20:09:37 -08:00
|
|
|
if (storiesCollection.isRiverView) {
|
|
|
|
feedIds = storiesCollection.activeFolderFeeds;
|
|
|
|
} else if (storiesCollection.activeFeed) {
|
|
|
|
feedIds = @[[storiesCollection.activeFeed objectForKey:@"id"]];
|
2013-06-16 14:09:28 -07:00
|
|
|
}
|
2013-07-15 18:25:09 -07:00
|
|
|
NSString *sql = [NSString stringWithFormat:@"SELECT c.image_url, c.story_hash FROM cached_images c "
|
2013-09-30 16:18:11 -07:00
|
|
|
"WHERE c.image_cached = 1 AND c.failed is null AND c.story_feed_id in (\"%@\")",
|
|
|
|
[feedIds componentsJoinedByString:@"\",\""]];
|
2013-07-15 18:25:09 -07:00
|
|
|
FMResultSet *cursor = [db executeQuery:sql];
|
2013-06-16 14:09:28 -07:00
|
|
|
|
2013-07-15 18:25:09 -07:00
|
|
|
while ([cursor next]) {
|
|
|
|
NSString *storyHash = [cursor objectForColumnName:@"story_hash"];
|
|
|
|
NSMutableArray *imageUrls;
|
|
|
|
if (![activeCachedImages objectForKey:storyHash]) {
|
|
|
|
imageUrls = [NSMutableArray array];
|
|
|
|
[activeCachedImages setObject:imageUrls forKey:storyHash];
|
2013-06-21 22:18:54 -07:00
|
|
|
} else {
|
2013-07-15 18:25:09 -07:00
|
|
|
imageUrls = [activeCachedImages objectForKey:storyHash];
|
2013-07-11 18:36:09 -07:00
|
|
|
}
|
2013-07-15 18:25:09 -07:00
|
|
|
[imageUrls addObject:[cursor objectForColumnName:@"image_url"]];
|
|
|
|
[activeCachedImages setObject:imageUrls forKey:storyHash];
|
2013-07-18 18:24:38 -07:00
|
|
|
cached++;
|
2013-06-16 08:15:40 -07:00
|
|
|
}
|
2013-06-22 19:34:12 -07:00
|
|
|
|
2014-02-11 11:52:32 -08:00
|
|
|
// NSLog(@"Pre-cached %d images", cached);
|
2013-06-16 08:15:40 -07:00
|
|
|
}
|
|
|
|
|
2013-10-08 16:00:55 -07:00
|
|
|
- (void)cleanImageCache {
|
|
|
|
OfflineCleanImages *operationCleanImages = [[OfflineCleanImages alloc] init];
|
|
|
|
if (!offlineCleaningQueue) {
|
|
|
|
offlineCleaningQueue = [NSOperationQueue new];
|
|
|
|
}
|
|
|
|
[offlineCleaningQueue addOperation:operationCleanImages];
|
|
|
|
}
|
|
|
|
|
2013-07-15 18:25:09 -07:00
|
|
|
- (void)deleteAllCachedImages {
|
|
|
|
NSFileManager *fileManager = [[NSFileManager alloc] init];
|
|
|
|
NSError *error = nil;
|
|
|
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
|
|
|
|
NSString *cacheDirectory = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"story_images"];
|
|
|
|
NSArray *directoryContents = [fileManager contentsOfDirectoryAtPath:cacheDirectory error:&error];
|
|
|
|
int removed = 0;
|
2013-06-23 22:19:08 -07:00
|
|
|
|
2013-07-15 18:25:09 -07:00
|
|
|
if (error == nil) {
|
|
|
|
for (NSString *path in directoryContents) {
|
|
|
|
NSString *fullPath = [cacheDirectory stringByAppendingPathComponent:path];
|
|
|
|
BOOL removeSuccess = [fileManager removeItemAtPath:fullPath error:&error];
|
|
|
|
removed++;
|
|
|
|
if (!removeSuccess) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-06-26 16:22:44 -07:00
|
|
|
}
|
2013-06-23 22:19:08 -07:00
|
|
|
}
|
2013-06-26 11:38:49 -07:00
|
|
|
|
2013-07-15 18:25:09 -07:00
|
|
|
NSLog(@"Deleted %d images.", removed);
|
2013-06-23 22:19:08 -07:00
|
|
|
}
|
|
|
|
|
2012-10-07 15:47:21 -04:00
|
|
|
@end
|
|
|
|
|
2013-05-30 18:45:51 -07:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Unread Counts
|
|
|
|
|
2012-10-07 15:47:21 -04:00
|
|
|
|
2012-10-12 15:33:40 -04:00
|
|
|
@implementation UnreadCounts
|
2012-10-07 15:47:21 -04:00
|
|
|
|
|
|
|
@synthesize ps, nt, ng;
|
|
|
|
|
|
|
|
|
|
|
|
- (id)init {
|
|
|
|
if (self = [super init]) {
|
|
|
|
ps = 0;
|
|
|
|
nt = 0;
|
|
|
|
ng = 0;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-10-12 15:33:40 -04:00
|
|
|
- (void)addCounts:(UnreadCounts *)counts {
|
2012-10-07 15:47:21 -04:00
|
|
|
ps += counts.ps;
|
|
|
|
nt += counts.nt;
|
|
|
|
ng += counts.ng;
|
|
|
|
}
|
|
|
|
|
2013-10-09 14:54:49 -07:00
|
|
|
- (NSString *)description {
|
|
|
|
return [NSString stringWithFormat:@"PS: %d, NT: %d, NG: %d", ps, nt, ng];
|
|
|
|
}
|
|
|
|
|
2012-07-12 22:05:23 -07:00
|
|
|
@end
|