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

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

Issue 2659693004: Add context menu when long press on a reading list entry (Closed)
Patch Set: Cleanup Created 3 years, 11 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_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..68828c41da9d60b8613f7f102dc75f374d8aad03 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,8 @@ 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;
// 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 +186,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 +204,6 @@ using ItemsMapByDate = std::multimap<int64_t, ReadingListCollectionViewItem*>;
_toolbar = toolbar;
_readingListModel = model;
- _tabModel = tabModel;
_largeIconService = largeIconService;
_readingListDownloadService = readingListDownloadService;
_emptyCollectionBackground = [self emptyCollectionBackground];
@@ -237,10 +234,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];
stkhapugin 2017/01/30 10:34:53 nit: parenthesis around hasItems: argument
gambard 2017/01/31 09:35:40 Done.
}
#pragma mark - UIViewController
@@ -262,6 +260,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 +291,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 +373,20 @@ 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];
+ }
+}
+
+- (void)stopObservingReadingListModel {
+ _modelBridge.reset();
+}
+
+#pragma mark - Private methods
- (UIView*)emptyCollectionBackground {
UIView* emptyCollectionBackground = [[UIView alloc] initWithFrame:CGRectZero];
@@ -449,30 +467,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 +477,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 +491,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 +536,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 +621,13 @@ 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];
}
#pragma mark - ReadingListToolbarDelegate

Powered by Google App Engine
This is Rietveld 408576698