Commit fc28aba9 authored by Yi Su's avatar Yi Su Committed by Commit Bot

Migrate HandoffCollectionViewController from CollectionViewController to...

Migrate HandoffCollectionViewController from CollectionViewController to ChromeTableViewControllerStyleWithAppBar.

This CL migrates the HandoffCollectionViewController from
CollectionViewController, which is based on MDCCollectionViewController,
to ChromeTableViewController, which is based on UITableViewController.

Bug: 894791
Change-Id: I4b6e25e3729ad2150fbc49fd6c71c54229f76f31
Reviewed-on: https://chromium-review.googlesource.com/c/1340326Reviewed-by: default avataredchin <edchin@chromium.org>
Commit-Queue: Yi Su <mrsuyi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#608820}
parent caaf2032
......@@ -56,8 +56,8 @@ source_set("settings") {
"google_services_settings_view_controller.h",
"google_services_settings_view_controller.mm",
"google_services_settings_view_controller_model_delegate.h",
"handoff_collection_view_controller.h",
"handoff_collection_view_controller.mm",
"handoff_table_view_controller.h",
"handoff_table_view_controller.mm",
"import_data_collection_view_controller.h",
"import_data_collection_view_controller.mm",
"material_cell_catalog_view_controller.h",
......
......@@ -2,10 +2,10 @@
// 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_HANDOFF_COLLECTION_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_HANDOFF_COLLECTION_VIEW_CONTROLLER_H_
#ifndef IOS_CHROME_BROWSER_UI_SETTINGS_HANDOFF_TABLE_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_SETTINGS_HANDOFF_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"
namespace ios {
class ChromeBrowserState;
......@@ -13,17 +13,16 @@ class ChromeBrowserState;
// This View Controller is responsible for managing the settings related to
// Handoff.
@interface HandoffCollectionViewController
: SettingsRootCollectionViewController
@interface HandoffTableViewController : SettingsRootTableViewController
// The designated initializer. |browserState| must not be nil.
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithLayout:(UICollectionViewLayout*)layout
style:(CollectionViewControllerStyle)style
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
NS_UNAVAILABLE;
- (instancetype)init NS_UNAVAILABLE;
@end
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_HANDOFF_COLLECTION_VIEW_CONTROLLER_H_
#endif // IOS_CHROME_BROWSER_UI_SETTINGS_HANDOFF_TABLE_VIEW_CONTROLLER_H_
......@@ -2,16 +2,14 @@
// 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/handoff_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/handoff_table_view_controller.h"
#import "base/mac/foundation_util.h"
#include "components/handoff/pref_names_ios.h"
#include "components/prefs/pref_member.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrome.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item.h"
#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
#import "ios/chrome/browser/ui/settings/cells/legacy/legacy_settings_switch_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_link_header_footer_item.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
......@@ -23,7 +21,6 @@ namespace {
typedef NS_ENUM(NSInteger, SectionIdentifier) {
SectionIdentifierSwitch = kSectionIdentifierEnumZero,
SectionIdentifierFooter,
};
typedef NS_ENUM(NSInteger, ItemType) {
......@@ -33,7 +30,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
} // namespace
@interface HandoffCollectionViewController () {
@interface HandoffTableViewController () {
// Pref for whether Handoff is enabled.
BooleanPrefMember _handoffEnabled;
}
......@@ -42,65 +39,66 @@ typedef NS_ENUM(NSInteger, ItemType) {
@end
@implementation HandoffCollectionViewController
@implementation HandoffTableViewController
#pragma mark - Initialization
- (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState {
DCHECK(browserState);
UICollectionViewLayout* layout = [[MDCCollectionViewFlowLayout alloc] init];
self =
[super initWithLayout:layout style:CollectionViewControllerStyleAppBar];
[super initWithTableViewStyle:UITableViewStyleGrouped
appBarStyle:ChromeTableViewControllerStyleWithAppBar];
if (self) {
self.title = l10n_util::GetNSString(IDS_IOS_OPTIONS_CONTINUITY_LABEL);
_handoffEnabled.Init(prefs::kIosHandoffToOtherDevices,
browserState->GetPrefs());
// 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;
}
#pragma mark - CollectionViewController
#pragma mark - UIViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.estimatedSectionFooterHeight = 70;
[self loadModel];
}
#pragma mark - ChromeTableViewController
- (void)loadModel {
[super loadModel];
CollectionViewModel* model = self.collectionViewModel;
TableViewModel* model = self.tableViewModel;
[model addSectionWithIdentifier:SectionIdentifierSwitch];
LegacySettingsSwitchItem* switchItem =
[[LegacySettingsSwitchItem alloc] initWithType:ItemTypeSwitch];
SettingsSwitchItem* switchItem =
[[SettingsSwitchItem alloc] initWithType:ItemTypeSwitch];
switchItem.text =
l10n_util::GetNSString(IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES);
switchItem.on = _handoffEnabled.GetValue();
[model addItem:switchItem toSectionWithIdentifier:SectionIdentifierSwitch];
// The footer item must currently go into a separate section, to work around a
// drawing bug in MDC.
// TODO(crbug.com/650424) Use setFooter:forSectionWithIdentifier:.
[model addSectionWithIdentifier:SectionIdentifierFooter];
CollectionViewFooterItem* footer =
[[CollectionViewFooterItem alloc] initWithType:ItemTypeFooter];
footer.cellStyle = CollectionViewCellStyle::kUIKit;
TableViewLinkHeaderFooterItem* footer =
[[TableViewLinkHeaderFooterItem alloc] initWithType:ItemTypeFooter];
footer.text = l10n_util::GetNSString(
IDS_IOS_OPTIONS_ENABLE_HANDOFF_TO_OTHER_DEVICES_DETAILS);
[model addItem:footer toSectionWithIdentifier:SectionIdentifierFooter];
[model setFooter:footer forSectionWithIdentifier:SectionIdentifierSwitch];
}
#pragma mark - UICollectionViewDataSource
#pragma mark - UITableViewDataSource
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
cellForItemAtIndexPath:(NSIndexPath*)indexPath {
UICollectionViewCell* cell =
[super collectionView:collectionView cellForItemAtIndexPath:indexPath];
- (UITableViewCell*)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UITableViewCell* cell =
[super tableView:tableView cellForRowAtIndexPath:indexPath];
ItemType itemType = static_cast<ItemType>(
[self.collectionViewModel itemTypeForIndexPath:indexPath]);
[self.tableViewModel itemTypeForIndexPath:indexPath]);
if (itemType == ItemTypeSwitch) {
LegacySettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<LegacySettingsSwitchCell>(cell);
SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
[switchCell.switchView addTarget:self
action:@selector(switchChanged:)
forControlEvents:UIControlEventValueChanged];
......@@ -108,58 +106,6 @@ typedef NS_ENUM(NSInteger, ItemType) {
return cell;
}
#pragma mark - MDCCollectionViewStylingDelegate
- (CGFloat)collectionView:(UICollectionView*)collectionView
cellHeightAtIndexPath:(NSIndexPath*)indexPath {
CollectionViewItem* item =
[self.collectionViewModel itemAtIndexPath:indexPath];
if (item.type == ItemTypeFooter)
return [MDCCollectionViewCell
cr_preferredHeightForWidth:CGRectGetWidth(collectionView.bounds)
forItem:item];
return MDCCellDefaultOneLineHeight;
}
- (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView
cellStyleForSection:(NSInteger)section {
NSInteger sectionIdentifier =
[self.collectionViewModel sectionIdentifierForSection:section];
switch (sectionIdentifier) {
case SectionIdentifierFooter:
// Display the Learn More footer in the default style with no "card" UI
// and no section padding.
return MDCCollectionViewCellStyleDefault;
default:
return self.styler.cellStyle;
}
}
- (BOOL)collectionView:(UICollectionView*)collectionView
shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath {
NSInteger sectionIdentifier =
[self.collectionViewModel sectionIdentifierForSection:indexPath.section];
switch (sectionIdentifier) {
case SectionIdentifierFooter:
// Display the Learn More footer without any background image or
// shadowing.
return YES;
default:
return NO;
}
}
- (BOOL)collectionView:(UICollectionView*)collectionView
hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
switch (type) {
case ItemTypeSwitch:
return YES;
default:
return NO;
}
}
#pragma mark - Private
- (void)switchChanged:(UISwitch*)switchView {
......
......@@ -32,7 +32,7 @@
#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/dataplan_usage_table_view_controller.h"
#import "ios/chrome/browser/ui/settings/handoff_collection_view_controller.h"
#import "ios/chrome/browser/ui/settings/handoff_table_view_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/utils/pref_backed_boolean.h"
......@@ -335,7 +335,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
switch (itemType) {
case ItemTypeOtherDevicesHandoff:
controller = [[HandoffCollectionViewController alloc]
controller = [[HandoffTableViewController alloc]
initWithBrowserState:_browserState];
break;
case ItemTypeWebServicesSendUsageData:
......
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