| Index: ios/chrome/browser/ui/reading_list/reading_list_view_controller.mm
|
| diff --git a/ios/chrome/browser/ui/reading_list/reading_list_view_controller.mm b/ios/chrome/browser/ui/reading_list/reading_list_view_controller.mm
|
| index 96d7bb9a1e99cf924edbb6fcb23c5285c7ce99aa..4c32d3f7bf9ecb5b97a84846995bfcbba45f5d01 100644
|
| --- a/ios/chrome/browser/ui/reading_list/reading_list_view_controller.mm
|
| +++ b/ios/chrome/browser/ui/reading_list/reading_list_view_controller.mm
|
| @@ -19,8 +19,6 @@
|
| #include "components/url_formatter/url_formatter.h"
|
| #include "ios/chrome/browser/reading_list/offline_url_utils.h"
|
| #include "ios/chrome/browser/reading_list/reading_list_download_service.h"
|
| -#import "ios/chrome/browser/tabs/tab.h"
|
| -#import "ios/chrome/browser/tabs/tab_model.h"
|
| #import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
|
| #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
|
| #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
|
| @@ -126,6 +124,10 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| - (BOOL)hasItemInSection:(SectionIdentifier)sectionIdentifier;
|
| // Adds an empty background if needed.
|
| - (void)collectionIsEmpty;
|
| +// Handles a long press.
|
| +- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer;
|
| +// Stops observing the ReadingListModel.
|
| +- (void)stopObservingReadingListModel;
|
| // Updates the toolbar state according to the selected items.
|
| - (void)updateToolbarState;
|
| // Displays an action sheet to let the user choose to mark all the elements as
|
| @@ -186,16 +188,14 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
|
|
| @implementation ReadingListViewController
|
| @synthesize readingListModel = _readingListModel;
|
| -@synthesize tabModel = _tabModel;
|
| @synthesize largeIconService = _largeIconService;
|
| @synthesize readingListDownloadService = _readingListDownloadService;
|
| @synthesize attributesProvider = _attributesProvider;
|
| -@synthesize audience = _audience;
|
| +@synthesize delegate = _delegate;
|
|
|
| #pragma mark lifecycle
|
|
|
| - (instancetype)initWithModel:(ReadingListModel*)model
|
| - tabModel:(TabModel*)tabModel
|
| largeIconService:(favicon::LargeIconService*)largeIconService
|
| readingListDownloadService:
|
| (ReadingListDownloadService*)readingListDownloadService
|
| @@ -206,7 +206,6 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| _toolbar = toolbar;
|
|
|
| _readingListModel = model;
|
| - _tabModel = tabModel;
|
| _largeIconService = largeIconService;
|
| _readingListDownloadService = readingListDownloadService;
|
| _emptyCollectionBackground = [self emptyCollectionBackground];
|
| @@ -237,10 +236,11 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| [_toolbar setState:toolbarState];
|
| }
|
|
|
| -- (void)setAudience:(id<ReadingListViewControllerAudience>)audience {
|
| - _audience = audience;
|
| +- (void)setDelegate:(id<ReadingListViewControllerDelegate>)delegate {
|
| + _delegate = delegate;
|
| if (self.readingListModel->loaded())
|
| - [audience setCollectionHasItems:self.readingListModel->size() > 0];
|
| + [delegate readingListViewController:self
|
| + hasItems:(self.readingListModel->size() > 0)];
|
| }
|
|
|
| #pragma mark - UIViewController
|
| @@ -262,6 +262,12 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| // Customize collection view settings.
|
| self.styler.cellStyle = MDCCollectionViewCellStyleCard;
|
| self.styler.separatorInset = UIEdgeInsetsMake(0, 16, 0, 16);
|
| +
|
| + UILongPressGestureRecognizer* longPressRecognizer =
|
| + [[UILongPressGestureRecognizer alloc]
|
| + initWithTarget:self
|
| + action:@selector(handleLongPress:)];
|
| + [self.collectionView addGestureRecognizer:longPressRecognizer];
|
| }
|
|
|
| #pragma mark - UICollectionViewDelegate
|
| @@ -287,7 +293,8 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| if (self.editor.editing) {
|
| [self updateToolbarState];
|
| } else {
|
| - [self openItemAtIndexPath:indexPath];
|
| + [self.delegate readingListViewController:self
|
| + openItemAtIndexPath:indexPath];
|
| }
|
| }
|
|
|
| @@ -368,7 +375,16 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| [self reloadData];
|
| }
|
|
|
| -#pragma mark - private methods
|
| +#pragma mark - Public methods
|
| +
|
| +- (void)reloadData {
|
| + [self loadModel];
|
| + if ([self isViewLoaded]) {
|
| + [self.collectionView reloadData];
|
| + }
|
| +}
|
| +
|
| +#pragma mark - Private methods
|
|
|
| - (UIView*)emptyCollectionBackground {
|
| UIView* emptyCollectionBackground = [[UIView alloc] initWithFrame:CGRectZero];
|
| @@ -449,30 +465,6 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| return emptyCollectionBackground;
|
| }
|
|
|
| -- (void)openItemAtIndexPath:(NSIndexPath*)indexPath {
|
| - ReadingListCollectionViewItem* readingListItem =
|
| - base::mac::ObjCCastStrict<ReadingListCollectionViewItem>(
|
| - [self.collectionViewModel itemAtIndexPath:indexPath]);
|
| - const ReadingListEntry* entry =
|
| - self.readingListModel->GetEntryByURL(readingListItem.url);
|
| - if (!entry) {
|
| - [self reloadData];
|
| - return;
|
| - }
|
| -
|
| - base::RecordAction(base::UserMetricsAction("MobileReadingListOpen"));
|
| -
|
| - // Reset observer to prevent further model update notifications.
|
| - _modelBridge.reset();
|
| -
|
| - Tab* currentTab = _tabModel.currentTab;
|
| - DCHECK(currentTab);
|
| - web::NavigationManager::WebLoadParams params(entry->URL());
|
| - params.transition_type = ui::PageTransition::PAGE_TRANSITION_AUTO_BOOKMARK;
|
| - [currentTab webState]->GetNavigationManager()->LoadURLWithParams(params);
|
| - [self dismiss];
|
| -}
|
| -
|
| - (void)donePressed {
|
| if ([self.editor isEditing]) {
|
| [self exitEditingModeAnimated:NO];
|
| @@ -483,9 +475,9 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| - (void)dismiss {
|
| _readingListModel->MarkAllSeen();
|
| // Reset observer to prevent further model update notifications.
|
| - _modelBridge.reset();
|
| + [self stopObservingReadingListModel];
|
| [_actionSheet stop];
|
| - [self.audience dismiss];
|
| + [self.delegate dismissReadingListViewController:self];
|
| }
|
|
|
| - (void)loadModel {
|
| @@ -497,7 +489,7 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| self.collectionView.alwaysBounceVertical = YES;
|
| [self loadItems];
|
| self.collectionView.backgroundView = nil;
|
| - [self.audience setCollectionHasItems:YES];
|
| + [self.delegate readingListViewController:self hasItems:YES];
|
| }
|
| }
|
|
|
| @@ -542,13 +534,6 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| }
|
| }
|
|
|
| -- (void)reloadData {
|
| - [self loadModel];
|
| - if ([self isViewLoaded]) {
|
| - [self.collectionView reloadData];
|
| - }
|
| -}
|
| -
|
| - (void)applyPendingUpdates {
|
| if (_modelHasBeenModified) {
|
| [self reloadData];
|
| @@ -634,7 +619,17 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
|
| // The collection is empty, add background.
|
| self.collectionView.alwaysBounceVertical = NO;
|
| self.collectionView.backgroundView = _emptyCollectionBackground;
|
| - [self.audience setCollectionHasItems:NO];
|
| + [self.delegate readingListViewController:self hasItems:NO];
|
| +}
|
| +
|
| +- (void)handleLongPress:(UILongPressGestureRecognizer*)gestureRecognizer {
|
| + [self.delegate readingListViewController:self
|
| + didRecognizeLongPress:gestureRecognizer
|
| + duringEdit:self.editor.editing];
|
| +}
|
| +
|
| +- (void)stopObservingReadingListModel {
|
| + _modelBridge.reset();
|
| }
|
|
|
| #pragma mark - ReadingListToolbarDelegate
|
|
|