Commit 497980ae authored by Chris Lu's avatar Chris Lu Committed by Commit Bot

[ios] Implement ClearDataOptions in ClearBrowsingDataTableViewController

Adds the clear data type cells to the table view.

Video: https://drive.google.com/open?id=11wNSwTOGKwI9r_6-ojWkLmMHYc-lqvAH

Bug: 805201

Change-Id: I6729233d8a3c4d42bc4b649d56ae0f786ec59b5b
Reviewed-on: https://chromium-review.googlesource.com/1101907
Commit-Queue: Chris Lu <thegreenfrog@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568624}
parent 35e7a8d3
......@@ -673,6 +673,10 @@ const int kRecentlyClosedTabsSectionIndex = 0;
itemTypeSelected == ItemTypeSessionTabData) {
[self loadFaviconForCell:cell indexPath:indexPath];
}
// ItemTypeOtherDevicesNoSessions should not be selectable.
if (itemTypeSelected == ItemTypeOtherDevicesNoSessions) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
return cell;
}
......
......@@ -168,6 +168,7 @@ source_set("settings") {
"//ios/chrome/browser/ui/signin_interaction",
"//ios/chrome/browser/ui/signin_interaction/public",
"//ios/chrome/browser/ui/table_view",
"//ios/chrome/browser/ui/table_view:styler",
"//ios/chrome/browser/ui/table_view/cells",
"//ios/chrome/browser/voice",
"//ios/chrome/browser/web:web",
......
......@@ -28,6 +28,8 @@ source_set("cells") {
"password_details_item.mm",
"sync_switch_item.h",
"sync_switch_item.mm",
"table_view_clear_browsing_data_item.h",
"table_view_clear_browsing_data_item.mm",
"text_and_error_item.h",
"text_and_error_item.mm",
"version_item.h",
......@@ -42,6 +44,8 @@ source_set("cells") {
"//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/collection_view/cells",
"//ios/chrome/browser/ui/colors",
"//ios/chrome/browser/ui/table_view:styler",
"//ios/chrome/browser/ui/table_view/cells",
"//ios/third_party/material_roboto_font_loader_ios",
"//ui/base",
]
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_TABLE_VIEW_CLEAR_BROWSING_DATA_ITEM_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_TABLE_VIEW_CLEAR_BROWSING_DATA_ITEM_H_
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
enum class BrowsingDataRemoveMask;
// TableViewClearBrowsingDataItem contains the model data for a
// TableViewTextCell in addition a BrowsingDataRemoveMask property.
@interface TableViewClearBrowsingDataItem : TableViewItem
// Text of the TableViewTextCell
@property(nonatomic, copy) NSString* text;
// Whether or not the cell should show a checkmark.
@property(nonatomic, assign) BOOL checked;
// Mask of the data to be cleared.
@property(nonatomic, assign) BrowsingDataRemoveMask dataTypeMask;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_TABLE_VIEW_CLEAR_BROWSING_DATA_ITEM_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/settings/cells/table_view_clear_browsing_data_item.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation TableViewClearBrowsingDataItem
@synthesize checked = _checked;
@synthesize dataTypeMask = _dataTypeMask;
@synthesize text = _text;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.cellClass = [TableViewTextCell class];
}
return self;
}
- (void)configureCell:(UITableViewCell*)tableCell
withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:tableCell withStyler:styler];
TableViewTextCell* cell =
base::mac::ObjCCastStrict<TableViewTextCell>(tableCell);
cell.textLabel.text = self.text;
cell.textLabel.textColor = [UIColor blackColor];
cell.checked = self.checked;
cell.textLabel.backgroundColor = styler.tableViewBackgroundColor;
}
@end
......@@ -15,7 +15,8 @@
- (void)start {
ClearBrowsingDataTableViewController* clearBrowsingDataTableViewController =
[[ClearBrowsingDataTableViewController alloc] init];
[[ClearBrowsingDataTableViewController alloc]
initWithBrowserState:self.browserState];
clearBrowsingDataTableViewController.extendedLayoutIncludesOpaqueBars = YES;
// We currently know for sure that baseViewController is a
// Navigation Controller.
......
......@@ -37,6 +37,8 @@
#import "ios/chrome/browser/ui/list_model/list_model.h"
#import "ios/chrome/browser/ui/settings/cells/clear_browsing_data_constants.h"
#import "ios/chrome/browser/ui/settings/cells/clear_browsing_data_item.h"
#import "ios/chrome/browser/ui/settings/cells/table_view_clear_browsing_data_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_item.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/common/channel_info.h"
#include "ios/chrome/grit/ios_chromium_strings.h"
......@@ -110,14 +112,16 @@ const int kMaxTimesHistoryNoticeShown = 1;
- (void)loadModel:(ListModel*)model {
// Time range section.
if (experimental_flags::IsNewClearBrowsingDataUIEnabled()) {
// Only implementing new UI for kListTypeCollectionView.
if (experimental_flags::IsNewClearBrowsingDataUIEnabled() &&
self.listType == ClearBrowsingDataListType::kListTypeCollectionView) {
[model addSectionWithIdentifier:SectionIdentifierTimeRange];
[model addItem:[self timeRangeItem]
toSectionWithIdentifier:SectionIdentifierTimeRange];
}
[self addClearBrowsingDataItemsToModel:model];
[self addClearDataButtonToModel:model];
[self addSyncProfileItemsToModel:model];
}
......@@ -165,12 +169,6 @@ const int kMaxTimesHistoryNoticeShown = 1;
prefName:browsing_data::prefs::kDeleteFormData];
[model addItem:autofillItem
toSectionWithIdentifier:SectionIdentifierDataTypes];
// Clear Browsing Data button.
[model addSectionWithIdentifier:SectionIdentifierClearBrowsingDataButton];
ListItem* clearButtonItem = [self clearButtonItem];
[model addItem:clearButtonItem
toSectionWithIdentifier:SectionIdentifierClearBrowsingDataButton];
}
- (NSString*)counterTextFromResult:
......@@ -243,6 +241,14 @@ const int kMaxTimesHistoryNoticeShown = 1;
return alertController;
}
- (void)addClearDataButtonToModel:(ListModel*)model {
// Clear Browsing Data button.
ListItem* clearButtonItem = [self clearButtonItem];
[model addSectionWithIdentifier:SectionIdentifierClearBrowsingDataButton];
[model addItem:clearButtonItem
toSectionWithIdentifier:SectionIdentifierClearBrowsingDataButton];
}
// Add footers about user's account data.
- (void)addSyncProfileItemsToModel:(ListModel*)model {
// Google Account footer.
......@@ -312,6 +318,11 @@ const int kMaxTimesHistoryNoticeShown = 1;
collectionClearButtonItem.accessibilityTraits |= UIAccessibilityTraitButton;
collectionClearButtonItem.textColor = [[MDCPalette cr_redPalette] tint500];
clearButtonItem = collectionClearButtonItem;
} else {
// TODO(crbug.com/853402): Implement using TableviewTextButtonItem.
TableViewTextItem* tableViewDummyItem = [[TableViewTextItem alloc]
initWithType:ItemTypeClearBrowsingDataButton];
clearButtonItem = tableViewDummyItem;
}
return clearButtonItem;
}
......@@ -336,6 +347,8 @@ const int kMaxTimesHistoryNoticeShown = 1;
}));
}
ListItem* clearDataItem;
// Create a ClearBrowsingDataItem for a CollectionView model and a
// TableViewClearBrowsingDataItem for a TableView model.
if (self.listType == ClearBrowsingDataListType::kListTypeCollectionView) {
ClearBrowsingDataItem* collectionClearDataItem =
[[ClearBrowsingDataItem alloc] initWithType:itemType
......@@ -359,6 +372,15 @@ const int kMaxTimesHistoryNoticeShown = 1;
l10n_util::GetNSString(IDS_DEL_COOKIES_COUNTER);
}
clearDataItem = collectionClearDataItem;
} else {
TableViewClearBrowsingDataItem* tableViewClearDataItem =
[[TableViewClearBrowsingDataItem alloc] initWithType:itemType];
tableViewClearDataItem.text = l10n_util::GetNSString(titleMessageID);
tableViewClearDataItem.checked = prefs->GetBoolean(prefName);
tableViewClearDataItem.accessibilityIdentifier =
[self accessibilityIdentifierFromItemType:itemType];
tableViewClearDataItem.dataTypeMask = mask;
clearDataItem = tableViewClearDataItem;
}
return clearDataItem;
}
......@@ -382,6 +404,11 @@ const int kMaxTimesHistoryNoticeShown = 1;
->GetClearBrowsingDataAccountActivityImage();
collectionFooterItem.image = image;
footerItem = collectionFooterItem;
} else {
// TODO(crbug.com/853402): Implement using TableviewLinkTextItem.
TableViewTextItem* dummyItem =
[[TableViewTextItem alloc] initWithType:ItemTypeFooterGoogleAccount];
footerItem = dummyItem;
}
return footerItem;
}
......@@ -433,6 +460,11 @@ const int kMaxTimesHistoryNoticeShown = 1;
collectionFooterItem.linkDelegate = self.linkDelegate;
collectionFooterItem.image = image;
footerItem = collectionFooterItem;
} else {
// TODO(crbug.com/853402): Implement using TableviewLinkTextItem.
TableViewTextItem* dummyItem =
[[TableViewTextItem alloc] initWithType:itemType];
footerItem = dummyItem;
}
return footerItem;
......
......@@ -7,12 +7,17 @@
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
namespace ios {
class ChromeBrowserState;
}
// TableView for clearing browsing data (including history,
// cookies, caches, passwords, and autofill).
@interface ClearBrowsingDataTableViewController : ChromeTableViewController
// Initializers.
- (instancetype)init NS_DESIGNATED_INITIALIZER;
// Initializers. |browserState| can't be nil.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
......
......@@ -4,6 +4,11 @@
#import "ios/chrome/browser/ui/settings/clear_browsing_data_table_view_controller.h"
#include "base/mac/foundation_util.h"
#import "ios/chrome/browser/ui/settings/cells/table_view_clear_browsing_data_item.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data_manager.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -11,23 +16,89 @@
#error "This file requires ARC support."
#endif
namespace ios {
class ChromeBrowserState;
}
@interface ClearBrowsingDataTableViewController ()
// TODO(crbug.com/850699): remove direct dependency and replace with
// delegate.
@property(nonatomic, readonly, strong) ClearBrowsingDataManager* dataManager;
// Browser state.
@property(nonatomic, assign) ios::ChromeBrowserState* browserState;
@end
@implementation ClearBrowsingDataTableViewController
@synthesize browserState = _browserState;
@synthesize dataManager = _dataManager;
#pragma mark - ViewController Lifecycle.
- (instancetype)init {
return [super initWithTableViewStyle:UITableViewStylePlain
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState {
self = [super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) {
_browserState = browserState;
_dataManager = [[ClearBrowsingDataManager alloc]
initWithBrowserState:browserState
listType:ClearBrowsingDataListType::kListTypeTableView];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// TableView configuration
self.tableView.estimatedRowHeight = 56;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedSectionHeaderHeight = 56;
self.tableView.estimatedSectionHeaderHeight = 0;
self.styler.tableViewBackgroundColor = [UIColor clearColor];
// Align cell separators with text label leading margin.
[self.tableView
setSeparatorInset:UIEdgeInsetsMake(0, kTableViewHorizontalSpacing, 0, 0)];
// Navigation controller configuration.
self.title = l10n_util::GetNSString(IDS_IOS_CLEAR_BROWSING_DATA_TITLE);
[self loadModel];
}
- (void)loadModel {
[super loadModel];
[self.dataManager loadModel:self.tableViewModel];
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView*)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
TableViewItem* item = [self.tableViewModel itemAtIndexPath:indexPath];
DCHECK(item);
switch (item.type) {
case ItemTypeDataTypeBrowsingHistory:
case ItemTypeDataTypeCookiesSiteData:
case ItemTypeDataTypeCache:
case ItemTypeDataTypeSavedPasswords:
case ItemTypeDataTypeAutofill: {
TableViewClearBrowsingDataItem* clearBrowsingDataItem =
base::mac::ObjCCastStrict<TableViewClearBrowsingDataItem>(item);
clearBrowsingDataItem.checked = !clearBrowsingDataItem.checked;
[self reconfigureCellsForItems:@[ clearBrowsingDataItem ]];
break;
}
case ItemTypeClearBrowsingDataButton:
case ItemTypeFooterGoogleAccount:
case ItemTypeFooterGoogleAccountAndMyActivity:
case ItemTypeFooterSavedSiteData:
case ItemTypeFooterClearSyncAndSavedSiteData:
case ItemTypeTimeRange:
default:
break;
}
}
@end
......@@ -36,6 +36,9 @@ typedef NS_ENUM(UInt32, TextItemColor) {
// The text to display.
@property(nonatomic, readonly, strong) UILabel* textLabel;
// Whether to show the checkmark accessory view.
@property(nonatomic, assign) BOOL checked;
@end
#endif // IOS_CHROME_BROWSER_UI_TABLE_VIEW_CELLS_TABLE_VIEW_TEXT_ITEM_H_
......@@ -36,15 +36,17 @@
cell.textLabel.text = self.text;
cell.textLabel.backgroundColor = styler.tableViewBackgroundColor;
// This item's text color takes precedence over the global styler.
if (self.textColor)
// TODO(crbug.com/854249): redo the logic for this convoluted if clause.
if (self.textColor == TextItemColorBlack ||
self.textColor == TextItemColorLightGrey) {
cell.textLabel.textColor = UIColorFromRGB(self.textColor);
else if (styler.cellTitleColor)
} else if (styler.cellTitleColor) {
cell.textLabel.textColor = styler.cellTitleColor;
else
} else {
cell.textLabel.textColor = UIColorFromRGB(TextItemColorLightGrey);
}
cell.textLabel.textAlignment =
self.textAlignment ? self.textAlignment : NSTextAlignmentLeft;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
@end
......@@ -53,6 +55,7 @@
@implementation TableViewTextCell
@synthesize textLabel = _textLabel;
@synthesize checked = _checked;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
......@@ -74,12 +77,11 @@
[_textLabel.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kTableViewHorizontalSpacing],
[_textLabel.topAnchor
constraintEqualToAnchor:self.contentView.topAnchor
constant:kTableViewLabelVerticalSpacing],
[_textLabel.topAnchor constraintEqualToAnchor:self.contentView.topAnchor
constant:kTableViewVerticalSpacing],
[_textLabel.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor
constant:-kTableViewLabelVerticalSpacing],
constant:-kTableViewVerticalSpacing],
[_textLabel.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kTableViewHorizontalSpacing]
......@@ -88,4 +90,19 @@
return self;
}
- (void)setChecked:(BOOL)checked {
if (checked) {
self.accessoryView = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:@"bookmark_blue_check"]];
} else {
self.accessoryView = nil;
}
_checked = checked;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.checked = NO;
}
@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