Commit ff8a8087 authored by Huanzhong Huang's avatar Huanzhong Huang Committed by Commit Bot

[iOS] CBD cell selection maintenance

- Previously in Clear Browsing Data, a selection of a cell is immediately
followed by a deselection along with UI update (checkmark in accessory view).
- With the new CBD UI being introduced, the selection state of cells becomes
relevant and should be handled and maintained.

Detail outline:
- Reconfigure instead of reload a cell upon browsing data counter finish
counting, as a reload clears a cell's selection state.
- Cell pre-selection according to browser state, whenever |viewWillAppear:|
is invoked.
- Have separate |tableView:didSelect...| and |tableView:didDeselect...|
implementations.
- Should introduce no effect when new-clear-browsing-data-ui is disabled.

Bug: 935346
Change-Id: I6b224e5d6ac05f5a3506668f8d6a68d3353fc897
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1551779
Commit-Queue: Huanzhong Huang <huanzhong@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#648651}
parent 0d2c4b6a
...@@ -138,7 +138,7 @@ const CGFloat kSeparationSpaceBetweenSections = 9; ...@@ -138,7 +138,7 @@ const CGFloat kSeparationSpaceBetweenSections = 9;
// Align cell separators with text label leading margin. // Align cell separators with text label leading margin.
[self.tableView [self.tableView
setSeparatorInset:UIEdgeInsetsMake(0, kTableViewHorizontalSpacing, 0, 0)]; setSeparatorInset:UIEdgeInsetsMake(0, kTableViewHorizontalSpacing, 0, 0)];
self.tableView.allowsMultipleSelection = YES;
// Navigation controller configuration. // Navigation controller configuration.
self.title = l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_TITLE); self.title = l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_TITLE);
// Adds the "Done" button and hooks it up to |dismiss|. // Adds the "Done" button and hooks it up to |dismiss|.
...@@ -160,7 +160,22 @@ const CGFloat kSeparationSpaceBetweenSections = 9; ...@@ -160,7 +160,22 @@ const CGFloat kSeparationSpaceBetweenSections = 9;
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated]; [super viewWillAppear:animated];
[self.dataManager restartCounters:BrowsingDataRemoveMask::REMOVE_ALL]; [self.dataManager restartCounters:BrowsingDataRemoveMask::REMOVE_ALL];
if (IsNewClearBrowsingDataUIEnabled()) { if (IsNewClearBrowsingDataUIEnabled()) {
// Select those cells correspond to a checked item.
NSArray* dataTypeItems = [self.tableViewModel
itemsInSectionWithIdentifier:SectionIdentifierDataTypes];
for (TableViewClearBrowsingDataItem* dataTypeItem in dataTypeItems) {
DCHECK(
[dataTypeItem isKindOfClass:[TableViewClearBrowsingDataItem class]]);
if (dataTypeItem.checked) {
[self.tableView selectRowAtIndexPath:[self.tableViewModel
indexPathForItem:dataTypeItem]
animated:NO
scrollPosition:UITableViewScrollPositionNone];
}
}
// Showing toolbar here because parent class hides toolbar in // Showing toolbar here because parent class hides toolbar in
// viewWillDisappear:. // viewWillDisappear:.
self.navigationController.toolbarHidden = NO; self.navigationController.toolbarHidden = NO;
...@@ -237,18 +252,41 @@ const CGFloat kSeparationSpaceBetweenSections = 9; ...@@ -237,18 +252,41 @@ const CGFloat kSeparationSpaceBetweenSections = 9;
- (void)tableView:(UITableView*)tableView - (void)tableView:(UITableView*)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath { didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
if (!IsNewClearBrowsingDataUIEnabled()) {
[self tableView:tableView legacyDidSelectRowAtIndexPath:indexPath];
} else {
TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath];
DCHECK(item);
switch (item.type) {
case ItemTypeTimeRange: {
UIViewController* controller =
[[TimeRangeSelectorTableViewController alloc]
initWithPrefs:self.browserState->GetPrefs()
delegate:self.dataManager];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
[self.navigationController pushViewController:controller animated:YES];
break;
}
case ItemTypeDataTypeBrowsingHistory:
case ItemTypeDataTypeCookiesSiteData:
case ItemTypeDataTypeCache:
case ItemTypeDataTypeSavedPasswords:
case ItemTypeDataTypeAutofill: {
[self updateItemAndReconfigureCellFor:item setChecked:YES];
break;
}
default:
break;
}
}
}
- (void)tableView:(UITableView*)tableView
legacyDidSelectRowAtIndexPath:(NSIndexPath*)indexPath {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath]; TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath];
DCHECK(item); DCHECK(item);
switch (item.type) { switch (item.type) {
case ItemTypeTimeRange: {
UIViewController* controller =
[[TimeRangeSelectorTableViewController alloc]
initWithPrefs:self.browserState->GetPrefs()
delegate:self.dataManager];
[self.navigationController pushViewController:controller animated:YES];
break;
}
case ItemTypeDataTypeBrowsingHistory: case ItemTypeDataTypeBrowsingHistory:
case ItemTypeDataTypeCookiesSiteData: case ItemTypeDataTypeCookiesSiteData:
case ItemTypeDataTypeCache: case ItemTypeDataTypeCache:
...@@ -262,11 +300,27 @@ const CGFloat kSeparationSpaceBetweenSections = 9; ...@@ -262,11 +300,27 @@ const CGFloat kSeparationSpaceBetweenSections = 9;
[self reconfigureCellsForItems:@[ clearBrowsingDataItem ]]; [self reconfigureCellsForItems:@[ clearBrowsingDataItem ]];
break; break;
} }
case ItemTypeClearBrowsingDataButton: default:
case ItemTypeFooterGoogleAccount: break;
case ItemTypeFooterGoogleAccountAndMyActivity: }
case ItemTypeFooterSavedSiteData: }
case ItemTypeFooterClearSyncAndSavedSiteData:
- (void)tableView:(UITableView*)tableView
didDeselectRowAtIndexPath:(NSIndexPath*)indexPath {
if (!IsNewClearBrowsingDataUIEnabled()) {
return;
}
TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath];
DCHECK(item);
switch (item.type) {
case ItemTypeDataTypeBrowsingHistory:
case ItemTypeDataTypeCookiesSiteData:
case ItemTypeDataTypeCache:
case ItemTypeDataTypeSavedPasswords:
case ItemTypeDataTypeAutofill: {
[self updateItemAndReconfigureCellFor:item setChecked:NO];
break;
}
default: default:
break; break;
} }
...@@ -296,6 +350,20 @@ const CGFloat kSeparationSpaceBetweenSections = 9; ...@@ -296,6 +350,20 @@ const CGFloat kSeparationSpaceBetweenSections = 9;
// thus the cell height needs to adapt accordingly. // thus the cell height needs to adapt accordingly.
[self reloadCellsForItems:@[ item ] [self reloadCellsForItems:@[ item ]
withRowAnimation:UITableViewRowAnimationAutomatic]; withRowAnimation:UITableViewRowAnimationAutomatic];
// Restore a cell's seleted state potentially cleared by the above reload
// method.
if (IsNewClearBrowsingDataUIEnabled() &&
[item isKindOfClass:[TableViewClearBrowsingDataItem class]]) {
TableViewClearBrowsingDataItem* dataTypeItem =
base::mac::ObjCCastStrict<TableViewClearBrowsingDataItem>(item);
if (dataTypeItem.checked) {
[self.tableView selectRowAtIndexPath:[self.tableViewModel
indexPathForItem:dataTypeItem]
animated:NO
scrollPosition:UITableViewScrollPositionNone];
}
}
} }
- (void)removeBrowsingDataForBrowserState:(ios::ChromeBrowserState*)browserState - (void)removeBrowsingDataForBrowserState:(ios::ChromeBrowserState*)browserState
...@@ -404,4 +472,21 @@ const CGFloat kSeparationSpaceBetweenSections = 9; ...@@ -404,4 +472,21 @@ const CGFloat kSeparationSpaceBetweenSections = 9;
[self.actionSheetCoordinator start]; [self.actionSheetCoordinator start];
} }
// Helper of |tableView:didSelectRowAtIndexPath:| and
// |tableView:didDeselectRowAtIndexPath:| for browsing data items.
// Sets |item|'s |checked| to |flag|, which depends on whether it's a selection
// or a deselection, then performs updates accordingly.
- (void)updateItemAndReconfigureCellFor:(TableViewItem*)item
setChecked:(BOOL)flag {
if (![item isKindOfClass:[TableViewClearBrowsingDataItem class]]) {
return;
}
TableViewClearBrowsingDataItem* clearBrowsingDataItem =
base::mac::ObjCCastStrict<TableViewClearBrowsingDataItem>(item);
clearBrowsingDataItem.checked = flag;
self.browserState->GetPrefs()->SetBoolean(clearBrowsingDataItem.prefName,
clearBrowsingDataItem.checked);
[self reconfigureCellsForItems:@[ clearBrowsingDataItem ]];
}
@end @end
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