Commit e54ac8c0 authored by Tina Wang's avatar Tina Wang Committed by Commit Bot

[SettingsUI] Modify managed UI for autofill address setting

Change the UI to managed when the pref is managed by policy.

Screenshots:
https://screenshot.googleplex.com/5YeV4SPvq1i
https://screenshot.googleplex.com/BJwV90Tv3uB

Bug: 1093167
Change-Id: I10bd1ddead11e129ad9762a5d75e7cb0ab4e3012
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2239526
Commit-Queue: Tina Wang <tinazwang@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#778004}
parent 3b2ca6fe
...@@ -20,8 +20,11 @@ ...@@ -20,8 +20,11 @@
#import "ios/chrome/browser/ui/settings/autofill/cells/autofill_data_item.h" #import "ios/chrome/browser/ui/settings/autofill/cells/autofill_data_item.h"
#import "ios/chrome/browser/ui/settings/cells/settings_switch_cell.h" #import "ios/chrome/browser/ui/settings/cells/settings_switch_cell.h"
#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/elements/enterprise_info_popover_view_controller.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_cells_constants.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_detail_text_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_info_button_cell.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_info_button_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_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"
#import "ios/chrome/browser/ui/table_view/table_view_model.h" #import "ios/chrome/browser/ui/table_view/table_view_model.h"
...@@ -44,6 +47,7 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) { ...@@ -44,6 +47,7 @@ typedef NS_ENUM(NSInteger, SectionIdentifier) {
typedef NS_ENUM(NSInteger, ItemType) { typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeAutofillAddressSwitch = kItemTypeEnumZero, ItemTypeAutofillAddressSwitch = kItemTypeEnumZero,
ItemTypeAutofillAddressManaged,
ItemTypeAddress, ItemTypeAddress,
ItemTypeHeader, ItemTypeHeader,
ItemTypeFooter, ItemTypeFooter,
...@@ -111,8 +115,17 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -111,8 +115,17 @@ typedef NS_ENUM(NSInteger, ItemType) {
TableViewModel* model = self.tableViewModel; TableViewModel* model = self.tableViewModel;
[model addSectionWithIdentifier:SectionIdentifierSwitches]; [model addSectionWithIdentifier:SectionIdentifierSwitches];
[model addItem:[self addressSwitchItem]
toSectionWithIdentifier:SectionIdentifierSwitches]; if (base::FeatureList::IsEnabled(kEnableIOSManagedSettingsUI) &&
_browserState->GetPrefs()->IsManagedPreference(
autofill::prefs::kAutofillProfileEnabled)) {
[model addItem:[self managedAddressItem]
toSectionWithIdentifier:SectionIdentifierSwitches];
} else {
[model addItem:[self addressSwitchItem]
toSectionWithIdentifier:SectionIdentifierSwitches];
}
[model setFooter:[self addressSwitchFooter] [model setFooter:[self addressSwitchFooter]
forSectionWithIdentifier:SectionIdentifierSwitches]; forSectionWithIdentifier:SectionIdentifierSwitches];
...@@ -148,6 +161,17 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -148,6 +161,17 @@ typedef NS_ENUM(NSInteger, ItemType) {
return switchItem; return switchItem;
} }
- (TableViewInfoButtonItem*)managedAddressItem {
TableViewInfoButtonItem* managedAddressItem = [[TableViewInfoButtonItem alloc]
initWithType:ItemTypeAutofillAddressManaged];
managedAddressItem.text =
l10n_util::GetNSString(IDS_AUTOFILL_ENABLE_PROFILES_TOGGLE_LABEL);
// The status could only be off when the pref is managed.
managedAddressItem.statusText = l10n_util::GetNSString(IDS_IOS_SETTING_OFF);
managedAddressItem.accessibilityIdentifier = @"addressItem_managed";
return managedAddressItem;
}
- (TableViewHeaderFooterItem*)addressSwitchFooter { - (TableViewHeaderFooterItem*)addressSwitchFooter {
TableViewLinkHeaderFooterItem* footer = TableViewLinkHeaderFooterItem* footer =
[[TableViewLinkHeaderFooterItem alloc] initWithType:ItemTypeFooter]; [[TableViewLinkHeaderFooterItem alloc] initWithType:ItemTypeFooter];
...@@ -260,6 +284,26 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -260,6 +284,26 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self.tableView deselectRowAtIndexPath:indexPath animated:YES]; [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
} }
#pragma mark - Actions
// Called when the user clicks on the information button of the managed
// setting's UI. Shows a textual bubble with the information of the enterprise.
- (void)didTapManagedUIInfoButton:(UIButton*)buttonView {
EnterpriseInfoPopoverViewController* bubbleViewController =
[[EnterpriseInfoPopoverViewController alloc] initWithEnterpriseName:nil];
[self presentViewController:bubbleViewController animated:YES completion:nil];
// Disable the button when showing the bubble.
buttonView.enabled = NO;
// Set the anchor and arrow direction of the bubble.
bubbleViewController.popoverPresentationController.sourceView = buttonView;
bubbleViewController.popoverPresentationController.sourceRect =
buttonView.bounds;
bubbleViewController.popoverPresentationController.permittedArrowDirections =
UIPopoverArrowDirectionAny;
}
#pragma mark - UITableViewDataSource #pragma mark - UITableViewDataSource
- (BOOL)tableView:(UITableView*)tableView - (BOOL)tableView:(UITableView*)tableView
...@@ -287,14 +331,29 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -287,14 +331,29 @@ typedef NS_ENUM(NSInteger, ItemType) {
UITableViewCell* cell = [super tableView:tableView UITableViewCell* cell = [super tableView:tableView
cellForRowAtIndexPath:indexPath]; cellForRowAtIndexPath:indexPath];
ItemType itemType = static_cast<ItemType>( switch (static_cast<ItemType>(
[self.tableViewModel itemTypeForIndexPath:indexPath]); [self.tableViewModel itemTypeForIndexPath:indexPath])) {
if (itemType == ItemTypeAutofillAddressSwitch) { case ItemTypeAddress:
SettingsSwitchCell* switchCell = case ItemTypeHeader:
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell); case ItemTypeFooter:
[switchCell.switchView addTarget:self break;
action:@selector(autofillAddressSwitchChanged:) case ItemTypeAutofillAddressSwitch: {
forControlEvents:UIControlEventValueChanged]; SettingsSwitchCell* switchCell =
base::mac::ObjCCastStrict<SettingsSwitchCell>(cell);
[switchCell.switchView addTarget:self
action:@selector(autofillAddressSwitchChanged:)
forControlEvents:UIControlEventValueChanged];
break;
}
case ItemTypeAutofillAddressManaged: {
TableViewInfoButtonCell* managedCell =
base::mac::ObjCCastStrict<TableViewInfoButtonCell>(cell);
[managedCell.trailingButton
addTarget:self
action:@selector(didTapManagedUIInfoButton:)
forControlEvents:UIControlEventTouchUpInside];
break;
}
} }
return cell; return cell;
......
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