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 @@
self.modalViewController.infobarModalDelegate = self;
self.modalViewController.username =
self.passwordInfoBarDelegate->GetUserNameText();
self.modalViewController.saveButtonText =
base::SysUTF16ToNSString(self.passwordInfoBarDelegate->GetButtonLabel(
ConfirmInfoBarDelegate::BUTTON_OK));
self.modalViewController.URL = self.passwordInfoBarDelegate->GetURLHostText();
}
......
......@@ -19,6 +19,8 @@
@property(nonatomic, copy) NSString* username;
// The URL being displayed in the InfobarModal.
@property(nonatomic, copy) NSString* URL;
// The text used for the save credentials button.
@property(nonatomic, copy) NSString* saveButtonText;
@end
......
......@@ -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_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_edit_item.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
......@@ -27,9 +28,18 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeURL = kItemTypeEnumZero,
ItemTypeUsername,
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
#pragma mark - ViewController Lifecycle
......@@ -78,30 +88,30 @@ typedef NS_ENUM(NSInteger, ItemType) {
[model addItem:URLDetailItem
toSectionWithIdentifier:SectionIdentifierContent];
TableViewDetailIconItem* usernameDetailItem =
[[TableViewDetailIconItem alloc] initWithType:ItemTypeUsername];
usernameDetailItem.text =
TableViewTextEditItem* usernameTextEditItem =
[[TableViewTextEditItem alloc] initWithType:ItemTypeUsername];
usernameTextEditItem.textFieldName =
l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_USERNAME);
usernameDetailItem.detailText = self.username;
[model addItem:usernameDetailItem
usernameTextEditItem.textFieldValue = self.username;
usernameTextEditItem.textFieldEnabled = YES;
[model addItem:usernameTextEditItem
toSectionWithIdentifier:SectionIdentifierContent];
TableViewDetailIconItem* passwordDetailItem =
[[TableViewDetailIconItem alloc] initWithType:ItemTypePassword];
passwordDetailItem.text =
self.passwordItem =
[[TableViewTextEditItem alloc] initWithType:ItemTypePassword];
self.passwordItem.textFieldName =
l10n_util::GetNSString(IDS_IOS_SHOW_PASSWORD_VIEW_PASSWORD);
// TODO(crbug.com/927064): Set the number of dots depending on Password
// length?
passwordDetailItem.detailText = @"•••••••••";
[model addItem:passwordDetailItem
self.passwordItem.textFieldValue = @"•••••••••";
self.passwordItem.textFieldEnabled = YES;
[model addItem:self.passwordItem
toSectionWithIdentifier:SectionIdentifierContent];
TableViewTextButtonItem* savePasswordButtonItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeSavePassword];
// TODO(crbug.com/927064): Create IDS String for this once we're sure about
// the exact text.
savePasswordButtonItem.buttonText = @"Save Password";
[model addItem:savePasswordButtonItem
self.saveCredentialsItem =
[[TableViewTextButtonItem alloc] initWithType:ItemTypeSaveCredentials];
self.saveCredentialsItem.buttonText = self.saveButtonText;
[model addItem:self.saveCredentialsItem
toSectionWithIdentifier:SectionIdentifierContent];
}
......@@ -111,16 +121,30 @@ typedef NS_ENUM(NSInteger, ItemType) {
cellForRowAtIndexPath:(NSIndexPath*)indexPath {
UITableViewCell* cell = [super tableView:tableView
cellForRowAtIndexPath:indexPath];
NSInteger itemTypeSelected =
[self.tableViewModel itemTypeForIndexPath:indexPath];
if (itemTypeSelected == ItemTypeSavePassword) {
TableViewTextButtonCell* tableViewTextButtonCell =
base::mac::ObjCCastStrict<TableViewTextButtonCell>(cell);
[tableViewTextButtonCell.button
addTarget:self.infobarModalDelegate
action:@selector(modalInfobarButtonWasPressed:)
forControlEvents:UIControlEventTouchUpInside];
ItemType itemType = static_cast<ItemType>(
[self.tableViewModel itemTypeForIndexPath:indexPath]);
switch (itemType) {
case ItemTypeSaveCredentials: {
TableViewTextButtonCell* tableViewTextButtonCell =
base::mac::ObjCCastStrict<TableViewTextButtonCell>(cell);
[tableViewTextButtonCell.button
addTarget:self.infobarModalDelegate
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;
......@@ -128,6 +152,15 @@ typedef NS_ENUM(NSInteger, ItemType) {
#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 {
[self.infobarModalDelegate dismissInfobarModal:sender completion:nil];
}
......
......@@ -14,6 +14,7 @@
// Text being displayed above the button.
@property(nonatomic, readwrite, strong) NSString* text;
// Text for cell button.
@property(nonatomic, readwrite, strong) NSString* buttonText;
......@@ -23,6 +24,10 @@
// Accessibility identifier that will assigned to the button.
@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
// TableViewTextButtonCell contains a textLabel and a UIbutton
......@@ -31,6 +36,7 @@
// Cell text information.
@property(nonatomic, strong) UILabel* textLabel;
// Action button. Note: Set action method in the TableView datasource method.
@property(nonatomic, strong) UIButton* button;
......
......@@ -16,6 +16,8 @@ namespace {
const CGFloat grayHexColor = 0x6d6d72;
// Action button blue background color.
const CGFloat blueHexColor = 0x1A73E8;
// Alpha value for the disabled action button.
const CGFloat disabledButtonAlpha = 0.5;
// Vertical spacing between stackView and cell contentView.
const CGFloat stackViewVerticalSpacing = 9.0;
// Horizontal spacing between stackView and cell contentView.
......@@ -42,6 +44,7 @@ const CGFloat buttonTitleFontSize = 17.0;
self = [super initWithType:type];
if (self) {
self.cellClass = [TableViewTextButtonCell class];
_enabled = YES;
}
return self;
}
......@@ -58,6 +61,11 @@ const CGFloat buttonTitleFontSize = 17.0;
? self.buttonBackgroundColor
: UIColorFromRGB(blueHexColor);
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
cell.button.enabled = self.enabled;
if (!self.enabled) {
cell.button.backgroundColor = [cell.button.backgroundColor
colorWithAlphaComponent:disabledButtonAlpha];
}
}
@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