Commit c6acad34 authored by sczs's avatar sczs Committed by Commit Bot

[ios] Displays the SaveCard Modal if Card will be uploaded.

- If the card will be uploaded the Modal with the ToS needs is shown
before.
- Creates SaveCardModalDelegate that its used by the Modal to Save the
Card.
- Adds a currentCardSaved property to the ModalVC in order to disable
the SaveButton if the card has been already saved.


Bug: 1014652
Change-Id: I3dadaf24b307c8ffe3b68d499e9ef3840c299623
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1913023
Commit-Queue: Sergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarChris Lu <thegreenfrog@chromium.org>
Cr-Commit-Position: refs/heads/master@{#715045}
parent 8b5b046f
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/infobars/banners/infobar_banner_view_controller.h" #import "ios/chrome/browser/ui/infobars/banners/infobar_banner_view_controller.h"
#import "ios/chrome/browser/ui/infobars/coordinators/infobar_coordinator_implementation.h" #import "ios/chrome/browser/ui/infobars/coordinators/infobar_coordinator_implementation.h"
#import "ios/chrome/browser/ui/infobars/infobar_container.h" #import "ios/chrome/browser/ui/infobars/infobar_container.h"
#import "ios/chrome/browser/ui/infobars/modals/infobar_save_card_modal_delegate.h"
#import "ios/chrome/browser/ui/infobars/modals/infobar_save_card_table_view_controller.h" #import "ios/chrome/browser/ui/infobars/modals/infobar_save_card_table_view_controller.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h" #import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
...@@ -21,7 +22,8 @@ ...@@ -21,7 +22,8 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@interface InfobarSaveCardCoordinator () <InfobarCoordinatorImplementation> @interface InfobarSaveCardCoordinator () <InfobarCoordinatorImplementation,
InfobarSaveCardModalDelegate>
// InfobarBannerViewController owned by this Coordinator. // InfobarBannerViewController owned by this Coordinator.
@property(nonatomic, strong) InfobarBannerViewController* bannerViewController; @property(nonatomic, strong) InfobarBannerViewController* bannerViewController;
...@@ -62,9 +64,14 @@ ...@@ -62,9 +64,14 @@
initWithDelegate:self initWithDelegate:self
presentsModal:self.hasBadge presentsModal:self.hasBadge
type:InfobarType::kInfobarTypeSaveCard]; type:InfobarType::kInfobarTypeSaveCard];
self.bannerViewController.buttonText = if (self.saveCardInfoBarDelegate->upload()) {
base::SysUTF16ToNSString(self.saveCardInfoBarDelegate->GetButtonLabel( // TODO(crbug.com/1014652): Use real string once its been created.
ConfirmInfoBarDelegate::BUTTON_OK)); self.bannerViewController.buttonText = @"Save...";
} else {
self.bannerViewController.buttonText =
base::SysUTF16ToNSString(self.saveCardInfoBarDelegate->GetButtonLabel(
ConfirmInfoBarDelegate::BUTTON_OK));
}
self.bannerViewController.titleText = base::SysUTF16ToNSString( self.bannerViewController.titleText = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->GetMessageText()); self.saveCardInfoBarDelegate->GetMessageText());
self.bannerViewController.subTitleText = self.bannerViewController.subTitleText =
...@@ -94,29 +101,15 @@ ...@@ -94,29 +101,15 @@
} }
- (void)performInfobarAction { - (void)performInfobarAction {
if (self.saveCardInfoBarDelegate->upload()) { // Display the modal (thus the ToS) if the card will be uploaded, this is a
// TODO(crbug.com/1014652): Open Modal if CreditCard details will be // legal requirement and shouldn't be changed.
// uploaded. Meaning that the ToS needs to be displayed. if (!self.modalViewController && self.saveCardInfoBarDelegate->upload()) {
} else if (self.saveCardInfoBarDelegate->Accept()) { [self presentInfobarModalFromBanner];
self.infobarAccepted = YES; return;
// TODO(crbug.com/1014652): Until a post save editing functionality is
// implemented the Infobar will be completely removed after its been
// accepted.
if (self.modalViewController) {
[self dismissInfobarModal:self
animated:YES
completion:^{
// TODO(crbug.com/1014652): Once the badge is created
// confirm detachView completely removes it.
[self detachView];
}];
} else {
[self dismissInfobarBannerAnimated:YES
completion:^{
[self detachView];
}];
}
} }
// Ignore the Accept() return value since it always returns YES.
self.saveCardInfoBarDelegate->Accept();
self.infobarAccepted = YES;
} }
- (void)infobarWasDismissed { - (void)infobarWasDismissed {
...@@ -170,6 +163,7 @@ ...@@ -170,6 +163,7 @@
self.saveCardInfoBarDelegate->expiration_date_month()); self.saveCardInfoBarDelegate->expiration_date_month());
self.modalViewController.expirationYear = base::SysUTF16ToNSString( self.modalViewController.expirationYear = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->expiration_date_year()); self.saveCardInfoBarDelegate->expiration_date_year());
self.modalViewController.currentCardSaved = !self.infobarAccepted;
return YES; return YES;
} }
...@@ -196,4 +190,14 @@ ...@@ -196,4 +190,14 @@
return tableView.contentSize.height + navigationBarHeight; return tableView.contentSize.height + navigationBarHeight;
} }
#pragma mark - InfobarSaveCardModalDelegate
- (void)saveCardWithCardholderName:(NSString*)cardholderName
expirationMonth:(NSString*)month
expirationYear:(NSString*)year {
// TODO(crbug.com/1014652): Once editing is supported send these parameters to
// the Delegate for saving.
[self modalInfobarButtonWasAccepted:self];
}
@end @end
...@@ -11,6 +11,7 @@ source_set("modals") { ...@@ -11,6 +11,7 @@ source_set("modals") {
"infobar_password_modal_delegate.h", "infobar_password_modal_delegate.h",
"infobar_password_table_view_controller.h", "infobar_password_table_view_controller.h",
"infobar_password_table_view_controller.mm", "infobar_password_table_view_controller.mm",
"infobar_save_card_modal_delegate.h",
"infobar_save_card_table_view_controller.h", "infobar_save_card_table_view_controller.h",
"infobar_save_card_table_view_controller.mm", "infobar_save_card_table_view_controller.mm",
"infobar_translate_modal_delegate.h", "infobar_translate_modal_delegate.h",
......
// Copyright 2019 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_INFOBARS_MODALS_INFOBAR_SAVE_CARD_MODAL_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_SAVE_CARD_MODAL_DELEGATE_H_
#import <Foundation/Foundation.h>
#import "ios/chrome/browser/ui/infobars/modals/infobar_modal_delegate.h"
// Delegate to handle Save Card Infobar Modal actions.
@protocol InfobarSaveCardModalDelegate <InfobarModalDelegate>
// Saves the current card with using |cardholderName| as cardholder name,
// |month| as expiration month and |year| as expiration year.
- (void)saveCardWithCardholderName:(NSString*)cardholderName
expirationMonth:(NSString*)month
expirationYear:(NSString*)year;
@end
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_SAVE_CARD_MODAL_DELEGATE_H_
...@@ -7,14 +7,14 @@ ...@@ -7,14 +7,14 @@
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h" #import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
@protocol InfobarModalDelegate; @protocol InfobarSaveCardModalDelegate;
// InfobarSaveCardTableViewController represents the content for the Save Card // InfobarSaveCardTableViewController represents the content for the Save Card
// InfobarModal. // InfobarModal.
@interface InfobarSaveCardTableViewController : ChromeTableViewController @interface InfobarSaveCardTableViewController : ChromeTableViewController
- (instancetype)initWithModalDelegate:(id<InfobarModalDelegate>)modalDelegate - (instancetype)initWithModalDelegate:
NS_DESIGNATED_INITIALIZER; (id<InfobarSaveCardModalDelegate>)modalDelegate NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style - (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle: appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle (ChromeTableViewControllerStyle)appBarStyle
...@@ -35,6 +35,9 @@ ...@@ -35,6 +35,9 @@
// Card Expiration Year to be displayed. // Card Expiration Year to be displayed.
@property(nonatomic, copy) NSString* expirationYear; @property(nonatomic, copy) NSString* expirationYear;
// YES if the Card being displayed has been saved.
@property(nonatomic, assign) BOOL currentCardSaved;
@end @end
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_SAVE_CARD_TABLE_VIEW_CONTROLLER_H_ #endif // IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_SAVE_CARD_TABLE_VIEW_CONTROLLER_H_
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
#include "base/metrics/user_metrics_action.h" #include "base/metrics/user_metrics_action.h"
#include "ios/chrome/browser/infobars/infobar_metrics_recorder.h" #include "ios/chrome/browser/infobars/infobar_metrics_recorder.h"
#import "ios/chrome/browser/ui/infobars/modals/infobar_modal_constants.h" #import "ios/chrome/browser/ui/infobars/modals/infobar_modal_constants.h"
#import "ios/chrome/browser/ui/infobars/modals/infobar_modal_delegate.h" #import "ios/chrome/browser/ui/infobars/modals/infobar_save_card_modal_delegate.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_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/cells/table_view_text_edit_item.h"
...@@ -36,8 +36,9 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -36,8 +36,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
@interface InfobarSaveCardTableViewController () <UITextFieldDelegate> @interface InfobarSaveCardTableViewController () <UITextFieldDelegate>
// InfobarModalDelegate for this ViewController. // InfobarSaveCardModalDelegate for this ViewController.
@property(nonatomic, strong) id<InfobarModalDelegate> infobarModalDelegate; @property(nonatomic, strong) id<InfobarSaveCardModalDelegate>
saveCardModalDelegate;
// Used to build and record metrics. // Used to build and record metrics.
@property(nonatomic, strong) InfobarMetricsRecorder* metricsRecorder; @property(nonatomic, strong) InfobarMetricsRecorder* metricsRecorder;
...@@ -45,11 +46,12 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -45,11 +46,12 @@ typedef NS_ENUM(NSInteger, ItemType) {
@implementation InfobarSaveCardTableViewController @implementation InfobarSaveCardTableViewController
- (instancetype)initWithModalDelegate:(id<InfobarModalDelegate>)modalDelegate { - (instancetype)initWithModalDelegate:
(id<InfobarSaveCardModalDelegate>)modalDelegate {
self = [super initWithTableViewStyle:UITableViewStylePlain self = [super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleNoAppBar]; appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) { if (self) {
_infobarModalDelegate = modalDelegate; _saveCardModalDelegate = modalDelegate;
_metricsRecorder = [[InfobarMetricsRecorder alloc] _metricsRecorder = [[InfobarMetricsRecorder alloc]
initWithType:InfobarType::kInfobarTypeSaveCard]; initWithType:InfobarType::kInfobarTypeSaveCard];
} }
...@@ -84,7 +86,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -84,7 +86,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
} }
- (void)viewDidDisappear:(BOOL)animated { - (void)viewDidDisappear:(BOOL)animated {
[self.infobarModalDelegate modalInfobarWasDismissed:self]; [self.saveCardModalDelegate modalInfobarWasDismissed:self];
[self.metricsRecorder recordModalEvent:MobileMessagesModalEvent::Dismissed]; [self.metricsRecorder recordModalEvent:MobileMessagesModalEvent::Dismissed];
[super viewDidDisappear:animated]; [super viewDidDisappear:animated];
} }
...@@ -151,7 +153,7 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -151,7 +153,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
saveCardButtonItem.text = @"TOS Agreement"; saveCardButtonItem.text = @"TOS Agreement";
saveCardButtonItem.buttonText = saveCardButtonItem.buttonText =
l10n_util::GetNSString(IDS_IOS_AUTOFILL_SAVE_CARD); l10n_util::GetNSString(IDS_IOS_AUTOFILL_SAVE_CARD);
saveCardButtonItem.enabled = YES; saveCardButtonItem.enabled = self.currentCardSaved;
saveCardButtonItem.disableButtonIntrinsicWidth = YES; saveCardButtonItem.disableButtonIntrinsicWidth = YES;
[model addItem:saveCardButtonItem [model addItem:saveCardButtonItem
toSectionWithIdentifier:SectionIdentifierContent]; toSectionWithIdentifier:SectionIdentifierContent];
...@@ -249,7 +251,13 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -249,7 +251,13 @@ typedef NS_ENUM(NSInteger, ItemType) {
} }
- (void)saveCardButtonWasPressed:(UIButton*)sender { - (void)saveCardButtonWasPressed:(UIButton*)sender {
// TODO(crbug.com/1014652): Implement and record metrics. base::RecordAction(
base::UserMetricsAction("MobileMessagesModalAcceptedTapped"));
[self.metricsRecorder recordModalEvent:MobileMessagesModalEvent::Accepted];
// TODO(crbug.com/1014652): Use current item values once editing is supported.
[self.saveCardModalDelegate saveCardWithCardholderName:self.cardholderName
expirationMonth:self.expirationMonth
expirationYear:self.expirationYear];
} }
- (void)nameEditDidBegin { - (void)nameEditDidBegin {
...@@ -271,9 +279,9 @@ typedef NS_ENUM(NSInteger, ItemType) { ...@@ -271,9 +279,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
base::RecordAction( base::RecordAction(
base::UserMetricsAction("MobileMessagesModalCancelledTapped")); base::UserMetricsAction("MobileMessagesModalCancelledTapped"));
[self.metricsRecorder recordModalEvent:MobileMessagesModalEvent::Canceled]; [self.metricsRecorder recordModalEvent:MobileMessagesModalEvent::Canceled];
[self.infobarModalDelegate dismissInfobarModal:sender [self.saveCardModalDelegate dismissInfobarModal:sender
animated:YES animated:YES
completion:nil]; completion:nil];
} }
#pragma mark - Helpers #pragma mark - Helpers
......
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