From ed30ad75e29fd394f6f57093ce17672a2edbd652 Mon Sep 17 00:00:00 2001 From: David Sinclair Date: Fri, 31 Jan 2020 15:50:03 -0800 Subject: [PATCH] #1238 (statistics) - Added Statistics to the preferences for the left swipe in the feeds list. - A bit of refactoring to support displaying the popover from a cell on iPad. --- .../ios/Classes/FeedDetailViewController.m | 6 +---- clients/ios/Classes/FeedTableCell.m | 19 +++++++++++---- clients/ios/Classes/NewsBlurAppDelegate.h | 3 ++- clients/ios/Classes/NewsBlurAppDelegate.m | 23 +++++++++++++++---- clients/ios/Classes/NewsBlurViewController.m | 16 +++++++++---- .../ios/Resources/Settings.bundle/Root.plist | 6 +++-- .../Resources/Settings.bundle/Root~ipad.plist | 4 +++- 7 files changed, 54 insertions(+), 23 deletions(-) diff --git a/clients/ios/Classes/FeedDetailViewController.m b/clients/ios/Classes/FeedDetailViewController.m index 8722c4cd6..ac2745a84 100644 --- a/clients/ios/Classes/FeedDetailViewController.m +++ b/clients/ios/Classes/FeedDetailViewController.m @@ -2500,11 +2500,7 @@ didEndSwipingSwipingWithState:(MCSwipeTableViewCellState)state } - (void)openStatisticsWithFeed:(NSString *)feedId { - NSString *urlString = [NSString stringWithFormat:@"%@/rss_feeds/statistics_embedded/%@", appDelegate.url, feedId]; - NSURL *url = [NSURL URLWithString:urlString]; - NSString *title = appDelegate.storiesCollection.activeFeed[@"feed_title"]; - - [appDelegate showInAppBrowser:url withCustomTitle:title fromBarButtonItem:settingsBarButton]; + [appDelegate openStatisticsWithFeed:feedId sender:settingsBarButton]; } - (void)openRenameSite { diff --git a/clients/ios/Classes/FeedTableCell.m b/clients/ios/Classes/FeedTableCell.m index 57dc5ff0c..807aa8042 100644 --- a/clients/ios/Classes/FeedTableCell.m +++ b/clients/ios/Classes/FeedTableCell.m @@ -90,12 +90,21 @@ static UIFont *textFont = nil; } NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults]; - BOOL isNotifications = [[preferences stringForKey:@"feed_swipe_left"] - isEqualToString:@"notifications"]; + NSString *swipe = [preferences stringForKey:@"feed_swipe_left"]; + NSString *iconName; + + if (self.isSocial) { + iconName = @"menu_icn_fetch_subscribers.png"; + } else if ([swipe isEqualToString:@"notifications"]) { + iconName = @"menu_icn_notifications.png"; + } else if ([swipe isEqualToString:@"statistics"]) { + iconName = @"menu_icn_statistics.png"; + } else { + iconName = @"train.png"; + } + [self setDelegate:(NewsBlurViewController *)appDelegate.feedsViewController]; - [self setFirstStateIconName:(self.isSocial ? @"menu_icn_fetch_subscribers.png" : - isNotifications ? @"menu_icn_notifications.png" : - @"train.png") + [self setFirstStateIconName:(iconName) firstColor:UIColorFromRGB(0xA4D97B) secondStateIconName:nil secondColor:nil diff --git a/clients/ios/Classes/NewsBlurAppDelegate.h b/clients/ios/Classes/NewsBlurAppDelegate.h index 01a9daee1..456f37e9a 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.h +++ b/clients/ios/Classes/NewsBlurAppDelegate.h @@ -321,6 +321,7 @@ SFSafariViewControllerDelegate> { - (void)openNotificationsWithFeed:(NSString *)feedId sender:(id)sender; - (void)updateNotifications:(NSDictionary *)params feed:(NSString *)feedId; - (void)checkForFeedNotifications; +- (void)openStatisticsWithFeed:(NSString *)feedId sender:(id)sender; - (void)openTrainSiteWithFeedLoaded:(BOOL)feedLoaded from:(id)sender; - (void)openTrainStory:(id)sender; - (void)openUserTagsStory:(id)sender; @@ -357,7 +358,7 @@ SFSafariViewControllerDelegate> { - (void)reloadFeedsView:(BOOL)showLoader; - (void)setTitle:(NSString *)title; - (void)showOriginalStory:(NSURL *)url; -- (void)showInAppBrowser:(NSURL *)url withCustomTitle:(NSString *)customTitle fromBarButtonItem:(UIBarButtonItem *)barButtonItem; +- (void)showInAppBrowser:(NSURL *)url withCustomTitle:(NSString *)customTitle fromSender:(id)sender; - (void)showSafariViewControllerWithURL:(NSURL *)url useReader:(BOOL)useReader; - (void)closeOriginalStory; - (void)hideStoryDetailView; diff --git a/clients/ios/Classes/NewsBlurAppDelegate.m b/clients/ios/Classes/NewsBlurAppDelegate.m index c1c557557..591f7b704 100644 --- a/clients/ios/Classes/NewsBlurAppDelegate.m +++ b/clients/ios/Classes/NewsBlurAppDelegate.m @@ -1272,6 +1272,15 @@ }]; } +- (void)openStatisticsWithFeed:(NSString *)feedId sender:(id)sender { + NSString *urlString = [NSString stringWithFormat:@"%@/rss_feeds/statistics_embedded/%@", self.url, feedId]; + NSURL *url = [NSURL URLWithString:urlString]; + NSDictionary *feed = self.dictFeeds[feedId]; + NSString *title = feed[@"feed_title"]; + + [self showInAppBrowser:url withCustomTitle:title fromSender:sender]; +} + - (void)openUserTagsStory:(id)sender { if (!self.userTagsViewController) { self.userTagsViewController = [[UserTagsViewController alloc] init]; @@ -2066,11 +2075,11 @@ } else if ([storyBrowser isEqualToString:@"inappsafarireader"]) { [self showSafariViewControllerWithURL:url useReader:YES]; } else { - [self showInAppBrowser:url withCustomTitle:nil fromBarButtonItem:nil]; + [self showInAppBrowser:url withCustomTitle:nil fromSender:nil]; } } -- (void)showInAppBrowser:(NSURL *)url withCustomTitle:(NSString *)customTitle fromBarButtonItem:(UIBarButtonItem *)barButtonItem { +- (void)showInAppBrowser:(NSURL *)url withCustomTitle:(NSString *)customTitle fromSender:(id)sender { if (!originalStoryViewController) { originalStoryViewController = [[OriginalStoryViewController alloc] init]; } @@ -2079,10 +2088,16 @@ originalStoryViewController.customPageTitle = customTitle; if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) { - if (barButtonItem) { + if ([sender isKindOfClass:[UIBarButtonItem class]]) { [originalStoryViewController view]; // Force viewDidLoad [originalStoryViewController loadInitialStory]; - [self showPopoverWithViewController:originalStoryViewController contentSize:CGSizeMake(600.0, 1000.0) barButtonItem:barButtonItem]; + [self showPopoverWithViewController:originalStoryViewController contentSize:CGSizeMake(600.0, 1000.0) barButtonItem:sender]; + } else if ([sender isKindOfClass:[UITableViewCell class]]) { + UITableViewCell *cell = (UITableViewCell *)sender; + + [originalStoryViewController view]; // Force viewDidLoad + [originalStoryViewController loadInitialStory]; + [self showPopoverWithViewController:originalStoryViewController contentSize:CGSizeMake(600.0, 1000.0) sourceView:cell sourceRect:cell.bounds]; } else { [self.masterContainerViewController transitionToOriginalView]; } diff --git a/clients/ios/Classes/NewsBlurViewController.m b/clients/ios/Classes/NewsBlurViewController.m index 6bdccc486..94e4cd22f 100644 --- a/clients/ios/Classes/NewsBlurViewController.m +++ b/clients/ios/Classes/NewsBlurViewController.m @@ -1553,12 +1553,18 @@ heightForHeaderInSection:(NSInteger)section { appDelegate.activeUserProfileId = [NSString stringWithFormat:@"%@", [feed objectForKey:@"user_id"]]; appDelegate.activeUserProfileName = [NSString stringWithFormat:@"%@", [feed objectForKey:@"username"]]; [appDelegate showUserProfileModal:cell]; - } else if ([[preferences stringForKey:@"feed_swipe_left"] isEqualToString:@"notifications"]) { - [appDelegate openNotificationsWithFeed:feedId sender:cell]; } else { - // Train - appDelegate.storiesCollection.activeFeed = [appDelegate.dictFeeds objectForKey:feedId]; - [appDelegate openTrainSiteWithFeedLoaded:NO from:cell]; + NSString *swipe = [preferences stringForKey:@"feed_swipe_left"]; + + if ([swipe isEqualToString:@"notifications"]) { + [appDelegate openNotificationsWithFeed:feedId sender:cell]; + } else if ([swipe isEqualToString:@"statistics"]) { + [appDelegate openStatisticsWithFeed:feedId sender:cell]; + } else { + // Train + appDelegate.storiesCollection.activeFeed = [appDelegate.dictFeeds objectForKey:feedId]; + [appDelegate openTrainSiteWithFeedLoaded:NO from:cell]; + } } } else if (state == MCSwipeTableViewCellState3) { // Mark read diff --git a/clients/ios/Resources/Settings.bundle/Root.plist b/clients/ios/Resources/Settings.bundle/Root.plist index 982508245..9f8997633 100644 --- a/clients/ios/Resources/Settings.bundle/Root.plist +++ b/clients/ios/Resources/Settings.bundle/Root.plist @@ -672,14 +672,16 @@ Titles Train intelligence - Notifications + Notifications + Statistics DefaultValue notifications Values trainer - notifications + notifications + statistics Key feed_swipe_left diff --git a/clients/ios/Resources/Settings.bundle/Root~ipad.plist b/clients/ios/Resources/Settings.bundle/Root~ipad.plist index 57b8b8c83..a1ff57845 100644 --- a/clients/ios/Resources/Settings.bundle/Root~ipad.plist +++ b/clients/ios/Resources/Settings.bundle/Root~ipad.plist @@ -693,13 +693,15 @@ Train intelligence Notifications + Statistics DefaultValue notifications Values trainer - notifications + notifications + statistics Key feed_swipe_left