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 @@
#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/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/util/uikit_ui_util.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -21,7 +22,8 @@
#error "This file requires ARC support."
#endif
@interface InfobarSaveCardCoordinator () <InfobarCoordinatorImplementation>
@interface InfobarSaveCardCoordinator () <InfobarCoordinatorImplementation,
InfobarSaveCardModalDelegate>
// InfobarBannerViewController owned by this Coordinator.
@property(nonatomic, strong) InfobarBannerViewController* bannerViewController;
......@@ -62,9 +64,14 @@
initWithDelegate:self
presentsModal:self.hasBadge
type:InfobarType::kInfobarTypeSaveCard];
self.bannerViewController.buttonText =
base::SysUTF16ToNSString(self.saveCardInfoBarDelegate->GetButtonLabel(
ConfirmInfoBarDelegate::BUTTON_OK));
if (self.saveCardInfoBarDelegate->upload()) {
// TODO(crbug.com/1014652): Use real string once its been created.
self.bannerViewController.buttonText = @"Save...";
} else {
self.bannerViewController.buttonText =
base::SysUTF16ToNSString(self.saveCardInfoBarDelegate->GetButtonLabel(
ConfirmInfoBarDelegate::BUTTON_OK));
}
self.bannerViewController.titleText = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->GetMessageText());
self.bannerViewController.subTitleText =
......@@ -94,29 +101,15 @@
}
- (void)performInfobarAction {
if (self.saveCardInfoBarDelegate->upload()) {
// TODO(crbug.com/1014652): Open Modal if CreditCard details will be
// uploaded. Meaning that the ToS needs to be displayed.
} else if (self.saveCardInfoBarDelegate->Accept()) {
self.infobarAccepted = YES;
// 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];
}];
}
// Display the modal (thus the ToS) if the card will be uploaded, this is a
// legal requirement and shouldn't be changed.
if (!self.modalViewController && self.saveCardInfoBarDelegate->upload()) {
[self presentInfobarModalFromBanner];
return;
}
// Ignore the Accept() return value since it always returns YES.
self.saveCardInfoBarDelegate->Accept();
self.infobarAccepted = YES;
}
- (void)infobarWasDismissed {
......@@ -170,6 +163,7 @@
self.saveCardInfoBarDelegate->expiration_date_month());
self.modalViewController.expirationYear = base::SysUTF16ToNSString(
self.saveCardInfoBarDelegate->expiration_date_year());
self.modalViewController.currentCardSaved = !self.infobarAccepted;
return YES;
}
......@@ -196,4 +190,14 @@
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
......@@ -11,6 +11,7 @@ source_set("modals") {
"infobar_password_modal_delegate.h",
"infobar_password_table_view_controller.h",
"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.mm",
"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 @@
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
@protocol InfobarModalDelegate;
@protocol InfobarSaveCardModalDelegate;
// InfobarSaveCardTableViewController represents the content for the Save Card
// InfobarModal.
@interface InfobarSaveCardTableViewController : ChromeTableViewController
- (instancetype)initWithModalDelegate:(id<InfobarModalDelegate>)modalDelegate
NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithModalDelegate:
(id<InfobarSaveCardModalDelegate>)modalDelegate NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithTableViewStyle:(UITableViewStyle)style
appBarStyle:
(ChromeTableViewControllerStyle)appBarStyle
......@@ -35,6 +35,9 @@
// Card Expiration Year to be displayed.
@property(nonatomic, copy) NSString* expirationYear;
// YES if the Card being displayed has been saved.
@property(nonatomic, assign) BOOL currentCardSaved;
@end
#endif // IOS_CHROME_BROWSER_UI_INFOBARS_MODALS_INFOBAR_SAVE_CARD_TABLE_VIEW_CONTROLLER_H_
......@@ -9,7 +9,7 @@
#include "base/metrics/user_metrics_action.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_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_text_button_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) {
@interface InfobarSaveCardTableViewController () <UITextFieldDelegate>
// InfobarModalDelegate for this ViewController.
@property(nonatomic, strong) id<InfobarModalDelegate> infobarModalDelegate;
// InfobarSaveCardModalDelegate for this ViewController.
@property(nonatomic, strong) id<InfobarSaveCardModalDelegate>
saveCardModalDelegate;
// Used to build and record metrics.
@property(nonatomic, strong) InfobarMetricsRecorder* metricsRecorder;
......@@ -45,11 +46,12 @@ typedef NS_ENUM(NSInteger, ItemType) {
@implementation InfobarSaveCardTableViewController
- (instancetype)initWithModalDelegate:(id<InfobarModalDelegate>)modalDelegate {
- (instancetype)initWithModalDelegate:
(id<InfobarSaveCardModalDelegate>)modalDelegate {
self = [super initWithTableViewStyle:UITableViewStylePlain
appBarStyle:ChromeTableViewControllerStyleNoAppBar];
if (self) {
_infobarModalDelegate = modalDelegate;
_saveCardModalDelegate = modalDelegate;
_metricsRecorder = [[InfobarMetricsRecorder alloc]
initWithType:InfobarType::kInfobarTypeSaveCard];
}
......@@ -84,7 +86,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
}
- (void)viewDidDisappear:(BOOL)animated {
[self.infobarModalDelegate modalInfobarWasDismissed:self];
[self.saveCardModalDelegate modalInfobarWasDismissed:self];
[self.metricsRecorder recordModalEvent:MobileMessagesModalEvent::Dismissed];
[super viewDidDisappear:animated];
}
......@@ -151,7 +153,7 @@ typedef NS_ENUM(NSInteger, ItemType) {
saveCardButtonItem.text = @"TOS Agreement";
saveCardButtonItem.buttonText =
l10n_util::GetNSString(IDS_IOS_AUTOFILL_SAVE_CARD);
saveCardButtonItem.enabled = YES;
saveCardButtonItem.enabled = self.currentCardSaved;
saveCardButtonItem.disableButtonIntrinsicWidth = YES;
[model addItem:saveCardButtonItem
toSectionWithIdentifier:SectionIdentifierContent];
......@@ -249,7 +251,13 @@ typedef NS_ENUM(NSInteger, ItemType) {
}
- (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 {
......@@ -271,9 +279,9 @@ typedef NS_ENUM(NSInteger, ItemType) {
base::RecordAction(
base::UserMetricsAction("MobileMessagesModalCancelledTapped"));
[self.metricsRecorder recordModalEvent:MobileMessagesModalEvent::Canceled];
[self.infobarModalDelegate dismissInfobarModal:sender
animated:YES
completion:nil];
[self.saveCardModalDelegate dismissInfobarModal:sender
animated:YES
completion:nil];
}
#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