Commit 24fd92ce authored by sczs's avatar sczs Committed by Commit Bot

[ios] Adds edit support for InfobarPasswordTableVC items

-InfobarPasswordTableVC now uses TableViewTextEditItem so the password
and username fields can be edited.
-Adds validation that disables the Save/Update button if the password is
blank.
-Adds disable property and styling to TableViewTextButtonItem.

Screenshots:
https://drive.google.com/open?id=1GO3Z-sqLMUmfuPtBkQnp27jqKjbn-dSy
https://drive.google.com/open?id=1x5ob2m5kXtvnghUlUXxXHW6O0g1SPHkO

Bug: 945478
Change-Id: Icfab83033d7edd3b3b686a3e4efce4c098a149a6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1559763Reviewed-by: default avatarPeter Lee <pkl@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649685}
parent feeb9a67
...@@ -81,6 +81,9 @@ ...@@ -81,6 +81,9 @@
self.modalViewController.infobarModalDelegate = self; self.modalViewController.infobarModalDelegate = self;
self.modalViewController.username = self.modalViewController.username =
self.passwordInfoBarDelegate->GetUserNameText(); self.passwordInfoBarDelegate->GetUserNameText();
self.modalViewController.saveButtonText =
base::SysUTF16ToNSString(self.passwordInfoBarDelegate->GetButtonLabel(
ConfirmInfoBarDelegate::BUTTON_OK));
self.modalViewController.URL = self.passwordInfoBarDelegate->GetURLHostText(); self.modalViewController.URL = self.passwordInfoBarDelegate->GetURLHostText();
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
@property(nonatomic, copy) NSString* username; @property(nonatomic, copy) NSString* username;
// The URL being displayed in the InfobarModal. // The URL being displayed in the InfobarModal.
@property(nonatomic, copy) NSString* URL; @property(nonatomic, copy) NSString* URL;
// The text used for the save credentials button.
@property(nonatomic, copy) NSString* saveButtonText;
@end @end
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#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_icon_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_detail_icon_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_button_item.h" #import "ios/chrome/browser/ui/table_view/cells/table_view_text_button_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_edit_item.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.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"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
...@@ -27,9 +28,18 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -27,9 +28,18 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeURL = kItemTypeEnumZero, ItemTypeURL = kItemTypeEnumZero,
ItemTypeUsername, ItemTypeUsername,
ItemTypePassword, ItemTypePassword,
ItemTypeSavePassword, ItemTypeSaveCredentials,
}; };
@interface InfobarPasswordTableViewController ()
// Item that holds the Username TextField information.
@property(nonatomic, strong) TableViewTextEditItem* usernameItem;
// Item that holds the Password TextField information.
@property(nonatomic, strong) TableViewTextEditItem* passwordItem;
// Item that holds the SaveCredentials Button information.
@property(nonatomic, strong) TableViewTextButtonItem* saveCredentialsItem;
@end
@implementation InfobarPasswordTableViewController @implementation InfobarPasswordTableViewController
#pragma mark - ViewController Lifecycle #pragma mark - ViewController Lifecycle
...@@ -78,30 +88,30 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -78,30 +88,30 @@ typedef NS_ENUM(NSInteger, ItemType) {
[model addItem:URLDetailItem [model addItem:URLDetailItem
toSectionWithIdentifier:SectionIdentifierContent]; toSectionWithIdentifier:SectionIdentifierContent];
TableViewDetailIconItem* usernameDetailItem = TableViewTextEditItem* usernameTextEditItem =
[[TableViewDetailIconItem alloc] initWithType:ItemTypeUsername]; [[TableViewTextEditItem alloc] initWithType:ItemTypeUsername];
usernameDetailItem.text = usernameTextEditItem.textFieldName =
l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME); l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME);
usernameDetailItem.detailText = self.username; usernameTextEditItem.textFieldValue = self.username;
[model addItem:usernameDetailItem usernameTextEditItem.textFieldEnabled = YES;
[model addItem:usernameTextEditItem
toSectionWithIdentifier:SectionIdentifierContent]; toSectionWithIdentifier:SectionIdentifierContent];
TableViewDetailIconItem* passwordDetailItem = self.passwordItem =
[[TableViewDetailIconItem alloc] initWithType:ItemTypePassword]; [[TableViewTextEditItem alloc] initWithType:ItemTypePassword];
passwordDetailItem.text = self.passwordItem.textFieldName =
l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD); l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD);
// TODO(crbug.com/927064): Set the number of dots depending on Password // TODO(crbug.com/927064): Set the number of dots depending on Password
// length? // length?
passwordDetailItem.detailText = @"•••••••••"; self.passwordItem.textFieldValue = @"•••••••••";
[model addItem:passwordDetailItem self.passwordItem.textFieldEnabled = YES;
[model addItem:self.passwordItem
toSectionWithIdentifier:SectionIdentifierContent]; toSectionWithIdentifier:SectionIdentifierContent];
TableViewTextButtonItem* savePasswordButtonItem = self.saveCredentialsItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeSavePassword]; [[TableViewTextButtonItem alloc] initWithType:ItemTypeSaveCredentials];
// TODO(crbug.com/927064): Create IDS String for this once we're sure about self.saveCredentialsItem.buttonText = self.saveButtonText;
// the exact text. [model addItem:self.saveCredentialsItem
savePasswordButtonItem.buttonText = @"Save Password";
[model addItem:savePasswordButtonItem
toSectionWithIdentifier:SectionIdentifierContent]; toSectionWithIdentifier:SectionIdentifierContent];
} }
...@@ -111,16 +121,30 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -111,16 +121,30 @@ typedef NS_ENUM(NSInteger, ItemType) {
cellForRowAtIndexPath:(NSIndexPath*)indexPath { cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UITableViewCell* cell = [super tableView:tableView UITableViewCell* cell = [super tableView:tableView
cellForRowAtIndexPath:indexPath]; cellForRowAtIndexPath:indexPath];
NSInteger itemTypeSelected = ItemType itemType = static_cast<ItemType>(
[self.tableViewModel itemTypeForIndexPath:indexPath]; [self.tableViewModel itemTypeForIndexPath:indexPath]);
if (itemTypeSelected == ItemTypeSavePassword) { switch (itemType) {
TableViewTextButtonCell* tableViewTextButtonCell = case ItemTypeSaveCredentials: {
base::mac::ObjCCastStrict<TableViewTextButtonCell>(cell); TableViewTextButtonCell* tableViewTextButtonCell =
[tableViewTextButtonCell.button base::mac::ObjCCastStrict<TableViewTextButtonCell>(cell);
addTarget:self.infobarModalDelegate [tableViewTextButtonCell.button
action:@selector(modalInfobarButtonWasPressed:) addTarget:self.infobarModalDelegate
forControlEvents:UIControlEventTouchUpInside]; action:@selector(modalInfobarButtonWasPressed:)
forControlEvents:UIControlEventTouchUpInside];
break;
}
case ItemTypeUsername:
case ItemTypePassword: {
TableViewTextEditCell* editCell =
base::mac::ObjCCast<TableViewTextEditCell>(cell);
[editCell.textField addTarget:self
action:@selector(updateSaveCredentialsButtonState)
forControlEvents:UIControlEventEditingChanged];
break;
}
case ItemTypeURL:
break;
} }
return cell; return cell;
...@@ -128,6 +152,15 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -128,6 +152,15 @@ typedef NS_ENUM(NSInteger, ItemType) {
#pragma mark - Private Methods #pragma mark - Private Methods
- (void)updateSaveCredentialsButtonState {
BOOL currentButtonState = [self.saveCredentialsItem isEnabled];
BOOL newButtonState = [self.passwordItem.textFieldValue length] ? YES : NO;
if (currentButtonState != newButtonState) {
self.saveCredentialsItem.enabled = newButtonState;
[self reconfigureCellsForItems:@[ self.saveCredentialsItem ]];
}
}
- (void)dismissInfobarModal:(UIButton*)sender { - (void)dismissInfobarModal:(UIButton*)sender {
[self.infobarModalDelegate dismissInfobarModal:sender completion:nil]; [self.infobarModalDelegate dismissInfobarModal:sender completion:nil];
} }
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
// Text being displayed above the button. // Text being displayed above the button.
@property(nonatomic, readwrite, strong) NSString* text; @property(nonatomic, readwrite, strong) NSString* text;
// Text for cell button. // Text for cell button.
@property(nonatomic, readwrite, strong) NSString* buttonText; @property(nonatomic, readwrite, strong) NSString* buttonText;
...@@ -23,6 +24,10 @@ ...@@ -23,6 +24,10 @@
// Accessibility identifier that will assigned to the button. // Accessibility identifier that will assigned to the button.
@property(nonatomic, strong) NSString* buttonAccessibilityIdentifier; @property(nonatomic, strong) NSString* buttonAccessibilityIdentifier;
// Whether the Item's button should be enabled or not. Button is enabled by
// default.
@property(nonatomic, assign, getter=isEnabled) BOOL enabled;
@end @end
// TableViewTextButtonCell contains a textLabel and a UIbutton // TableViewTextButtonCell contains a textLabel and a UIbutton
...@@ -31,6 +36,7 @@ ...@@ -31,6 +36,7 @@
// Cell text information. // Cell text information.
@property(nonatomic, strong) UILabel* textLabel; @property(nonatomic, strong) UILabel* textLabel;
// Action button. Note: Set action method in the TableView datasource method. // Action button. Note: Set action method in the TableView datasource method.
@property(nonatomic, strong) UIButton* button; @property(nonatomic, strong) UIButton* button;
......
...@@ -16,6 +16,8 @@ namespace { ...@@ -16,6 +16,8 @@ namespace {
const CGFloat grayHexColor = 0x6d6d72; const CGFloat grayHexColor = 0x6d6d72;
// Action button blue background color. // Action button blue background color.
const CGFloat blueHexColor = 0x1A73E8; const CGFloat blueHexColor = 0x1A73E8;
// Alpha value for the disabled action button.
const CGFloat disabledButtonAlpha = 0.5;
// Vertical spacing between stackView and cell contentView. // Vertical spacing between stackView and cell contentView.
const CGFloat stackViewVerticalSpacing = 9.0; const CGFloat stackViewVerticalSpacing = 9.0;
// Horizontal spacing between stackView and cell contentView. // Horizontal spacing between stackView and cell contentView.
...@@ -42,6 +44,7 @@ const CGFloat buttonTitleFontSize = 17.0; ...@@ -42,6 +44,7 @@ const CGFloat buttonTitleFontSize = 17.0;
self = [super initWithType:type]; self = [super initWithType:type];
if (self) { if (self) {
self.cellClass = [TableViewTextButtonCell class]; self.cellClass = [TableViewTextButtonCell class];
_enabled = YES;
} }
return self; return self;
} }
...@@ -58,6 +61,11 @@ const CGFloat buttonTitleFontSize = 17.0; ...@@ -58,6 +61,11 @@ const CGFloat buttonTitleFontSize = 17.0;
? self.buttonBackgroundColor ? self.buttonBackgroundColor
: UIColorFromRGB(blueHexColor); : UIColorFromRGB(blueHexColor);
[cell setSelectionStyle:UITableViewCellSelectionStyleNone]; [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.button.enabled = self.enabled;
if (!self.enabled) {
cell.button.backgroundColor = [cell.button.backgroundColor
colorWithAlphaComponent:disabledButtonAlpha];
}
} }
@end @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