Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1913)

Unified Diff: ios/chrome/browser/ui/reading_list/reading_list_coordinator.mm

Issue 2693863005: Create ReadingListCoordinator (Closed)
Patch Set: Address comments Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/reading_list/reading_list_coordinator.mm
diff --git a/ios/chrome/browser/ui/reading_list/reading_list_view_controller.mm b/ios/chrome/browser/ui/reading_list/reading_list_coordinator.mm
similarity index 56%
copy from ios/chrome/browser/ui/reading_list/reading_list_view_controller.mm
copy to ios/chrome/browser/ui/reading_list/reading_list_coordinator.mm
index 253ce8479d2a567843a2d008f2d8496aa5f9c2d7..1958db54722370ae27e078d8e68696ca5686e25b 100644
--- a/ios/chrome/browser/ui/reading_list/reading_list_view_controller.mm
+++ b/ios/chrome/browser/ui/reading_list/reading_list_coordinator.mm
@@ -1,29 +1,30 @@
-// Copyright 2016 The Chromium Authors. All rights reserved.
+// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#import "ios/chrome/browser/ui/reading_list/reading_list_view_controller.h"
-
-#import <MobileCoreServices/MobileCoreServices.h>
+#import "ios/chrome/browser/ui/reading_list/reading_list_coordinator.h"
#include "base/metrics/histogram_macros.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "components/reading_list/ios/reading_list_model.h"
+#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
+#include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h"
#include "ios/chrome/browser/reading_list/offline_url_utils.h"
+#include "ios/chrome/browser/reading_list/reading_list_download_service.h"
+#include "ios/chrome/browser/reading_list/reading_list_download_service_factory.h"
+#include "ios/chrome/browser/reading_list/reading_list_model_factory.h"
#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
-#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
-#import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h"
-#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_controller.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_toolbar.h"
-#import "ios/chrome/browser/ui/uikit_ui_util.h"
+#import "ios/chrome/browser/ui/reading_list/reading_list_view_controller.h"
#import "ios/chrome/browser/ui/url_loader.h"
#import "ios/chrome/browser/ui/util/pasteboard_util.h"
#include "ios/chrome/grit/ios_strings.h"
-#include "ios/web/public/navigation_manager.h"
+#include "ios/web/public/referrer.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/strings/grit/ui_strings.h"
+#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
@@ -46,37 +47,19 @@ enum UMAContextMenuAction {
// Add new enum above ENUM_MAX.
ENUM_MAX
};
-
-// Height of the toolbar in normal state.
-const int kToolbarNormalHeight = 48;
-// Height of the expanded toolbar (buttons on multiple lines).
-const int kToolbarExpandedHeight = 58;
-
-typedef NS_ENUM(NSInteger, LayoutPriority) {
- LayoutPriorityLow = 750,
- LayoutPriorityHigh = 751
-};
}
-@interface ReadingListViewController ()<ReadingListToolbarActions,
- ReadingListToolbarHeightDelegate> {
- // Toolbar with the actions.
- ReadingListToolbar* _toolbar;
- // This constraint control the expanded mode of the toolbar.
- NSLayoutConstraint* _expandedToolbarConstraint;
- // Coordinator for the alert displayed when the user long presses an entry.
- AlertCoordinator* _alertCoordinator;
-}
+@interface ReadingListCoordinator ()
-// UrlLoader for navigating to entries.
-@property(nonatomic, weak, readonly) id<UrlLoader> URLLoader;
-@property(nonatomic, strong, readonly)
- ReadingListCollectionViewController* readingListCollectionViewController;
+@property(nonatomic, assign) ios::ChromeBrowserState* browserState;
+// Used to load the Reading List pages.
+@property(nonatomic, weak) id<UrlLoader> URLLoader;
+@property(nonatomic, strong) ReadingListViewController* containerViewController;
+@property(nonatomic, strong) AlertCoordinator* alertCoordinator;
-// Closes the ReadingList view.
-- (void)dismiss;
// Opens |URL| in a new tab |incognito| or not.
- (void)openNewTabWithURL:(const GURL&)URL incognito:(BOOL)incognito;
+
// Opens the offline url |offlineURL| of the entry saved in the reading list
// model with the |entryURL| url.
- (void)openOfflineURL:(const GURL&)offlineURL
@@ -87,105 +70,72 @@ typedef NS_ENUM(NSInteger, LayoutPriority) {
@end
-@implementation ReadingListViewController
+@implementation ReadingListCoordinator
-@synthesize readingListCollectionViewController =
- _readingListCollectionViewController;
+@synthesize alertCoordinator = _alertCoordinator;
+@synthesize containerViewController = _containerViewController;
@synthesize URLLoader = _URLLoader;
+@synthesize browserState = _browserState;
-- (instancetype)initWithModel:(ReadingListModel*)model
- loader:(id<UrlLoader>)loader
- largeIconService:(favicon::LargeIconService*)largeIconService
- readingListDownloadService:
- (ReadingListDownloadService*)readingListDownloadService {
- self = [super initWithNibName:nil bundle:nil];
+- (instancetype)initWithBaseViewController:(UIViewController*)viewController
+ browserState:
+ (ios::ChromeBrowserState*)browserState
+ loader:(id<UrlLoader>)loader {
+ self = [super initWithBaseViewController:viewController];
if (self) {
+ _browserState = browserState;
_URLLoader = loader;
- _toolbar = [[ReadingListToolbar alloc] initWithFrame:CGRectZero];
- _toolbar.heightDelegate = self;
- _readingListCollectionViewController =
+ }
+ return self;
+}
+
+#pragma mark - ChromeCoordinator
+
+- (void)start {
+ if (!self.containerViewController) {
+ ReadingListModel* model =
+ ReadingListModelFactory::GetInstance()->GetForBrowserState(
+ self.browserState);
+ favicon::LargeIconService* largeIconService =
+ IOSChromeLargeIconServiceFactory::GetForBrowserState(self.browserState);
+ ReadingListDownloadService* readingListDownloadService =
+ ReadingListDownloadServiceFactory::GetInstance()->GetForBrowserState(
+ self.browserState);
+
+ ReadingListToolbar* toolbar = [[ReadingListToolbar alloc] init];
+ ReadingListCollectionViewController* collectionViewController =
[[ReadingListCollectionViewController alloc]
initWithModel:model
largeIconService:largeIconService
readingListDownloadService:readingListDownloadService
- toolbar:_toolbar];
- _readingListCollectionViewController.delegate = self;
+ toolbar:toolbar];
+ collectionViewController.delegate = self;
- // Configure modal presentation.
- [self setModalPresentationStyle:UIModalPresentationFormSheet];
- [self setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
+ self.containerViewController = [[ReadingListViewController alloc]
+ initWithCollectionViewController:collectionViewController
+ toolbar:toolbar];
+ self.containerViewController.delegate = self;
}
- return self;
-}
-
-- (void)viewDidLoad {
- [self addChildViewController:self.readingListCollectionViewController];
- [self.view addSubview:self.readingListCollectionViewController.view];
- [self.readingListCollectionViewController didMoveToParentViewController:self];
-
- [_toolbar setTranslatesAutoresizingMaskIntoConstraints:NO];
- [self.readingListCollectionViewController.view
- setTranslatesAutoresizingMaskIntoConstraints:NO];
-
- NSDictionary* views =
- @{ @"collection" : self.readingListCollectionViewController.view };
- NSArray* constraints = @[ @"V:|[collection]", @"H:|[collection]|" ];
- ApplyVisualConstraints(constraints, views);
-
- // This constraint has a low priority so it will only take effect when the
- // toolbar isn't present, allowing the collection to take the whole page.
- NSLayoutConstraint* constraint =
- [self.readingListCollectionViewController.view.bottomAnchor
- constraintEqualToAnchor:self.view.bottomAnchor];
- constraint.priority = LayoutPriorityLow;
- constraint.active = YES;
-}
-- (BOOL)prefersStatusBarHidden {
- return NO;
+ [self.baseViewController presentViewController:self.containerViewController
+ animated:YES
+ completion:nil];
}
-#pragma mark UIAccessibilityAction
+- (void)stop {
+ [self.containerViewController.presentingViewController
+ dismissViewControllerAnimated:YES
+ completion:nil];
-- (BOOL)accessibilityPerformEscape {
- [self dismiss];
- return YES;
+ self.containerViewController = nil;
}
#pragma mark - ReadingListCollectionViewControllerDelegate
-- (void)readingListCollectionViewController:
- (ReadingListCollectionViewController*)
- readingListCollectionViewController
- hasItems:(BOOL)hasItems {
- if (hasItems) {
- // If there are items, add the toolbar.
- [self.view addSubview:_toolbar];
- NSDictionary* views = @{
- @"toolbar" : _toolbar,
- @"collection" : readingListCollectionViewController.view
- };
- NSArray* constraints = @[ @"V:[collection][toolbar]|", @"H:|[toolbar]|" ];
- ApplyVisualConstraints(constraints, views);
- NSLayoutConstraint* height =
- [_toolbar.heightAnchor constraintEqualToConstant:kToolbarNormalHeight];
- height.priority = LayoutPriorityHigh;
- height.active = YES;
- // When the toolbar is added, the only button is the "edit" button. No need
- // to go in expanded mode.
- _expandedToolbarConstraint = [_toolbar.heightAnchor
- constraintEqualToConstant:kToolbarExpandedHeight];
- } else {
- // If there is no item, remove the toolbar. The constraints will make sure
- // the collection takes the whole view.
- [_toolbar removeFromSuperview];
- }
-}
-
- (void)dismissReadingListCollectionViewController:
(ReadingListCollectionViewController*)readingListCollectionViewController {
[readingListCollectionViewController willBeDismissed];
- [self dismiss];
+ [self stop];
}
- (void)readingListCollectionViewController:
@@ -194,6 +144,10 @@ typedef NS_ENUM(NSInteger, LayoutPriority) {
displayContextMenuForItem:
(ReadingListCollectionViewItem*)readingListItem
atPoint:(CGPoint)menuLocation {
+ if (!self.containerViewController) {
+ return;
+ }
+
const ReadingListEntry* entry =
readingListCollectionViewController.readingListModel->GetEntryByURL(
readingListItem.url);
@@ -204,10 +158,10 @@ typedef NS_ENUM(NSInteger, LayoutPriority) {
}
const GURL entryURL = entry->URL();
- __weak ReadingListViewController* weakSelf = self;
+ __weak ReadingListCoordinator* weakSelf = self;
_alertCoordinator = [[ActionSheetCoordinator alloc]
- initWithBaseViewController:self
+ initWithBaseViewController:self.containerViewController
title:readingListItem.text
message:readingListItem.detailText
rect:CGRectMake(menuLocation.x, menuLocation.y, 0,
@@ -299,63 +253,11 @@ readingListCollectionViewController:
transition:ui::PAGE_TRANSITION_AUTO_BOOKMARK
rendererInitiated:NO];
- [self dismiss];
-}
-
-#pragma mark - ReadingListToolbarActionTarget
-
-- (void)markPressed {
- [self.readingListCollectionViewController markPressed];
-}
-
-- (void)deletePressed {
- [self.readingListCollectionViewController deletePressed];
-}
-
-- (void)enterEditingModePressed {
- [self.readingListCollectionViewController enterEditingModePressed];
-}
-
-- (void)exitEditingModePressed {
- [self.readingListCollectionViewController exitEditingModePressed];
-}
-
-#pragma mark - ReadingListToolbarHeightDelegate
-
-- (void)toolbar:(id)toolbar onHeightChanged:(ReadingListToolbarHeight)height {
- dispatch_async(dispatch_get_main_queue(), ^{
- switch (height) {
- case NormalHeight:
- _expandedToolbarConstraint.active = NO;
- break;
-
- case ExpandedHeight:
- _expandedToolbarConstraint.active = YES;
- break;
- }
- });
+ [self stop];
}
#pragma mark - Private
-- (void)dismiss {
- [self.presentingViewController dismissViewControllerAnimated:YES
- completion:nil];
-}
-
-- (void)openNewTabWithURL:(const GURL&)URL incognito:(BOOL)incognito {
- base::RecordAction(base::UserMetricsAction("MobileReadingListOpen"));
-
- [self.URLLoader webPageOrderedOpen:URL
- referrer:web::Referrer()
- windowName:nil
- inIncognito:incognito
- inBackground:NO
- appendTo:kLastTab];
-
- [self dismiss];
-}
-
- (void)openOfflineURL:(const GURL&)offlineURL
correspondingEntryURL:(const GURL&)entryURL
fromReadingListCollectionViewController:
@@ -371,16 +273,17 @@ readingListCollectionViewController:
true);
}
-#pragma mark - UIResponder
+- (void)openNewTabWithURL:(const GURL&)URL incognito:(BOOL)incognito {
+ base::RecordAction(base::UserMetricsAction("MobileReadingListOpen"));
+
+ [self.URLLoader webPageOrderedOpen:URL
+ referrer:web::Referrer()
+ windowName:nil
+ inIncognito:incognito
+ inBackground:NO
+ appendTo:kLastTab];
-- (NSArray*)keyCommands {
- __weak ReadingListViewController* weakSelf = self;
- return @[ [UIKeyCommand cr_keyCommandWithInput:UIKeyInputEscape
- modifierFlags:Cr_UIKeyModifierNone
- title:nil
- action:^{
- [weakSelf dismiss];
- }] ];
+ [self stop];
}
@end

Powered by Google App Engine
This is Rietveld 408576698