Commit 8c13e4c6 authored by Jérôme Lebel's avatar Jérôme Lebel Committed by Commit Bot

[iOS] Adding SyncSwitchItem implementation for UITableView

SyncSwitchItem is to replace LegacySyncSwitchCell for UITableView. The
item uses SettingsSwitchCell.

Change-Id: I62933ec77c30813bda489dce3f89a1ff642b2b7c
Reviewed-on: https://chromium-review.googlesource.com/c/1384254
Commit-Queue: Jérôme Lebel <jlebel@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#618802}
parent 993479af
......@@ -40,6 +40,8 @@ source_set("cells") {
"settings_switch_item.mm",
"settings_text_item.h",
"settings_text_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",
......
// 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_SYNC_SWITCH_ITEM_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SYNC_SWITCH_ITEM_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
// SyncSwitchItem is a model class that uses SettingsSwitchCell.
@interface SyncSwitchItem : TableViewItem
// The text to display.
@property(nonatomic, copy) NSString* text;
// The detail text string.
@property(nonatomic, copy) NSString* detailText;
// The current state of the switch.
@property(nonatomic, assign, getter=isOn) BOOL on;
// Whether or not the switch is enabled. Disabled switches are automatically
// drawn as in the "off" state, with dimmed text.
@property(nonatomic, assign, getter=isEnabled) BOOL enabled;
// SyncSetupService::SyncableDatatype value for the item.
@property(nonatomic, assign) NSInteger dataType;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_CELLS_SYNC_SWITCH_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/sync_switch_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_cell.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@implementation SyncSwitchItem
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
if (self) {
self.cellClass = [SettingsSwitchCell class];
self.enabled = YES;
}
return self;
}
#pragma mark TableViewItem
- (void)configureCell:(SettingsSwitchCell*)cell
withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:cell withStyler:styler];
cell.textLabel.text = self.text;
cell.detailTextLabel.text = self.detailText;
cell.switchView.enabled = self.enabled;
cell.switchView.on = self.on;
cell.textLabel.textColor =
[SettingsSwitchCell defaultTextColorForState:cell.switchView.state];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
@end
......@@ -12,6 +12,7 @@
#import "ios/chrome/browser/ui/settings/cells/encryption_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_detail_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h"
#import "ios/chrome/browser/ui/settings/cells/sync_switch_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_detail_text_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_image_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h"
......@@ -55,6 +56,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeDetailText,
ItemTypeSettingsSwitch1,
ItemTypeSettingsSwitch2,
ItemTypeSyncSwitch,
ItemTypeAutofillEditItem,
ItemTypeAutofillData,
ItemTypeAccount,
......@@ -176,19 +178,28 @@ typedef NS_ENUM(NSInteger, ItemType) {
SettingsSwitchItem* settingsSwitchItem =
[[SettingsSwitchItem alloc] initWithType:ItemTypeSettingsSwitch1];
settingsSwitchItem.text = @"This is a switch item";
settingsSwitchItem.text = @"This is a settings switch item";
[model addItem:settingsSwitchItem
toSectionWithIdentifier:SectionIdentifierSettings];
SettingsSwitchItem* settingsSwitchItem2 =
[[SettingsSwitchItem alloc] initWithType:ItemTypeSettingsSwitch2];
settingsSwitchItem2.text = @"This is a disabled switch item";
settingsSwitchItem2.text = @"This is a disabled settings switch item";
settingsSwitchItem2.detailText = @"This is a switch item with detail text";
settingsSwitchItem2.on = YES;
settingsSwitchItem2.enabled = NO;
[model addItem:settingsSwitchItem2
toSectionWithIdentifier:SectionIdentifierSettings];
SyncSwitchItem* syncSwitchItem =
[[SyncSwitchItem alloc] initWithType:ItemTypeSyncSwitch];
syncSwitchItem.text = @"This is a sync switch item";
syncSwitchItem.detailText = @"This is a sync switch item with detail text";
syncSwitchItem.on = YES;
syncSwitchItem.enabled = NO;
[model addItem:syncSwitchItem
toSectionWithIdentifier:SectionIdentifierSettings];
EncryptionItem* encryptionChecked =
[[EncryptionItem alloc] initWithType:ItemTypeEncryption];
encryptionChecked.text =
......
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