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

Unified Diff: ios/chrome/browser/ui/history/history_collection_view_controller.mm

Issue 2800473004: [ios] Inserts and deletes history items in the same BatchUpdates block (Closed)
Patch Set: Refactor Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/chrome/browser/ui/history/history_collection_view_controller.mm
diff --git a/ios/chrome/browser/ui/history/history_collection_view_controller.mm b/ios/chrome/browser/ui/history/history_collection_view_controller.mm
index 4fdf911823afc17d06ed682ae366b2d0b80e929d..0d7737b4cb017d5aba6f0a27f68f9359b830a609 100644
--- a/ios/chrome/browser/ui/history/history_collection_view_controller.mm
+++ b/ios/chrome/browser/ui/history/history_collection_view_controller.mm
@@ -108,14 +108,20 @@ const CGFloat kSeparatorInset = 10;
// the empty string, all history is fetched.
- (void)fetchHistoryForQuery:(NSString*)query
priorToTime:(const base::Time&)time;
+// Updates various elements after history items have been deleted from the
+// CollectionView.
+- (void)updateCollectionViewAfterDeletingEntries;
// Updates header section to provide relevant information about the currently
// displayed history entries.
- (void)updateEntriesStatusMessage;
// Removes selected items from the visible collection, but does not delete them
// from browser history.
- (void)removeSelectedItemsFromCollection;
-// Removes all items in the collection that are not included in entries.
+// Selects all items in the collection that are not included in entries.
- (void)filterForHistoryEntries:(NSArray*)entries;
+// Deletes all items in the collection which indexes are included in indexArray,
+// needs to be run inside a performBatchUpdates block.
+- (void)deleteItemsFromCollectionViewModelWithIndex:(NSArray*)indexArray;
// Adds loading indicator to the top of the history collection, if one is not
// already present.
- (void)addLoadingIndicator;
@@ -370,16 +376,20 @@ const CGFloat kSeparatorInset = 10;
}
}
[self.delegate historyCollectionViewControllerDidChangeEntries:self];
+ if (([self isSearching] && [searchQuery length] > 0 &&
+ [self.currentQuery isEqualToString:searchQuery]) ||
+ self.filterQueryResult) {
+ // If in search mode, filter out entries that are not
+ // part of the search result.
+ [self filterForHistoryEntries:filterResults];
+ NSArray* deletedIndexPaths =
+ self.collectionView.indexPathsForSelectedItems;
+ [self deleteItemsFromCollectionViewModelWithIndex:deletedIndexPaths];
+ self.filterQueryResult = NO;
+ }
}
completion:^(BOOL) {
- if (([self isSearching] && [searchQuery length] > 0 &&
- [self.currentQuery isEqualToString:searchQuery]) ||
- self.filterQueryResult) {
- // If in search mode, filter out entries that are not
- // part of the search result.
- [self filterForHistoryEntries:filterResults];
- self.filterQueryResult = NO;
- }
+ [self updateCollectionViewAfterDeletingEntries];
}];
}
@@ -564,6 +574,15 @@ const CGFloat kSeparatorInset = 10;
_historyServiceFacade->QueryOtherFormsOfBrowsingHistory();
}
+- (void)updateCollectionViewAfterDeletingEntries {
+ // If only the header section remains, there are no history entries.
+ if ([self.collectionViewModel numberOfSections] == 1) {
+ self.entriesType = NO_ENTRIES;
+ }
+ [self updateEntriesStatusMessage];
+ [self.delegate historyCollectionViewControllerDidChangeEntries:self];
+}
+
- (void)updateEntriesStatusMessage {
CollectionViewItem* entriesStatusItem = nil;
if (!self.hasHistoryEntries) {
@@ -618,28 +637,27 @@ const CGFloat kSeparatorInset = 10;
- (void)removeSelectedItemsFromCollection {
NSArray* deletedIndexPaths = self.collectionView.indexPathsForSelectedItems;
[self.collectionView performBatchUpdates:^{
- [self collectionView:self.collectionView
- willDeleteItemsAtIndexPaths:deletedIndexPaths];
- [self.collectionView deleteItemsAtIndexPaths:deletedIndexPaths];
-
- // Remove any empty sections, except the header section.
- for (int section = self.collectionView.numberOfSections - 1; section > 0;
- --section) {
- if (![self.collectionViewModel numberOfItemsInSection:section]) {
- [self.entryInserter removeSection:section];
- }
- }
+ [self deleteItemsFromCollectionViewModelWithIndex:deletedIndexPaths];
}
completion:^(BOOL) {
- // If only the header section remains, there are no history entries.
- if ([self.collectionViewModel numberOfSections] == 1) {
- self.entriesType = NO_ENTRIES;
- }
- [self updateEntriesStatusMessage];
- [self.delegate historyCollectionViewControllerDidChangeEntries:self];
+ [self updateCollectionViewAfterDeletingEntries];
}];
}
+- (void)deleteItemsFromCollectionViewModelWithIndex:(NSArray*)indexArray {
+ [self collectionView:self.collectionView
+ willDeleteItemsAtIndexPaths:indexArray];
+ [self.collectionView deleteItemsAtIndexPaths:indexArray];
+
+ // Remove any empty sections, except the header section.
+ for (int section = self.collectionView.numberOfSections - 1; section > 0;
+ --section) {
+ if (![self.collectionViewModel numberOfItemsInSection:section]) {
+ [self.entryInserter removeSection:section];
+ }
+ }
+}
+
- (void)filterForHistoryEntries:(NSArray*)entries {
self.collectionView.allowsMultipleSelection = YES;
for (int section = 1; section < [self.collectionViewModel numberOfSections];
@@ -665,7 +683,6 @@ const CGFloat kSeparatorInset = 10;
}
}
}
- [self removeSelectedItemsFromCollection];
}
- (void)addLoadingIndicator {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698