Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: ios/chrome/browser/payments/shipping_option_selection_view_controller.mm

Issue 2710493006: [ObjC ARC] Converts ios/chrome/browser/payments:payments to ARC. (Closed)
Patch Set: rebase? Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ios/chrome/browser/payments/shipping_option_selection_view_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import "ios/chrome/browser/payments/shipping_option_selection_view_controller.h " 5 #import "ios/chrome/browser/payments/shipping_option_selection_view_controller.h "
6 6
7 #import "base/ios/weak_nsobject.h"
8 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
9 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
10 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
11 #include "components/payments/currency_formatter.h" 10 #include "components/payments/currency_formatter.h"
12 #include "components/strings/grit/components_strings.h" 11 #include "components/strings/grit/components_strings.h"
13 #import "ios/chrome/browser/payments/cells/payments_text_item.h" 12 #import "ios/chrome/browser/payments/cells/payments_text_item.h"
14 #include "ios/chrome/browser/payments/payment_request.h" 13 #include "ios/chrome/browser/payments/payment_request.h"
15 #import "ios/chrome/browser/payments/payment_request_util.h" 14 #import "ios/chrome/browser/payments/payment_request_util.h"
16 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" 15 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
17 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h" 16 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom e.h"
18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h" 17 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
19 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 18 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
20 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
21 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 20 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
22 #import "ios/chrome/browser/ui/icons/chrome_icon.h" 21 #import "ios/chrome/browser/ui/icons/chrome_icon.h"
23 #include "ios/chrome/browser/ui/uikit_ui_util.h" 22 #include "ios/chrome/browser/ui/uikit_ui_util.h"
24 #include "ios/chrome/grit/ios_strings.h" 23 #include "ios/chrome/grit/ios_strings.h"
25 #include "ios/chrome/grit/ios_theme_resources.h" 24 #include "ios/chrome/grit/ios_theme_resources.h"
26 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 25 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
27 #include "ui/base/l10n/l10n_util.h" 26 #include "ui/base/l10n/l10n_util.h"
28 27
28 #if !defined(__has_feature) || !__has_feature(objc_arc)
29 #error "This file requires ARC support."
30 #endif
31
29 NSString* const kShippingOptionSelectionCollectionViewId = 32 NSString* const kShippingOptionSelectionCollectionViewId =
30 @"kShippingOptionSelectionCollectionViewId"; 33 @"kShippingOptionSelectionCollectionViewId";
31 34
32 namespace { 35 namespace {
33 36
34 const CGFloat kSeparatorEdgeInset = 14; 37 const CGFloat kSeparatorEdgeInset = 14;
35 38
36 typedef NS_ENUM(NSInteger, SectionIdentifier) { 39 typedef NS_ENUM(NSInteger, SectionIdentifier) {
37 SectionIdentifierShippingOption = kSectionIdentifierEnumZero, 40 SectionIdentifierShippingOption = kSectionIdentifierEnumZero,
38 }; 41 };
39 42
40 typedef NS_ENUM(NSInteger, ItemType) { 43 typedef NS_ENUM(NSInteger, ItemType) {
41 ItemTypeSpinner = kItemTypeEnumZero, 44 ItemTypeSpinner = kItemTypeEnumZero,
42 ItemTypeMessage, 45 ItemTypeMessage,
43 ItemTypeShippingOption, // This is a repeated item type. 46 ItemTypeShippingOption, // This is a repeated item type.
44 }; 47 };
45 48
46 } // namespace 49 } // namespace
47 50
48 @interface ShippingOptionSelectionViewController () { 51 @interface ShippingOptionSelectionViewController () {
49 base::WeakNSProtocol<id<ShippingOptionSelectionViewControllerDelegate>> 52 __weak id<ShippingOptionSelectionViewControllerDelegate> _delegate;
50 _delegate;
51 53
52 // The PaymentRequest object owning an instance of web::PaymentRequest as 54 // The PaymentRequest object owning an instance of web::PaymentRequest as
53 // provided by the page invoking the Payment Request API. This is a weak 55 // provided by the page invoking the Payment Request API. This is a weak
54 // pointer and should outlive this class. 56 // pointer and should outlive this class.
55 PaymentRequest* _paymentRequest; 57 PaymentRequest* _paymentRequest;
56 58
57 // The currently selected item. May be nil. 59 // The currently selected item. May be nil.
58 CollectionViewTextItem* _selectedItem; 60 CollectionViewTextItem* _selectedItem;
59 } 61 }
60 62
(...skipping 19 matching lines...) Expand all
80 action:@selector(onReturn)]; 82 action:@selector(onReturn)];
81 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); 83 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK);
82 self.navigationItem.leftBarButtonItem = returnButton; 84 self.navigationItem.leftBarButtonItem = returnButton;
83 85
84 _paymentRequest = paymentRequest; 86 _paymentRequest = paymentRequest;
85 } 87 }
86 return self; 88 return self;
87 } 89 }
88 90
89 - (id<ShippingOptionSelectionViewControllerDelegate>)delegate { 91 - (id<ShippingOptionSelectionViewControllerDelegate>)delegate {
90 return _delegate.get(); 92 return _delegate;
91 } 93 }
92 94
93 - (void)setDelegate: 95 - (void)setDelegate:
94 (id<ShippingOptionSelectionViewControllerDelegate>)delegate { 96 (id<ShippingOptionSelectionViewControllerDelegate>)delegate {
95 _delegate.reset(delegate); 97 _delegate = delegate;
96 } 98 }
97 99
98 - (void)onReturn { 100 - (void)onReturn {
99 [_delegate shippingOptionSelectionViewControllerDidReturn:self]; 101 [_delegate shippingOptionSelectionViewControllerDidReturn:self];
100 } 102 }
101 103
102 #pragma mark - CollectionViewController methods 104 #pragma mark - CollectionViewController methods
103 105
104 - (void)loadModel { 106 - (void)loadModel {
105 [super loadModel]; 107 [super loadModel];
106 CollectionViewModel* model = self.collectionViewModel; 108 CollectionViewModel* model = self.collectionViewModel;
107 _selectedItem = nil; 109 _selectedItem = nil;
108 110
109 [model addSectionWithIdentifier:SectionIdentifierShippingOption]; 111 [model addSectionWithIdentifier:SectionIdentifierShippingOption];
110 112
111 if (self.isLoading) { 113 if (self.isLoading) {
112 StatusItem* statusItem = 114 StatusItem* statusItem = [[StatusItem alloc] initWithType:ItemTypeSpinner];
113 [[[StatusItem alloc] initWithType:ItemTypeSpinner] autorelease];
114 statusItem.text = 115 statusItem.text =
115 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_CHECKING_LABEL); 116 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_CHECKING_LABEL);
116 [model addItem:statusItem 117 [model addItem:statusItem
117 toSectionWithIdentifier:SectionIdentifierShippingOption]; 118 toSectionWithIdentifier:SectionIdentifierShippingOption];
118 return; 119 return;
119 } 120 }
120 121
121 if (_errorMessage) { 122 if (_errorMessage) {
122 PaymentsTextItem* messageItem = 123 PaymentsTextItem* messageItem =
123 [[[PaymentsTextItem alloc] initWithType:ItemTypeMessage] autorelease]; 124 [[PaymentsTextItem alloc] initWithType:ItemTypeMessage];
124 messageItem.text = _errorMessage; 125 messageItem.text = _errorMessage;
125 messageItem.image = NativeImage(IDR_IOS_PAYMENTS_WARNING); 126 messageItem.image = NativeImage(IDR_IOS_PAYMENTS_WARNING);
126 [model addItem:messageItem 127 [model addItem:messageItem
127 toSectionWithIdentifier:SectionIdentifierShippingOption]; 128 toSectionWithIdentifier:SectionIdentifierShippingOption];
128 } 129 }
129 130
130 for (const auto& shippingOption : _paymentRequest->shipping_options()) { 131 for (const auto& shippingOption : _paymentRequest->shipping_options()) {
131 CollectionViewTextItem* item = [[[CollectionViewTextItem alloc] 132 CollectionViewTextItem* item =
132 initWithType:ItemTypeShippingOption] autorelease]; 133 [[CollectionViewTextItem alloc] initWithType:ItemTypeShippingOption];
133 item.text = base::SysUTF16ToNSString(shippingOption->label); 134 item.text = base::SysUTF16ToNSString(shippingOption->label);
134 payments::CurrencyFormatter* currencyFormatter = 135 payments::CurrencyFormatter* currencyFormatter =
135 _paymentRequest->GetOrCreateCurrencyFormatter(); 136 _paymentRequest->GetOrCreateCurrencyFormatter();
136 item.detailText = SysUTF16ToNSString(currencyFormatter->Format( 137 item.detailText = SysUTF16ToNSString(currencyFormatter->Format(
137 base::UTF16ToASCII(shippingOption->amount.value))); 138 base::UTF16ToASCII(shippingOption->amount.value)));
138 139
139 // Styling. 140 // Styling.
140 item.textFont = [MDCTypography body2Font]; 141 item.textFont = [MDCTypography body2Font];
141 item.textColor = [[MDCPalette greyPalette] tint900]; 142 item.textColor = [[MDCPalette greyPalette] tint900];
142 item.detailTextFont = [MDCTypography body1Font]; 143 item.detailTextFont = [MDCTypography body1Font];
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 247 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
247 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 248 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
248 if (type == ItemTypeMessage) { 249 if (type == ItemTypeMessage) {
249 return YES; 250 return YES;
250 } else { 251 } else {
251 return NO; 252 return NO;
252 } 253 }
253 } 254 }
254 255
255 @end 256 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/payments/shipping_option_selection_view_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698