Commit 8376eb4a authored by sczs's avatar sczs Committed by Commit Bot

[ios] Moves EditBookmark InvalidURL label to footer.

As per UX request, this is being moved to a tableView footer instead of the cell itself.

Screenshot:
https://drive.google.com/open?id=1zK2X9e-__l3CurjcB7Z3zgUIxTgSxXuJ

Bug: 843827
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I977a625d10c108efa4f0794a2aafd77a32b8e495
Reviewed-on: https://chromium-review.googlesource.com/1142527Reviewed-by: default avataredchin <edchin@chromium.org>
Commit-Queue: edchin <edchin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576394}
parent faee83df
...@@ -30,8 +30,10 @@ ...@@ -30,8 +30,10 @@
#import "ios/chrome/browser/ui/image_util/image_util.h" #import "ios/chrome/browser/ui/image_util/image_util.h"
#import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h" #import "ios/chrome/browser/ui/keyboard/UIKeyCommand+Chrome.h"
#include "ios/chrome/browser/ui/rtl_geometry.h" #include "ios/chrome/browser/ui/rtl_geometry.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_text_header_footer_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/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h"
#import "ios/chrome/common/ui_util/constraints_ui_util.h" #import "ios/chrome/common/ui_util/constraints_ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#import "ios/public/provider/chrome/browser/chrome_browser_provider.h" #import "ios/public/provider/chrome/browser/chrome_browser_provider.h"
...@@ -71,7 +73,11 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -71,7 +73,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
ItemTypeName = kItemTypeEnumZero, ItemTypeName = kItemTypeEnumZero,
ItemTypeFolder, ItemTypeFolder,
ItemTypeURL, ItemTypeURL,
ItemTypeInvalidURLFooter,
}; };
// The text color for the invalid URL label.
const CGFloat kInvalidURLTextColor = 0xEA4335;
} // namespace } // namespace
@interface BookmarkEditViewController ()<BookmarkFolderViewControllerDelegate, @interface BookmarkEditViewController ()<BookmarkFolderViewControllerDelegate,
...@@ -114,6 +120,9 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -114,6 +120,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
@property(nonatomic, strong) BookmarkParentFolderItem* folderItem; @property(nonatomic, strong) BookmarkParentFolderItem* folderItem;
@property(nonatomic, strong) BookmarkTextFieldItem* URLItem; @property(nonatomic, strong) BookmarkTextFieldItem* URLItem;
// YES if the URL item is displaying a valid URL.
@property(nonatomic, assign) BOOL displayingValidURL;
// Reports the changes to the delegate, that has the responsibility to save the // Reports the changes to the delegate, that has the responsibility to save the
// bookmark. // bookmark.
- (void)commitBookmarkChanges; - (void)commitBookmarkChanges;
...@@ -153,6 +162,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -153,6 +162,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
@synthesize bookmark = _bookmark; @synthesize bookmark = _bookmark;
@synthesize bookmarkModel = _bookmarkModel; @synthesize bookmarkModel = _bookmarkModel;
@synthesize delegate = _delegate; @synthesize delegate = _delegate;
@synthesize displayingValidURL = _displayingValidURL;
@synthesize folder = _folder; @synthesize folder = _folder;
@synthesize folderViewController = _folderViewController; @synthesize folderViewController = _folderViewController;
@synthesize browserState = _browserState; @synthesize browserState = _browserState;
...@@ -207,7 +217,6 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -207,7 +217,6 @@ typedef NS_ENUM(NSInteger, ItemType) {
self.tableView.estimatedRowHeight = 88.0; self.tableView.estimatedRowHeight = 88.0;
self.tableView.rowHeight = UITableViewAutomaticDimension; self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.sectionHeaderHeight = 0; self.tableView.sectionHeaderHeight = 0;
self.tableView.sectionFooterHeight = 0;
self.view.accessibilityIdentifier = kBookmarkEditViewContainerIdentifier; self.view.accessibilityIdentifier = kBookmarkEditViewContainerIdentifier;
if (experimental_flags::IsBookmarksUIRebootEnabled()) { if (experimental_flags::IsBookmarksUIRebootEnabled()) {
...@@ -406,6 +415,11 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -406,6 +415,11 @@ typedef NS_ENUM(NSInteger, ItemType) {
self.URLItem.delegate = self; self.URLItem.delegate = self;
[model addItem:self.URLItem toSectionWithIdentifier:SectionIdentifierInfo]; [model addItem:self.URLItem toSectionWithIdentifier:SectionIdentifierInfo];
TableViewHeaderFooterItem* errorFooter =
[[TableViewHeaderFooterItem alloc] initWithType:ItemTypeInvalidURLFooter];
[model setFooter:errorFooter forSectionWithIdentifier:SectionIdentifierInfo];
self.displayingValidURL = YES;
// Save button state. // Save button state.
[self updateSaveButtonState]; [self updateSaveButtonState];
} }
...@@ -472,21 +486,20 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -472,21 +486,20 @@ typedef NS_ENUM(NSInteger, ItemType) {
- (void)textDidChangeForItem:(BookmarkTextFieldItem*)item { - (void)textDidChangeForItem:(BookmarkTextFieldItem*)item {
[self updateSaveButtonState]; [self updateSaveButtonState];
if (experimental_flags::IsBookmarksUIRebootEnabled() &&
if (experimental_flags::IsBookmarksUIRebootEnabled()) { (self.displayingValidURL != [self inputURLIsValid])) {
NSIndexPath* textFieldIndexPath = self.displayingValidURL = [self inputURLIsValid];
[self.tableViewModel indexPathForItemType:item.type UITableViewHeaderFooterView* footer = [self.tableView
sectionIdentifier:SectionIdentifierInfo]; footerViewForSection:[self.tableViewModel sectionForSectionIdentifier:
UITableViewCell* cell = SectionIdentifierInfo]];
[self.tableView cellForRowAtIndexPath:textFieldIndexPath]; NSString* footerText =
BookmarkTextFieldCell* URLCell = [self inputURLIsValid]
base::mac::ObjCCastStrict<BookmarkTextFieldCell>(cell); ? @""
// Update the URLCell valid state if it has changed. : l10n_util::GetNSString(
if ([self inputURLIsValid] != URLCell.validState) { IDS_IOS_BOOKMARK_URL_FIELD_VALIDATION_FAILED);
[self.tableView beginUpdates]; [self.tableView beginUpdates];
URLCell.validState = [self inputURLIsValid]; footer.textLabel.text = footerText;
[self.tableView endUpdates]; [self.tableView endUpdates];
}
} }
} }
...@@ -542,6 +555,21 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -542,6 +555,21 @@ typedef NS_ENUM(NSInteger, ItemType) {
[self moveBookmark]; [self moveBookmark];
} }
- (UIView*)tableView:(UITableView*)tableView
viewForFooterInSection:(NSInteger)section {
UIView* footerView =
[super tableView:tableView viewForFooterInSection:section];
if (section ==
[self.tableViewModel sectionForSectionIdentifier:SectionIdentifierInfo]) {
UITableViewHeaderFooterView* headerFooterView =
base::mac::ObjCCastStrict<UITableViewHeaderFooterView>(footerView);
headerFooterView.textLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
headerFooterView.textLabel.textColor = UIColorFromRGB(kInvalidURLTextColor);
}
return footerView;
}
#pragma mark - BookmarkFolderViewControllerDelegate #pragma mark - BookmarkFolderViewControllerDelegate
- (void)folderPicker:(BookmarkFolderViewController*)folderPicker - (void)folderPicker:(BookmarkFolderViewController*)folderPicker
......
...@@ -42,10 +42,6 @@ ...@@ -42,10 +42,6 @@
// Text field to display the title or the URL of the bookmark node. // Text field to display the title or the URL of the bookmark node.
@property(nonatomic, strong) UITextField* textField; @property(nonatomic, strong) UITextField* textField;
// If |NO| changes the cell appearance to reflect that |self.textfield| is on an
// invalid state.
@property(nonatomic, assign) BOOL validState;
@end @end
@interface LegacyBookmarkTextFieldCell : UITableViewCell @interface LegacyBookmarkTextFieldCell : UITableViewCell
......
...@@ -56,7 +56,6 @@ ...@@ -56,7 +56,6 @@
cell.textField.accessibilityLabel = self.text; cell.textField.accessibilityLabel = self.text;
cell.textField.accessibilityIdentifier = [NSString cell.textField.accessibilityIdentifier = [NSString
stringWithFormat:@"%@_textField", self.accessibilityIdentifier]; stringWithFormat:@"%@_textField", self.accessibilityIdentifier];
cell.validState = YES;
cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else { } else {
LegacyBookmarkTextFieldCell* cell = LegacyBookmarkTextFieldCell* cell =
...@@ -86,15 +85,9 @@ ...@@ -86,15 +85,9 @@
#pragma mark - BookmarkTextFieldCell #pragma mark - BookmarkTextFieldCell
@interface BookmarkTextFieldCell ()
@property(nonatomic, strong) UILabel* invalidURLLabel;
@end
@implementation BookmarkTextFieldCell @implementation BookmarkTextFieldCell
@synthesize textField = _textField; @synthesize textField = _textField;
@synthesize titleLabel = _titleLabel; @synthesize titleLabel = _titleLabel;
@synthesize invalidURLLabel = _invalidURLLabel;
@synthesize validState = _validState;
- (instancetype)initWithStyle:(UITableViewCellStyle)style - (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier { reuseIdentifier:(NSString*)reuseIdentifier {
...@@ -138,44 +131,21 @@ ...@@ -138,44 +131,21 @@
[horizontalStack [horizontalStack
setContentCompressionResistancePriority:UILayoutPriorityRequired setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical]; forAxis:UILayoutConstraintAxisVertical];
horizontalStack.translatesAutoresizingMaskIntoConstraints = NO;
// Invalid URL label [self.contentView addSubview:horizontalStack];
self.invalidURLLabel = [[UILabel alloc] init];
self.invalidURLLabel.text =
l10n_util::GetNSString(IDS_IOS_BOOKMARK_URL_FIELD_VALIDATION_FAILED);
self.invalidURLLabel.textColor = [UIColor redColor];
self.invalidURLLabel.font =
[UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
self.invalidURLLabel.adjustsFontForContentSizeCategory = YES;
[self.invalidURLLabel
setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical];
[self.invalidURLLabel
setContentHuggingPriority:UILayoutPriorityDefaultLow
forAxis:UILayoutConstraintAxisHorizontal];
// Vertical StackView.
UIStackView* verticalStack = [[UIStackView alloc]
initWithArrangedSubviews:@[ horizontalStack, self.invalidURLLabel ]];
verticalStack.axis = UILayoutConstraintAxisVertical;
verticalStack.translatesAutoresizingMaskIntoConstraints = NO;
[verticalStack
setContentCompressionResistancePriority:UILayoutPriorityRequired
forAxis:UILayoutConstraintAxisVertical];
[self.contentView addSubview:verticalStack];
// Set up constraints. // Set up constraints.
[NSLayoutConstraint activateConstraints:@[ [NSLayoutConstraint activateConstraints:@[
[verticalStack.topAnchor [horizontalStack.topAnchor
constraintEqualToAnchor:self.contentView.topAnchor constraintEqualToAnchor:self.contentView.topAnchor
constant:kBookmarkCellVerticalInset], constant:kBookmarkCellVerticalInset],
[verticalStack.bottomAnchor [horizontalStack.bottomAnchor
constraintEqualToAnchor:self.contentView.bottomAnchor constraintEqualToAnchor:self.contentView.bottomAnchor
constant:-kBookmarkCellVerticalInset], constant:-kBookmarkCellVerticalInset],
[verticalStack.leadingAnchor [horizontalStack.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kBookmarkCellHorizontalLeadingInset], constant:kBookmarkCellHorizontalLeadingInset],
[verticalStack.trailingAnchor [horizontalStack.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kBookmarkCellHorizontalTrailingInset], constant:-kBookmarkCellHorizontalTrailingInset],
]]; ]];
...@@ -183,24 +153,12 @@ ...@@ -183,24 +153,12 @@
return self; return self;
} }
- (void)setValidState:(BOOL)validState {
_validState = validState;
if (validState) {
self.invalidURLLabel.hidden = YES;
self.textField.textColor = [UIColor lightGrayColor];
} else {
self.invalidURLLabel.hidden = NO;
self.textField.textColor = [UIColor redColor];
}
}
- (void)prepareForReuse { - (void)prepareForReuse {
[super prepareForReuse]; [super prepareForReuse];
[self.textField resignFirstResponder]; [self.textField resignFirstResponder];
[self.textField removeTarget:nil [self.textField removeTarget:nil
action:NULL action:NULL
forControlEvents:UIControlEventAllEvents]; forControlEvents:UIControlEventAllEvents];
self.validState = YES;
self.textField.delegate = nil; self.textField.delegate = nil;
self.textField.text = nil; self.textField.text = nil;
} }
......
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