Commit d9f5a2e5 authored by David Jean's avatar David Jean Committed by Commit Bot

[ios] add manual fallback credit card and address view controller

Added base class that should be used in passwords later.

Bug: 845472
Change-Id: I1c1d2204d920ae141448239cfeb1c1c5a0e93a20
Reviewed-on: https://chromium-review.googlesource.com/c/1319714
Commit-Queue: David Jean <djean@chromium.org>
Reviewed-by: default avatarMoe Ahmadi <mahmadi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606773}
parent fd575eaf
...@@ -54,10 +54,16 @@ source_set("manual_fill_ui") { ...@@ -54,10 +54,16 @@ source_set("manual_fill_ui") {
"action_cell.mm", "action_cell.mm",
"address_consumer.h", "address_consumer.h",
"address_list_delegate.h", "address_list_delegate.h",
"address_view_controller.h",
"address_view_controller.mm",
"card_consumer.h", "card_consumer.h",
"card_list_delegate.h", "card_list_delegate.h",
"card_view_controller.h",
"card_view_controller.mm",
"credential.h", "credential.h",
"credential.mm", "credential.mm",
"fallback_view_controller.h",
"fallback_view_controller.mm",
"keyboard_observer_helper.h", "keyboard_observer_helper.h",
"keyboard_observer_helper.mm", "keyboard_observer_helper.mm",
"manual_fill_accessory_view_controller.h", "manual_fill_accessory_view_controller.h",
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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_AUTOFILL_MANUAL_FILL_ADDRESS_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/autofill/manual_fill/address_consumer.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/fallback_view_controller.h"
namespace manual_fill {
extern NSString* const AddressTableViewAccessibilityIdentifier;
} // namespace manual_fill
// This class presents a list of usernames and addresess in a table view.
@interface AddressViewController
: FallbackViewController<ManualFillAddressConsumer>
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_ADDRESS_VIEW_CONTROLLER_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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/autofill/manual_fill/address_view_controller.h"
#include "base/ios/ios_util.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/action_cell.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace manual_fill {
NSString* const AddressTableViewAccessibilityIdentifier =
@"kManualFillAddressTableViewAccessibilityIdentifier";
} // namespace manual_fill
@implementation AddressViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.accessibilityIdentifier =
manual_fill::AddressTableViewAccessibilityIdentifier;
}
#pragma mark - ManualFillAddressConsumer
// TODO(crbug.com/845472): look at replacing ManualFillXXXConsumer with
// ManualFillItemsConsumer.
- (void)presentAddresses:(NSArray<ManualFillAddressItem*>*)addresses {
[self presentDataItems:(NSArray<TableViewItem*>*)addresses];
}
- (void)presentActions:(NSArray<ManualFillActionItem*>*)actions {
[self presentActionItems:actions];
}
@end
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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_AUTOFILL_MANUAL_FILL_CARD_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/autofill/manual_fill/card_consumer.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/fallback_view_controller.h"
namespace manual_fill {
extern NSString* const CardTableViewAccessibilityIdentifier;
} // namespace manual_fill
// This class presents a list of credit cards in a table view.
@interface CardViewController : FallbackViewController<ManualFillCardConsumer>
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_CARD_VIEW_CONTROLLER_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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/autofill/manual_fill/card_view_controller.h"
#include "base/ios/ios_util.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/action_cell.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace manual_fill {
NSString* const CardTableViewAccessibilityIdentifier =
@"kManualFillCardTableViewAccessibilityIdentifier";
} // namespace manual_fill
@implementation CardViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView.accessibilityIdentifier =
manual_fill::CardTableViewAccessibilityIdentifier;
}
#pragma mark - ManualFillCardConsumer
- (void)presentCards:(NSArray<ManualFillCardItem*>*)cards {
[self presentDataItems:(NSArray<TableViewItem*>*)cards];
}
- (void)presentActions:(NSArray<ManualFillActionItem*>*)actions {
[self presentActionItems:actions];
}
@end
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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_AUTOFILL_MANUAL_FILL_FALLBACK_VIEW_CONTROLLER_H_
#define IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_FALLBACK_VIEW_CONTROLLER_H_
#import <UIKit/UIKit.h>
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
// This class presents a list of fallback item in a table view.
@interface FallbackViewController : ChromeTableViewController
- (instancetype)init NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
NS_UNAVAILABLE;
// If set to YES, the controller will add negative content insets inverse to the
// ones added by UITableViewController to accommodate for the keyboard.
@property(nonatomic, assign) BOOL contentInsetsAlwaysEqualToSafeArea;
// Presents given items in 'items' section.
- (void)presentDataItems:(NSArray<TableViewItem*>*)items;
// Presents given action items in 'actions' section.
- (void)presentActionItems:(NSArray<TableViewItem*>*)actions;
@end
#endif // IOS_CHROME_BROWSER_UI_AUTOFILL_MANUAL_FILL_FALLBACK_VIEW_CONTROLLER_H_
// Copyright 2018 The Chromium Authors. All rights reserved.
// 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/autofill/manual_fill/fallback_view_controller.h"
#include "base/ios/ios_util.h"
#import "ios/chrome/browser/ui/autofill/manual_fill/action_cell.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#include "ios/chrome/browser/ui/util/ui_util.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util_mac.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
typedef NS_ENUM(NSInteger, SectionIdentifier) {
ItemsSectionIdentifier = kSectionIdentifierEnumZero,
ActionsSectionIdentifier,
};
namespace {
// This is the width used for |self.preferredContentSize|.
constexpr float PopoverPreferredWidth = 320;
// This is the maximum height used for |self.preferredContentSize|.
constexpr float PopoverMaxHeight = 250;
} // namespace
@implementation FallbackViewController
- (instancetype)init {
self = [super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) {
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleKeyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(handleKeyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
}
return self;
}
- (void)viewDidLoad {
// Super's |viewDidLoad| uses |styler.tableViewBackgroundColor| so it needs to
// be set before.
self.styler.tableViewBackgroundColor = [UIColor whiteColor];
[super viewDidLoad];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.sectionHeaderHeight = 0;
self.tableView.sectionFooterHeight = 20.0;
self.tableView.estimatedRowHeight = 200;
self.tableView.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);
self.definesPresentationContext = YES;
}
- (void)presentDataItems:(NSArray<TableViewItem*>*)items {
if (!self.tableViewModel) {
[self loadModel];
}
BOOL sectionExist = [self.tableViewModel
hasSectionForSectionIdentifier:ItemsSectionIdentifier];
// If there are no passed items, remove section if exist.
if (!items.count && sectionExist) {
[self.tableViewModel removeSectionWithIdentifier:ItemsSectionIdentifier];
} else if (items.count && !sectionExist) {
[self.tableViewModel insertSectionWithIdentifier:ItemsSectionIdentifier
atIndex:0];
}
[self presentFallbackItems:items inSection:ItemsSectionIdentifier];
}
- (void)presentActionItems:(NSArray<TableViewItem*>*)actions {
if (!self.tableViewModel) {
[self loadModel];
}
BOOL sectionExist = [self.tableViewModel
hasSectionForSectionIdentifier:ActionsSectionIdentifier];
// If there are no passed items, remove section if exist.
if (!actions.count && sectionExist) {
[self.tableViewModel removeSectionWithIdentifier:ActionsSectionIdentifier];
} else if (actions.count && !sectionExist) {
[self.tableViewModel addSectionWithIdentifier:ActionsSectionIdentifier];
}
[self presentFallbackItems:actions inSection:ActionsSectionIdentifier];
}
#pragma mark - Private
- (void)handleKeyboardDidHide:(NSNotification*)notification {
if (self.contentInsetsAlwaysEqualToSafeArea && !IsIPadIdiom()) {
// Resets the table view content inssets to be equal to the safe area
// insets.
self.tableView.contentInset = SafeAreaInsetsForView(self.view);
}
}
- (void)handleKeyboardWillShow:(NSNotification*)notification {
if (self.contentInsetsAlwaysEqualToSafeArea && !IsIPadIdiom()) {
// Sets the bottom inset to be equal to the height of the keyboard to
// override the behaviour in UITableViewController. Which adjust the scroll
// view insets to accommodate for the keyboard.
CGRect keyboardFrame =
[notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = keyboardFrame.size.height;
UIEdgeInsets safeInsets = SafeAreaInsetsForView(self.view);
self.tableView.contentInset =
UIEdgeInsetsMake(safeInsets.top, safeInsets.left,
safeInsets.bottom - keyboardHeight, safeInsets.right);
}
}
// Presents |items| in the respective section. Handles creating or deleting the
// section accordingly.
- (void)presentFallbackItems:(NSArray<TableViewItem*>*)items
inSection:(SectionIdentifier)sectionIdentifier {
// If there are no passed items, remove section if exist.
if (items.count) {
[self.tableViewModel
deleteAllItemsFromSectionWithIdentifier:sectionIdentifier];
for (TableViewItem* item in items) {
[self.tableViewModel addItem:item
toSectionWithIdentifier:sectionIdentifier];
}
}
[self.tableView reloadData];
if (IsIPadIdiom()) {
// Update the preffered content size on iPad so the popover shows the right
// size.
[self.tableView layoutIfNeeded];
CGSize systemLayoutSize = self.tableView.contentSize;
CGFloat preferredHeight = MIN(systemLayoutSize.height, PopoverMaxHeight);
self.preferredContentSize =
CGSizeMake(PopoverPreferredWidth, preferredHeight);
}
}
@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