Commit f0db4720 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Convert DataplanVC to TableView

This CL converts the DataplanUsageCollectionViewController to
UITableViewController.
It also adds the cellBackgroundColor property to the styler so the cells
can have a background color different from the table view's background.
It also adds an accessoryType for the DetailTextItem.

Bug: 894791
Cq-Include-Trybots: luci.chromium.try:ios-simulator-cronet;luci.chromium.try:ios-simulator-full-configs
Change-Id: Ie1332811d3df6d8ef7650fb34fa3a17a515da3d9
Reviewed-on: https://chromium-review.googlesource.com/c/1286142
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601109}
parent 12076064
...@@ -42,8 +42,8 @@ source_set("settings") { ...@@ -42,8 +42,8 @@ source_set("settings") {
"compose_email_handler_collection_view_controller.mm", "compose_email_handler_collection_view_controller.mm",
"content_settings_collection_view_controller.h", "content_settings_collection_view_controller.h",
"content_settings_collection_view_controller.mm", "content_settings_collection_view_controller.mm",
"dataplan_usage_collection_view_controller.h", "dataplan_usage_table_view_controller.h",
"dataplan_usage_collection_view_controller.mm", "dataplan_usage_table_view_controller.mm",
"google_services_navigation_coordinator.h", "google_services_navigation_coordinator.h",
"google_services_navigation_coordinator.mm", "google_services_navigation_coordinator.mm",
"google_services_settings_consumer.h", "google_services_settings_consumer.h",
...@@ -278,7 +278,7 @@ source_set("unit_tests") { ...@@ -278,7 +278,7 @@ source_set("unit_tests") {
"clear_browsing_data_manager_unittest.mm", "clear_browsing_data_manager_unittest.mm",
"compose_email_handler_collection_view_controller_unittest.mm", "compose_email_handler_collection_view_controller_unittest.mm",
"content_settings_collection_view_controller_unittest.mm", "content_settings_collection_view_controller_unittest.mm",
"dataplan_usage_collection_view_controller_unittest.mm", "dataplan_usage_table_view_controller_unittest.mm",
"import_data_collection_view_controller_unittest.mm", "import_data_collection_view_controller_unittest.mm",
"password_details_collection_view_controller_unittest.mm", "password_details_collection_view_controller_unittest.mm",
"password_exporter_unittest.mm", "password_exporter_unittest.mm",
......
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#import "ios/chrome/browser/ui/settings/cells/settings_detail_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_detail_item.h"
#import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/dataplan_usage_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_utils.h" #import "ios/chrome/browser/ui/settings/settings_utils.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_item.h"
...@@ -126,12 +126,11 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -126,12 +126,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
if (type == ItemTypePreload) { if (type == ItemTypePreload) {
NSString* preloadTitle = NSString* preloadTitle =
l10n_util::GetNSString(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES); l10n_util::GetNSString(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES);
UIViewController* controller = UIViewController* controller = [[DataplanUsageTableViewController alloc]
[[DataplanUsageCollectionViewController alloc] initWithPrefs:_browserState->GetPrefs()
initWithPrefs:_browserState->GetPrefs() basePref:prefs::kNetworkPredictionEnabled
basePref:prefs::kNetworkPredictionEnabled wifiPref:prefs::kNetworkPredictionWifiOnly
wifiPref:prefs::kNetworkPredictionWifiOnly title:preloadTitle];
title:preloadTitle];
[self.navigationController pushViewController:controller animated:YES]; [self.navigationController pushViewController:controller animated:YES];
} }
} }
...@@ -141,7 +140,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -141,7 +140,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)onPreferenceChanged:(const std::string&)preferenceName { - (void)onPreferenceChanged:(const std::string&)preferenceName {
if (preferenceName == prefs::kNetworkPredictionEnabled || if (preferenceName == prefs::kNetworkPredictionEnabled ||
preferenceName == prefs::kNetworkPredictionWifiOnly) { preferenceName == prefs::kNetworkPredictionWifiOnly) {
NSString* detailText = [DataplanUsageCollectionViewController NSString* detailText = [DataplanUsageTableViewController
currentLabelForPreference:_browserState->GetPrefs() currentLabelForPreference:_browserState->GetPrefs()
basePref:prefs::kNetworkPredictionEnabled basePref:prefs::kNetworkPredictionEnabled
wifiPref:prefs::kNetworkPredictionWifiOnly]; wifiPref:prefs::kNetworkPredictionWifiOnly];
...@@ -156,7 +155,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -156,7 +155,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
// Returns a newly created SettingsDetailItem for the preload webpages menu. // Returns a newly created SettingsDetailItem for the preload webpages menu.
- (SettingsDetailItem*)preloadWebpagesItem { - (SettingsDetailItem*)preloadWebpagesItem {
NSString* detailText = [DataplanUsageCollectionViewController NSString* detailText = [DataplanUsageTableViewController
currentLabelForPreference:_browserState->GetPrefs() currentLabelForPreference:_browserState->GetPrefs()
basePref:prefs::kNetworkPredictionEnabled basePref:prefs::kNetworkPredictionEnabled
wifiPref:prefs::kNetworkPredictionWifiOnly]; wifiPref:prefs::kNetworkPredictionWifiOnly];
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "ios/chrome/browser/browser_state/test_chrome_browser_state.h" #include "ios/chrome/browser/browser_state/test_chrome_browser_state.h"
#include "ios/chrome/browser/pref_names.h" #include "ios/chrome/browser/pref_names.h"
#include "ios/chrome/browser/prefs/browser_prefs.h" #include "ios/chrome/browser/prefs/browser_prefs.h"
#import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/dataplan_usage_table_view_controller.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller_test.h" #import "ios/chrome/browser/ui/table_view/chrome_table_view_controller_test.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h" #import "ios/chrome/browser/ui/table_view/table_view_model.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
...@@ -80,7 +80,7 @@ TEST_F(BandwidthManagementTableViewControllerTest, TestModel) { ...@@ -80,7 +80,7 @@ TEST_F(BandwidthManagementTableViewControllerTest, TestModel) {
// Preload webpages item. // Preload webpages item.
NSString* expected_title = NSString* expected_title =
l10n_util::GetNSString(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES); l10n_util::GetNSString(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES);
NSString* expected_subtitle = [DataplanUsageCollectionViewController NSString* expected_subtitle = [DataplanUsageTableViewController
currentLabelForPreference:chrome_browser_state_->GetPrefs() currentLabelForPreference:chrome_browser_state_->GetPrefs()
basePref:prefs::kNetworkPredictionEnabled basePref:prefs::kNetworkPredictionEnabled
wifiPref:prefs::kNetworkPredictionWifiOnly]; wifiPref:prefs::kNetworkPredictionWifiOnly];
......
...@@ -2,25 +2,25 @@ ...@@ -2,25 +2,25 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_DATAPLAN_USAGE_COLLECTION_VIEW_CONTROLLER_H_ #ifndef IOS_CHROME_BROWSER_UI_SETTINGS_DATAPLAN_USAGE_TABLE_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_DATAPLAN_USAGE_COLLECTION_VIEW_CONTROLLER_H_ #define IOS_CHROME_BROWSER_UI_SETTINGS_DATAPLAN_USAGE_TABLE_VIEW_CONTROLLER_H_
#import "ios/chrome/browser/ui/settings/settings_root_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/settings_root_table_view_controller.h"
class PrefService; class PrefService;
// Class that handles the UI and preference setting for options that require // Class that handles the UI and preference setting for options that require
// three states: 'Always', 'Only on WiFi', and 'Never'. // three states: 'Always', 'Only on WiFi', and 'Never'.
@interface DataplanUsageCollectionViewController @interface DataplanUsageTableViewController : SettingsRootTableViewController
: SettingsRootCollectionViewController
- (instancetype)initWithPrefs:(PrefService*)prefs - (instancetype)initWithPrefs:(PrefService*)prefs
basePref:(const char*)basePreference basePref:(const char*)basePreference
wifiPref:(const char*)wifiPreference wifiPref:(const char*)wifiPreference
title:(NSString*)title NS_DESIGNATED_INITIALIZER; title:(NSString*)title NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithLayout:(UICollectionViewLayout*)layout - (instancetype)initWithTableViewStyle:(UITableViewStyle)style
style:(CollectionViewControllerStyle)style appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
NS_UNAVAILABLE; NS_UNAVAILABLE;
// Returns the text for the current setting, based on the values of the // Returns the text for the current setting, based on the values of the
...@@ -31,4 +31,4 @@ class PrefService; ...@@ -31,4 +31,4 @@ class PrefService;
wifiPref:(const char*)wifiPreference; wifiPref:(const char*)wifiPreference;
@end @end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_DATAPLAN_USAGE_COLLECTION_VIEW_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_SETTINGS_DATAPLAN_USAGE_TABLE_VIEW_CONTROLLER_H_
...@@ -2,16 +2,16 @@ ...@@ -2,16 +2,16 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/dataplan_usage_table_view_controller.h"
#include "base/logging.h" #include "base/logging.h"
#import "base/mac/foundation_util.h" #import "base/mac/foundation_util.h"
#include "components/prefs/pref_member.h" #include "components/prefs/pref_member.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_detail_text_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_text_item.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"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
...@@ -33,7 +33,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -33,7 +33,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
} // namespace. } // namespace.
@interface DataplanUsageCollectionViewController () { @interface DataplanUsageTableViewController () {
BooleanPrefMember basePreference_; BooleanPrefMember basePreference_;
BooleanPrefMember wifiPreference_; BooleanPrefMember wifiPreference_;
} }
...@@ -45,7 +45,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -45,7 +45,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)updateBasePref:(BOOL)basePref wifiPref:(BOOL)wifiPref; - (void)updateBasePref:(BOOL)basePref wifiPref:(BOOL)wifiPref;
@end @end
@implementation DataplanUsageCollectionViewController @implementation DataplanUsageTableViewController
#pragma mark - Initialization #pragma mark - Initialization
...@@ -53,40 +53,45 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -53,40 +53,45 @@ typedef NS_ENUM(NSInteger, ItemType) {
basePref:(const char*)basePreference basePref:(const char*)basePreference
wifiPref:(const char*)wifiPreference wifiPref:(const char*)wifiPreference
title:(NSString*)title { title:(NSString*)title {
UICollectionViewLayout* layout = [[MDCCollectionViewFlowLayout alloc] init];
self = self =
[super initWithLayout:layout style:CollectionViewControllerStyleAppBar]; [super initWithTableViewStyle:UITableViewStyleGrouped
appBarStyle:ChromeTableViewControllerStyleWithAppBar];
if (self) { if (self) {
self.title = title; self.title = title;
basePreference_.Init(basePreference, prefs); basePreference_.Init(basePreference, prefs);
wifiPreference_.Init(wifiPreference, prefs); wifiPreference_.Init(wifiPreference, prefs);
// TODO(crbug.com/764578): -loadModel should not be called from
// initializer. A possible fix is to move this call to -viewDidLoad.
[self loadModel];
} }
return self; return self;
} }
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.estimatedRowHeight = 70;
self.tableView.rowHeight = UITableViewAutomaticDimension;
[self loadModel];
}
- (void)loadModel { - (void)loadModel {
[super loadModel]; [super loadModel];
CollectionViewModel* model = self.collectionViewModel; self.styler.cellTitleColor = [UIColor blackColor];
TableViewModel<TableViewItem*>* model = self.tableViewModel;
[model addSectionWithIdentifier:SectionIdentifierOptions]; [model addSectionWithIdentifier:SectionIdentifierOptions];
SettingsTextItem* always = TableViewDetailTextItem* always =
[[SettingsTextItem alloc] initWithType:ItemTypeOptionsAlways]; [[TableViewDetailTextItem alloc] initWithType:ItemTypeOptionsAlways];
[always setText:l10n_util::GetNSString(IDS_IOS_OPTIONS_DATA_USAGE_ALWAYS)]; [always setText:l10n_util::GetNSString(IDS_IOS_OPTIONS_DATA_USAGE_ALWAYS)];
[always setAccessibilityTraits:UIAccessibilityTraitButton]; [always setAccessibilityTraits:UIAccessibilityTraitButton];
[model addItem:always toSectionWithIdentifier:SectionIdentifierOptions]; [model addItem:always toSectionWithIdentifier:SectionIdentifierOptions];
SettingsTextItem* wifi = TableViewDetailTextItem* wifi =
[[SettingsTextItem alloc] initWithType:ItemTypeOptionsOnlyOnWiFi]; [[TableViewDetailTextItem alloc] initWithType:ItemTypeOptionsOnlyOnWiFi];
[wifi setText:l10n_util::GetNSString(IDS_IOS_OPTIONS_DATA_USAGE_ONLY_WIFI)]; [wifi setText:l10n_util::GetNSString(IDS_IOS_OPTIONS_DATA_USAGE_ONLY_WIFI)];
[wifi setAccessibilityTraits:UIAccessibilityTraitButton]; [wifi setAccessibilityTraits:UIAccessibilityTraitButton];
[model addItem:wifi toSectionWithIdentifier:SectionIdentifierOptions]; [model addItem:wifi toSectionWithIdentifier:SectionIdentifierOptions];
SettingsTextItem* never = TableViewDetailTextItem* never =
[[SettingsTextItem alloc] initWithType:ItemTypeOptionsNever]; [[TableViewDetailTextItem alloc] initWithType:ItemTypeOptionsNever];
[never setText:l10n_util::GetNSString(IDS_IOS_OPTIONS_DATA_USAGE_NEVER)]; [never setText:l10n_util::GetNSString(IDS_IOS_OPTIONS_DATA_USAGE_NEVER)];
[never setAccessibilityTraits:UIAccessibilityTraitButton]; [never setAccessibilityTraits:UIAccessibilityTraitButton];
[model addItem:never toSectionWithIdentifier:SectionIdentifierOptions]; [model addItem:never toSectionWithIdentifier:SectionIdentifierOptions];
...@@ -97,7 +102,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -97,7 +102,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)updateCheckedState { - (void)updateCheckedState {
BOOL basePrefOn = basePreference_.GetValue(); BOOL basePrefOn = basePreference_.GetValue();
BOOL wifiPrefOn = wifiPreference_.GetValue(); BOOL wifiPrefOn = wifiPreference_.GetValue();
CollectionViewModel* model = self.collectionViewModel; TableViewModel<TableViewItem*>* model = self.tableViewModel;
std::unordered_map<NSInteger, bool> optionsMap = { std::unordered_map<NSInteger, bool> optionsMap = {
{ItemTypeOptionsAlways, basePrefOn && !wifiPrefOn}, {ItemTypeOptionsAlways, basePrefOn && !wifiPrefOn},
...@@ -106,14 +111,14 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -106,14 +111,14 @@ typedef NS_ENUM(NSInteger, ItemType) {
}; };
NSMutableArray* modifiedItems = [NSMutableArray array]; NSMutableArray* modifiedItems = [NSMutableArray array];
for (SettingsTextItem* item in for (TableViewDetailTextItem* item in
[model itemsInSectionWithIdentifier:SectionIdentifierOptions]) { [model itemsInSectionWithIdentifier:SectionIdentifierOptions]) {
auto value = optionsMap.find(item.type); auto value = optionsMap.find(item.type);
DCHECK(value != optionsMap.end()); DCHECK(value != optionsMap.end());
MDCCollectionViewCellAccessoryType desiredType = UITableViewCellAccessoryType desiredType =
value->second ? MDCCollectionViewCellAccessoryCheckmark value->second ? UITableViewCellAccessoryCheckmark
: MDCCollectionViewCellAccessoryNone; : UITableViewCellAccessoryNone;
if (item.accessoryType != desiredType) { if (item.accessoryType != desiredType) {
item.accessoryType = desiredType; item.accessoryType = desiredType;
[modifiedItems addObject:item]; [modifiedItems addObject:item];
...@@ -145,13 +150,11 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -145,13 +150,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
return l10n_util::GetNSString(IDS_IOS_OPTIONS_DATA_USAGE_NEVER); return l10n_util::GetNSString(IDS_IOS_OPTIONS_DATA_USAGE_NEVER);
} }
#pragma mark - UICollectionViewDelegate #pragma mark - UITableViewDelegate
- (void)collectionView:(UICollectionView*)collectionView - (void)tableView:(UITableView*)tableView
didSelectItemAtIndexPath:(NSIndexPath*)indexPath { didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
[super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; NSInteger type = [self.tableViewModel itemTypeForIndexPath:indexPath];
NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
switch (type) { switch (type) {
case ItemTypeOptionsAlways: case ItemTypeOptionsAlways:
[self updateBasePref:YES wifiPref:NO]; [self updateBasePref:YES wifiPref:NO];
...@@ -163,6 +166,8 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -163,6 +166,8 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self updateBasePref:NO wifiPref:NO]; [self updateBasePref:NO wifiPref:NO];
break; break;
} }
[tableView deselectRowAtIndexPath:indexPath animated:YES];
} }
@end @end
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/dataplan_usage_table_view_controller.h"
#include <memory> #include <memory>
...@@ -13,8 +13,8 @@ ...@@ -13,8 +13,8 @@
#include "components/prefs/pref_registry_simple.h" #include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h" #include "components/prefs/pref_service.h"
#include "components/sync_preferences/pref_service_mock_factory.h" #include "components/sync_preferences/pref_service_mock_factory.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_controller_test.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_detail_text_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_text_item.h" #import "ios/chrome/browser/ui/table_view/chrome_table_view_controller_test.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface DataplanUsageCollectionViewController (ExposedForTesting) @interface DataplanUsageTableViewController (ExposedForTesting)
- (void)updateBasePref:(BOOL)basePref wifiPref:(BOOL)wifiPref; - (void)updateBasePref:(BOOL)basePref wifiPref:(BOOL)wifiPref;
@end @end
...@@ -32,17 +32,17 @@ namespace { ...@@ -32,17 +32,17 @@ namespace {
const char* kBasePref = "BasePref"; const char* kBasePref = "BasePref";
const char* kWifiPref = "WifiPref"; const char* kWifiPref = "WifiPref";
class DataplanUsageCollectionViewControllerTest class DataplanUsageTableViewControllerTest
: public CollectionViewControllerTest { : public ChromeTableViewControllerTest {
protected: protected:
void SetUp() override { void SetUp() override {
CollectionViewControllerTest::SetUp(); ChromeTableViewControllerTest::SetUp();
pref_service_ = CreateLocalState(); pref_service_ = CreateLocalState();
CreateController(); CreateController();
} }
CollectionViewController* InstantiateController() override { ChromeTableViewController* InstantiateController() override {
dataplanController_ = [[DataplanUsageCollectionViewController alloc] dataplanController_ = [[DataplanUsageTableViewController alloc]
initWithPrefs:pref_service_.get() initWithPrefs:pref_service_.get()
basePref:kBasePref basePref:kBasePref
wifiPref:kWifiPref wifiPref:kWifiPref
...@@ -56,65 +56,64 @@ class DataplanUsageCollectionViewControllerTest ...@@ -56,65 +56,64 @@ class DataplanUsageCollectionViewControllerTest
registry->RegisterBooleanPref(kWifiPref, false); registry->RegisterBooleanPref(kWifiPref, false);
sync_preferences::PrefServiceMockFactory factory; sync_preferences::PrefServiceMockFactory factory;
base::FilePath path("DataplanUsageCollectionViewControllerTest.pref"); base::FilePath path("DataplanUsageTableViewControllerTest.pref");
factory.SetUserPrefsFile(path, message_loop_.task_runner().get()); factory.SetUserPrefsFile(path, message_loop_.task_runner().get());
return factory.Create(registry.get()); return factory.Create(registry.get());
} }
// Verifies that the cell at |item| in |section| has the given |accessory| // Verifies that the cell at |item| in |section| has the given |accessory|
// type. // type.
void CheckTextItemAccessoryType( void CheckTextItemAccessoryType(UITableViewCellAccessoryType accessory_type,
MDCCollectionViewCellAccessoryType accessory_type, int section,
int section, int item) {
int item) { TableViewDetailTextItem* cell = GetTableViewItem(section, item);
SettingsTextItem* cell = GetCollectionViewItem(section, item);
EXPECT_EQ(accessory_type, cell.accessoryType); EXPECT_EQ(accessory_type, cell.accessoryType);
} }
base::MessageLoopForUI message_loop_; base::MessageLoopForUI message_loop_;
std::unique_ptr<PrefService> pref_service_; std::unique_ptr<PrefService> pref_service_;
DataplanUsageCollectionViewController* dataplanController_; DataplanUsageTableViewController* dataplanController_;
}; };
TEST_F(DataplanUsageCollectionViewControllerTest, TestModel) { TEST_F(DataplanUsageTableViewControllerTest, TestModel) {
CheckController(); CheckController();
EXPECT_EQ(1, NumberOfSections()); EXPECT_EQ(1, NumberOfSections());
// No section header + 3 rows // No section header + 3 rows
EXPECT_EQ(3, NumberOfItemsInSection(0)); EXPECT_EQ(3, NumberOfItemsInSection(0));
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 0); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 0);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 1);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 0, 2); CheckTextItemAccessoryType(UITableViewCellAccessoryCheckmark, 0, 2);
CheckTextCellTitleWithId(IDS_IOS_OPTIONS_DATA_USAGE_ALWAYS, 0, 0); CheckTextCellTextWithId(IDS_IOS_OPTIONS_DATA_USAGE_ALWAYS, 0, 0);
CheckTextCellTitleWithId(IDS_IOS_OPTIONS_DATA_USAGE_ONLY_WIFI, 0, 1); CheckTextCellTextWithId(IDS_IOS_OPTIONS_DATA_USAGE_ONLY_WIFI, 0, 1);
CheckTextCellTitleWithId(IDS_IOS_OPTIONS_DATA_USAGE_NEVER, 0, 2); CheckTextCellTextWithId(IDS_IOS_OPTIONS_DATA_USAGE_NEVER, 0, 2);
} }
TEST_F(DataplanUsageCollectionViewControllerTest, TestUpdateCheckedState) { TEST_F(DataplanUsageTableViewControllerTest, TestUpdateCheckedState) {
CheckController(); CheckController();
ASSERT_EQ(1, NumberOfSections()); ASSERT_EQ(1, NumberOfSections());
ASSERT_EQ(3, NumberOfItemsInSection(0)); ASSERT_EQ(3, NumberOfItemsInSection(0));
[dataplanController_ updateBasePref:YES wifiPref:YES]; [dataplanController_ updateBasePref:YES wifiPref:YES];
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 0); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 0);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 0, 1); CheckTextItemAccessoryType(UITableViewCellAccessoryCheckmark, 0, 1);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 2); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 2);
[dataplanController_ updateBasePref:YES wifiPref:NO]; [dataplanController_ updateBasePref:YES wifiPref:NO];
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 0, 0); CheckTextItemAccessoryType(UITableViewCellAccessoryCheckmark, 0, 0);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 1);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 2); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 2);
[dataplanController_ updateBasePref:NO wifiPref:YES]; [dataplanController_ updateBasePref:NO wifiPref:YES];
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 0); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 0);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 1);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 0, 2); CheckTextItemAccessoryType(UITableViewCellAccessoryCheckmark, 0, 2);
[dataplanController_ updateBasePref:NO wifiPref:NO]; [dataplanController_ updateBasePref:NO wifiPref:NO];
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 0); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 0);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryNone, 0, 1); CheckTextItemAccessoryType(UITableViewCellAccessoryNone, 0, 1);
CheckTextItemAccessoryType(MDCCollectionViewCellAccessoryCheckmark, 0, 2); CheckTextItemAccessoryType(UITableViewCellAccessoryCheckmark, 0, 2);
} }
} // namespace } // namespace
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_text_item.h" #import "ios/chrome/browser/ui/settings/cells/settings_text_item.h"
#import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/clear_browsing_data_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/dataplan_usage_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/handoff_collection_view_controller.h" #import "ios/chrome/browser/ui/settings/handoff_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/settings_navigation_controller.h" #import "ios/chrome/browser/ui/settings/settings_navigation_controller.h"
#import "ios/chrome/browser/ui/settings/settings_utils.h" #import "ios/chrome/browser/ui/settings/settings_utils.h"
...@@ -269,7 +269,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -269,7 +269,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
} }
- (CollectionViewItem*)sendUsageDetailItem { - (CollectionViewItem*)sendUsageDetailItem {
NSString* detailText = [DataplanUsageCollectionViewController NSString* detailText = [DataplanUsageTableViewController
currentLabelForPreference:GetApplicationContext()->GetLocalState() currentLabelForPreference:GetApplicationContext()->GetLocalState()
basePref:metrics::prefs::kMetricsReportingEnabled basePref:metrics::prefs::kMetricsReportingEnabled
wifiPref:prefs::kMetricsReportingWifiOnly]; wifiPref:prefs::kMetricsReportingWifiOnly];
...@@ -329,7 +329,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -329,7 +329,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self.collectionViewModel itemTypeForIndexPath:indexPath]; [self.collectionViewModel itemTypeForIndexPath:indexPath];
// Items that push a new view controller. // Items that push a new view controller.
SettingsRootCollectionViewController* controller; UIViewController<SettingsRootViewControlling>* controller;
switch (itemType) { switch (itemType) {
case ItemTypeOtherDevicesHandoff: case ItemTypeOtherDevicesHandoff:
...@@ -337,7 +337,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -337,7 +337,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
initWithBrowserState:_browserState]; initWithBrowserState:_browserState];
break; break;
case ItemTypeWebServicesSendUsageData: case ItemTypeWebServicesSendUsageData:
controller = [[DataplanUsageCollectionViewController alloc] controller = [[DataplanUsageTableViewController alloc]
initWithPrefs:GetApplicationContext()->GetLocalState() initWithPrefs:GetApplicationContext()->GetLocalState()
basePref:metrics::prefs::kMetricsReportingEnabled basePref:metrics::prefs::kMetricsReportingEnabled
wifiPref:prefs::kMetricsReportingWifiOnly wifiPref:prefs::kMetricsReportingWifiOnly
...@@ -485,7 +485,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -485,7 +485,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
if (preferenceName == metrics::prefs::kMetricsReportingEnabled || if (preferenceName == metrics::prefs::kMetricsReportingEnabled ||
preferenceName == prefs::kMetricsReportingWifiOnly) { preferenceName == prefs::kMetricsReportingWifiOnly) {
NSString* detailText = [DataplanUsageCollectionViewController NSString* detailText = [DataplanUsageTableViewController
currentLabelForPreference:GetApplicationContext()->GetLocalState() currentLabelForPreference:GetApplicationContext()->GetLocalState()
basePref:metrics::prefs::kMetricsReportingEnabled basePref:metrics::prefs::kMetricsReportingEnabled
wifiPref:prefs::kMetricsReportingWifiOnly]; wifiPref:prefs::kMetricsReportingWifiOnly];
......
...@@ -25,6 +25,7 @@ ...@@ -25,6 +25,7 @@
[UIColor groupTableViewBackgroundColor]; [UIColor groupTableViewBackgroundColor];
self.styler.tableViewSectionHeaderBlurEffect = nil; self.styler.tableViewSectionHeaderBlurEffect = nil;
[super viewDidLoad]; [super viewDidLoad];
self.styler.cellBackgroundColor = [UIColor whiteColor];
} }
- (void)viewWillAppear:(BOOL)animated { - (void)viewWillAppear:(BOOL)animated {
......
...@@ -16,6 +16,9 @@ ...@@ -16,6 +16,9 @@
// Text Alignment for the cell's textLabel. Default is NSTextAlignmentNatural. // Text Alignment for the cell's textLabel. Default is NSTextAlignmentNatural.
@property(nonatomic, assign) NSTextAlignment textAlignment; @property(nonatomic, assign) NSTextAlignment textAlignment;
// The accessory type to display on the trailing edge of the cell.
@property(nonatomic) UITableViewCellAccessoryType accessoryType;
// UIColor for the cell's textLabel. Default is // UIColor for the cell's textLabel. Default is
// kTableViewTextLabelColorLightGrey. ChromeTableViewStyler's |cellTitleColor| // kTableViewTextLabelColorLightGrey. ChromeTableViewStyler's |cellTitleColor|
// takes precedence over the default color, but not over |textColor|. // takes precedence over the default color, but not over |textColor|.
......
...@@ -34,6 +34,7 @@ const CGFloat kMinimalHeight = 48; ...@@ -34,6 +34,7 @@ const CGFloat kMinimalHeight = 48;
- (void)configureCell:(TableViewDetailTextCell*)cell - (void)configureCell:(TableViewDetailTextCell*)cell
withStyler:(ChromeTableViewStyler*)styler { withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:cell withStyler:styler]; [super configureCell:cell withStyler:styler];
cell.accessoryType = self.accessoryType;
cell.textLabel.text = self.text; cell.textLabel.text = self.text;
cell.detailTextLabel.text = self.detailText; cell.detailTextLabel.text = self.detailText;
cell.isAccessibilityElement = YES; cell.isAccessibilityElement = YES;
......
...@@ -27,7 +27,11 @@ ...@@ -27,7 +27,11 @@
cell.accessibilityTraits = self.accessibilityTraits; cell.accessibilityTraits = self.accessibilityTraits;
cell.accessibilityIdentifier = self.accessibilityIdentifier; cell.accessibilityIdentifier = self.accessibilityIdentifier;
if (!cell.backgroundView) { if (!cell.backgroundView) {
cell.backgroundColor = styler.tableViewBackgroundColor; if (styler.cellBackgroundColor) {
cell.backgroundColor = styler.cellBackgroundColor;
} else {
cell.backgroundColor = styler.tableViewBackgroundColor;
}
} }
// Since this Cell might get reconfigured while it's being highlighted, // Since this Cell might get reconfigured while it's being highlighted,
// re-setting the selectedBackgroundView will interrupt the higlight // re-setting the selectedBackgroundView will interrupt the higlight
......
...@@ -17,6 +17,9 @@ ...@@ -17,6 +17,9 @@
// opaque color, cells can choose to make themselves opaque and draw their own // opaque color, cells can choose to make themselves opaque and draw their own
// background as a performance optimization. // background as a performance optimization.
@property(nonatomic, readwrite, strong) UIColor* tableViewBackgroundColor; @property(nonatomic, readwrite, strong) UIColor* tableViewBackgroundColor;
// The background color for the cell. It overrides |tableViewBackgroundColor|
// for the cell background if it is not nil.
@property(nonatomic, readwrite, strong) UIColor* cellBackgroundColor;
// Text colors. // Text colors.
@property(nonatomic, readwrite, strong) UIColor* cellTitleColor; @property(nonatomic, readwrite, strong) UIColor* cellTitleColor;
@property(nonatomic, readwrite, strong) UIColor* headerFooterTitleColor; @property(nonatomic, readwrite, strong) UIColor* headerFooterTitleColor;
......
...@@ -24,6 +24,7 @@ const CGFloat kDefaultTableViewSeparatorColor = 0xC8C7CC; ...@@ -24,6 +24,7 @@ const CGFloat kDefaultTableViewSeparatorColor = 0xC8C7CC;
@synthesize tableViewSectionHeaderBlurEffect = @synthesize tableViewSectionHeaderBlurEffect =
_tableViewSectionHeaderBlurEffect; _tableViewSectionHeaderBlurEffect;
@synthesize tableViewBackgroundColor = _tableViewBackgroundColor; @synthesize tableViewBackgroundColor = _tableViewBackgroundColor;
@synthesize cellBackgroundColor = _cellBackgroundColor;
@synthesize cellTitleColor = _cellTitleColor; @synthesize cellTitleColor = _cellTitleColor;
@synthesize headerFooterTitleColor = _headerFooterTitleColor; @synthesize headerFooterTitleColor = _headerFooterTitleColor;
@synthesize cellHighlightColor = _cellHighlightColor; @synthesize cellHighlightColor = _cellHighlightColor;
......
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