Commit 3da34e94 authored by sczs's avatar sczs Committed by Commit bot

[ios] Inserts and deletes history items in the same BatchUpdates block

BUG=707241

Review-Url: https://codereview.chromium.org/2800473004
Cr-Commit-Position: refs/heads/master@{#462784}
parent 9c1cc6a2
...@@ -108,14 +108,20 @@ const CGFloat kSeparatorInset = 10; ...@@ -108,14 +108,20 @@ const CGFloat kSeparatorInset = 10;
// the empty string, all history is fetched. // the empty string, all history is fetched.
- (void)fetchHistoryForQuery:(NSString*)query - (void)fetchHistoryForQuery:(NSString*)query
priorToTime:(const base::Time&)time; 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 // Updates header section to provide relevant information about the currently
// displayed history entries. // displayed history entries.
- (void)updateEntriesStatusMessage; - (void)updateEntriesStatusMessage;
// Removes selected items from the visible collection, but does not delete them // Removes selected items from the visible collection, but does not delete them
// from browser history. // from browser history.
- (void)removeSelectedItemsFromCollection; - (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; - (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 // Adds loading indicator to the top of the history collection, if one is not
// already present. // already present.
- (void)addLoadingIndicator; - (void)addLoadingIndicator;
...@@ -370,16 +376,20 @@ const CGFloat kSeparatorInset = 10; ...@@ -370,16 +376,20 @@ const CGFloat kSeparatorInset = 10;
} }
} }
[self.delegate historyCollectionViewControllerDidChangeEntries:self]; [self.delegate historyCollectionViewControllerDidChangeEntries:self];
}
completion:^(BOOL) {
if (([self isSearching] && [searchQuery length] > 0 && if (([self isSearching] && [searchQuery length] > 0 &&
[self.currentQuery isEqualToString:searchQuery]) || [self.currentQuery isEqualToString:searchQuery]) ||
self.filterQueryResult) { self.filterQueryResult) {
// If in search mode, filter out entries that are not // If in search mode, filter out entries that are not
// part of the search result. // part of the search result.
[self filterForHistoryEntries:filterResults]; [self filterForHistoryEntries:filterResults];
NSArray* deletedIndexPaths =
self.collectionView.indexPathsForSelectedItems;
[self deleteItemsFromCollectionViewModelWithIndex:deletedIndexPaths];
self.filterQueryResult = NO; self.filterQueryResult = NO;
} }
}
completion:^(BOOL) {
[self updateCollectionViewAfterDeletingEntries];
}]; }];
} }
...@@ -564,6 +574,15 @@ const CGFloat kSeparatorInset = 10; ...@@ -564,6 +574,15 @@ const CGFloat kSeparatorInset = 10;
_historyServiceFacade->QueryOtherFormsOfBrowsingHistory(); _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 { - (void)updateEntriesStatusMessage {
CollectionViewItem* entriesStatusItem = nil; CollectionViewItem* entriesStatusItem = nil;
if (!self.hasHistoryEntries) { if (!self.hasHistoryEntries) {
...@@ -618,9 +637,17 @@ const CGFloat kSeparatorInset = 10; ...@@ -618,9 +637,17 @@ const CGFloat kSeparatorInset = 10;
- (void)removeSelectedItemsFromCollection { - (void)removeSelectedItemsFromCollection {
NSArray* deletedIndexPaths = self.collectionView.indexPathsForSelectedItems; NSArray* deletedIndexPaths = self.collectionView.indexPathsForSelectedItems;
[self.collectionView performBatchUpdates:^{ [self.collectionView performBatchUpdates:^{
[self deleteItemsFromCollectionViewModelWithIndex:deletedIndexPaths];
}
completion:^(BOOL) {
[self updateCollectionViewAfterDeletingEntries];
}];
}
- (void)deleteItemsFromCollectionViewModelWithIndex:(NSArray*)indexArray {
[self collectionView:self.collectionView [self collectionView:self.collectionView
willDeleteItemsAtIndexPaths:deletedIndexPaths]; willDeleteItemsAtIndexPaths:indexArray];
[self.collectionView deleteItemsAtIndexPaths:deletedIndexPaths]; [self.collectionView deleteItemsAtIndexPaths:indexArray];
// Remove any empty sections, except the header section. // Remove any empty sections, except the header section.
for (int section = self.collectionView.numberOfSections - 1; section > 0; for (int section = self.collectionView.numberOfSections - 1; section > 0;
...@@ -629,15 +656,6 @@ const CGFloat kSeparatorInset = 10; ...@@ -629,15 +656,6 @@ const CGFloat kSeparatorInset = 10;
[self.entryInserter removeSection:section]; [self.entryInserter removeSection:section];
} }
} }
}
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];
}];
} }
- (void)filterForHistoryEntries:(NSArray*)entries { - (void)filterForHistoryEntries:(NSArray*)entries {
...@@ -665,7 +683,6 @@ const CGFloat kSeparatorInset = 10; ...@@ -665,7 +683,6 @@ const CGFloat kSeparatorInset = 10;
} }
} }
} }
[self removeSelectedItemsFromCollection];
} }
- (void)addLoadingIndicator { - (void)addLoadingIndicator {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment