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

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

Issue 2710493006: [ObjC ARC] Converts ios/chrome/browser/payments:payments to ARC. (Closed)
Patch Set: fixes compilation by reintroducing formal declaration of designated initializer 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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_address_selection_view_controller. h" 5 #import "ios/chrome/browser/payments/shipping_address_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/mac/scoped_nsobject.h"
10 #include "base/strings/sys_string_conversions.h" 8 #include "base/strings/sys_string_conversions.h"
11 #include "components/autofill/core/browser/autofill_profile.h" 9 #include "components/autofill/core/browser/autofill_profile.h"
12 #include "components/strings/grit/components_strings.h" 10 #include "components/strings/grit/components_strings.h"
13 #include "ios/chrome/browser/application_context.h" 11 #include "ios/chrome/browser/application_context.h"
14 #import "ios/chrome/browser/payments/cells/payments_text_item.h" 12 #import "ios/chrome/browser/payments/cells/payments_text_item.h"
15 #import "ios/chrome/browser/payments/cells/shipping_address_item.h" 13 #import "ios/chrome/browser/payments/cells/shipping_address_item.h"
16 #import "ios/chrome/browser/payments/payment_request_util.h" 14 #import "ios/chrome/browser/payments/payment_request_util.h"
17 #import "ios/chrome/browser/ui/autofill/cells/status_item.h" 15 #import "ios/chrome/browser/ui/autofill/cells/status_item.h"
18 #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"
19 #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"
20 #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 "
21 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" 19 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
22 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 20 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
23 #import "ios/chrome/browser/ui/icons/chrome_icon.h" 21 #import "ios/chrome/browser/ui/icons/chrome_icon.h"
24 #include "ios/chrome/browser/ui/uikit_ui_util.h" 22 #include "ios/chrome/browser/ui/uikit_ui_util.h"
25 #include "ios/chrome/grit/ios_strings.h" 23 #include "ios/chrome/grit/ios_strings.h"
26 #include "ios/chrome/grit/ios_theme_resources.h" 24 #include "ios/chrome/grit/ios_theme_resources.h"
27 #include "ui/base/l10n/l10n_util.h" 25 #include "ui/base/l10n/l10n_util.h"
28 26
27 #if !defined(__has_feature) || !__has_feature(objc_arc)
28 #error "This file requires ARC support."
29 #endif
30
29 using payment_request_util::NameLabelFromAutofillProfile; 31 using payment_request_util::NameLabelFromAutofillProfile;
30 using payment_request_util::AddressLabelFromAutofillProfile; 32 using payment_request_util::AddressLabelFromAutofillProfile;
31 using payment_request_util::PhoneNumberLabelFromAutofillProfile; 33 using payment_request_util::PhoneNumberLabelFromAutofillProfile;
32 34
33 NSString* const kShippingAddressSelectionCollectionViewId = 35 NSString* const kShippingAddressSelectionCollectionViewId =
34 @"kShippingAddressSelectionCollectionViewId"; 36 @"kShippingAddressSelectionCollectionViewId";
35 37
36 namespace { 38 namespace {
37 39
38 const CGFloat kSeparatorEdgeInset = 14; 40 const CGFloat kSeparatorEdgeInset = 14;
39 41
40 typedef NS_ENUM(NSInteger, SectionIdentifier) { 42 typedef NS_ENUM(NSInteger, SectionIdentifier) {
41 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero, 43 SectionIdentifierShippingAddress = kSectionIdentifierEnumZero,
42 }; 44 };
43 45
44 typedef NS_ENUM(NSInteger, ItemType) { 46 typedef NS_ENUM(NSInteger, ItemType) {
45 ItemTypeSpinner = kItemTypeEnumZero, 47 ItemTypeSpinner = kItemTypeEnumZero,
46 ItemTypeMessage, 48 ItemTypeMessage,
47 ItemTypeShippingAddress, // This is a repeated item type. 49 ItemTypeShippingAddress, // This is a repeated item type.
48 ItemTypeAddShippingAddress, 50 ItemTypeAddShippingAddress,
49 }; 51 };
50 52
51 } // namespace 53 } // namespace
52 54
53 @interface ShippingAddressSelectionViewController () { 55 @interface ShippingAddressSelectionViewController () {
54 base::WeakNSProtocol<id<ShippingAddressSelectionViewControllerDelegate>>
55 _delegate;
56
57 // The PaymentRequest object owning an instance of web::PaymentRequest as 56 // The PaymentRequest object owning an instance of web::PaymentRequest as
58 // provided by the page invoking the Payment Request API. This is a weak 57 // provided by the page invoking the Payment Request API. This is a weak
59 // pointer and should outlive this class. 58 // pointer and should outlive this class.
60 PaymentRequest* _paymentRequest; 59 PaymentRequest* _paymentRequest;
61 60
62 // The currently selected item. May be nil. 61 // The currently selected item. May be nil.
63 ShippingAddressItem* _selectedItem; 62 __weak ShippingAddressItem* _selectedItem;
64 } 63 }
65 64
66 // Called when the user presses the return button. 65 // Called when the user presses the return button.
67 - (void)onReturn; 66 - (void)onReturn;
68 67
69 @end 68 @end
70 69
71 @implementation ShippingAddressSelectionViewController 70 @implementation ShippingAddressSelectionViewController
72 71
73 @synthesize isLoading = _isLoading; 72 @synthesize isLoading = _isLoading;
74 @synthesize errorMessage = _errorMessage; 73 @synthesize errorMessage = _errorMessage;
74 @synthesize delegate = _delegate;
75 75
76 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest { 76 - (instancetype)initWithPaymentRequest:(PaymentRequest*)paymentRequest {
77 DCHECK(paymentRequest); 77 DCHECK(paymentRequest);
78 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) { 78 if ((self = [super initWithStyle:CollectionViewControllerStyleAppBar])) {
79 self.title = l10n_util::GetNSString( 79 self.title = l10n_util::GetNSString(
80 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_TITLE); 80 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_TITLE);
81 81
82 UIBarButtonItem* returnButton = 82 UIBarButtonItem* returnButton =
83 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon] 83 [ChromeIcon templateBarButtonItemWithImage:[ChromeIcon backIcon]
84 target:nil 84 target:nil
85 action:@selector(onReturn)]; 85 action:@selector(onReturn)];
86 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK); 86 returnButton.accessibilityLabel = l10n_util::GetNSString(IDS_ACCNAME_BACK);
87 self.navigationItem.leftBarButtonItem = returnButton; 87 self.navigationItem.leftBarButtonItem = returnButton;
88 88
89 _paymentRequest = paymentRequest; 89 _paymentRequest = paymentRequest;
90 } 90 }
91 return self; 91 return self;
92 } 92 }
93 93
94 - (id<ShippingAddressSelectionViewControllerDelegate>)delegate {
95 return _delegate.get();
96 }
97
98 - (void)setDelegate:
99 (id<ShippingAddressSelectionViewControllerDelegate>)delegate {
100 _delegate.reset(delegate);
101 }
102
103 - (void)onReturn { 94 - (void)onReturn {
104 [_delegate shippingAddressSelectionViewControllerDidReturn:self]; 95 [_delegate shippingAddressSelectionViewControllerDidReturn:self];
105 } 96 }
106 97
107 #pragma mark - CollectionViewController methods 98 #pragma mark - CollectionViewController methods
108 99
109 - (void)loadModel { 100 - (void)loadModel {
110 [super loadModel]; 101 [super loadModel];
111 CollectionViewModel* model = self.collectionViewModel; 102 CollectionViewModel* model = self.collectionViewModel;
112 _selectedItem = nil; 103 _selectedItem = nil;
113 104
114 [model addSectionWithIdentifier:SectionIdentifierShippingAddress]; 105 [model addSectionWithIdentifier:SectionIdentifierShippingAddress];
115 106
116 if (_isLoading) { 107 if (_isLoading) {
117 StatusItem* statusItem = 108 StatusItem* statusItem = [[StatusItem alloc] initWithType:ItemTypeSpinner];
118 [[[StatusItem alloc] initWithType:ItemTypeSpinner] autorelease];
119 statusItem.text = 109 statusItem.text =
120 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_CHECKING_LABEL); 110 l10n_util::GetNSString(IDS_IOS_PAYMENT_REQUEST_CHECKING_LABEL);
121 [model addItem:statusItem 111 [model addItem:statusItem
122 toSectionWithIdentifier:SectionIdentifierShippingAddress]; 112 toSectionWithIdentifier:SectionIdentifierShippingAddress];
123 return; 113 return;
124 } 114 }
125 115
126 PaymentsTextItem* messageItem = 116 PaymentsTextItem* messageItem =
127 [[[PaymentsTextItem alloc] initWithType:ItemTypeMessage] autorelease]; 117 [[PaymentsTextItem alloc] initWithType:ItemTypeMessage];
128 if (_errorMessage) { 118 if (_errorMessage) {
129 messageItem.text = _errorMessage; 119 messageItem.text = _errorMessage;
130 messageItem.image = NativeImage(IDR_IOS_PAYMENTS_WARNING); 120 messageItem.image = NativeImage(IDR_IOS_PAYMENTS_WARNING);
131 } else { 121 } else {
132 messageItem.text = l10n_util::GetNSString( 122 messageItem.text = l10n_util::GetNSString(
133 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_MESSAGE); 123 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_MESSAGE);
134 } 124 }
135 [model addItem:messageItem 125 [model addItem:messageItem
136 toSectionWithIdentifier:SectionIdentifierShippingAddress]; 126 toSectionWithIdentifier:SectionIdentifierShippingAddress];
137 127
138 for (const auto& shippingAddress : _paymentRequest->shipping_profiles()) { 128 for (const auto& shippingAddress : _paymentRequest->shipping_profiles()) {
139 ShippingAddressItem* item = [[[ShippingAddressItem alloc] 129 ShippingAddressItem* item =
140 initWithType:ItemTypeShippingAddress] autorelease]; 130 [[ShippingAddressItem alloc] initWithType:ItemTypeShippingAddress];
141 item.accessibilityTraits |= UIAccessibilityTraitButton; 131 item.accessibilityTraits |= UIAccessibilityTraitButton;
142 item.name = NameLabelFromAutofillProfile(shippingAddress); 132 item.name = NameLabelFromAutofillProfile(shippingAddress);
143 item.address = AddressLabelFromAutofillProfile(shippingAddress); 133 item.address = AddressLabelFromAutofillProfile(shippingAddress);
144 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(shippingAddress); 134 item.phoneNumber = PhoneNumberLabelFromAutofillProfile(shippingAddress);
145 if (_paymentRequest->selected_shipping_profile() == shippingAddress) { 135 if (_paymentRequest->selected_shipping_profile() == shippingAddress) {
146 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark; 136 item.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
147 _selectedItem = item; 137 _selectedItem = item;
148 } 138 }
149 [model addItem:item 139 [model addItem:item
150 toSectionWithIdentifier:SectionIdentifierShippingAddress]; 140 toSectionWithIdentifier:SectionIdentifierShippingAddress];
151 } 141 }
152 142
153 PaymentsTextItem* addShippingAddress = [[[PaymentsTextItem alloc] 143 PaymentsTextItem* addShippingAddress =
154 initWithType:ItemTypeAddShippingAddress] autorelease]; 144 [[PaymentsTextItem alloc] initWithType:ItemTypeAddShippingAddress];
155 addShippingAddress.text = l10n_util::GetNSString( 145 addShippingAddress.text = l10n_util::GetNSString(
156 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_ADD_BUTTON); 146 IDS_IOS_PAYMENT_REQUEST_SHIPPING_ADDRESS_SELECTION_ADD_BUTTON);
157 addShippingAddress.image = NativeImage(IDR_IOS_PAYMENTS_ADD); 147 addShippingAddress.image = NativeImage(IDR_IOS_PAYMENTS_ADD);
158 addShippingAddress.accessibilityTraits |= UIAccessibilityTraitButton; 148 addShippingAddress.accessibilityTraits |= UIAccessibilityTraitButton;
159 [model addItem:addShippingAddress 149 [model addItem:addShippingAddress
160 toSectionWithIdentifier:SectionIdentifierShippingAddress]; 150 toSectionWithIdentifier:SectionIdentifierShippingAddress];
161 } 151 }
162 152
163 - (void)viewDidLoad { 153 - (void)viewDidLoad {
164 [super viewDidLoad]; 154 [super viewDidLoad];
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath { 253 hidesInkViewAtIndexPath:(NSIndexPath*)indexPath {
264 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; 254 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath];
265 if (type == ItemTypeMessage) { 255 if (type == ItemTypeMessage) {
266 return YES; 256 return YES;
267 } else { 257 } else {
268 return NO; 258 return NO;
269 } 259 }
270 } 260 }
271 261
272 @end 262 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698