| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/ui/settings/native_apps_collection_view_controller.h
" | 5 #import "ios/chrome/browser/ui/settings/native_apps_collection_view_controller.h
" |
| 6 #import "ios/chrome/browser/ui/settings/native_apps_collection_view_controller_p
rivate.h" | 6 #import "ios/chrome/browser/ui/settings/native_apps_collection_view_controller_p
rivate.h" |
| 7 | 7 |
| 8 #import <StoreKit/StoreKit.h> | 8 #import <StoreKit/StoreKit.h> |
| 9 | 9 |
| 10 #import "base/ios/weak_nsobject.h" | 10 #import "base/ios/weak_nsobject.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #import "base/mac/foundation_util.h" | 12 #import "base/mac/foundation_util.h" |
| 13 #import "base/mac/scoped_nsobject.h" | 13 #import "base/mac/scoped_nsobject.h" |
| 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
| 15 #include "base/metrics/user_metrics.h" | 16 #include "base/metrics/user_metrics.h" |
| 16 #include "base/metrics/user_metrics_action.h" | 17 #include "base/metrics/user_metrics_action.h" |
| 17 #include "base/strings/sys_string_conversions.h" | 18 #include "base/strings/sys_string_conversions.h" |
| 19 #include "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" |
| 18 #import "ios/chrome/browser/installation_notifier.h" | 20 #import "ios/chrome/browser/installation_notifier.h" |
| 19 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 21 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 20 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" | 22 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
| 21 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 23 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 22 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" | 24 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
| 23 #import "ios/chrome/browser/ui/settings/cells/native_app_item.h" | 25 #import "ios/chrome/browser/ui/settings/cells/native_app_item.h" |
| 24 #import "ios/chrome/browser/ui/settings/settings_utils.h" | 26 #import "ios/chrome/browser/ui/settings/settings_utils.h" |
| 25 #import "ios/chrome/common/string_util.h" | 27 #import "ios/chrome/common/string_util.h" |
| 26 #include "ios/chrome/grit/ios_strings.h" | 28 #include "ios/chrome/grit/ios_strings.h" |
| 27 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" | 29 #import "ios/public/provider/chrome/browser/chrome_browser_provider.h" |
| 28 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad
ata.h" | 30 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_metad
ata.h" |
| 29 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white
list_manager.h" | 31 #import "ios/public/provider/chrome/browser/native_app_launcher/native_app_white
list_manager.h" |
| 30 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" | 32 #import "ios/third_party/material_components_ios/src/components/Buttons/src/Mate
rialButtons.h" |
| 31 #include "net/url_request/url_request_context_getter.h" | 33 #include "ios/web/public/web_thread.h" |
| 32 #include "ui/base/l10n/l10n_util.h" | 34 #include "ui/base/l10n/l10n_util.h" |
| 33 #include "url/gurl.h" | 35 #include "url/gurl.h" |
| 34 | 36 |
| 35 const NSInteger kTagShift = 1000; | 37 const NSInteger kTagShift = 1000; |
| 36 | 38 |
| 37 namespace { | 39 namespace { |
| 38 | 40 |
| 39 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 41 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 40 SectionIdentifierLearnMore = kSectionIdentifierEnumZero, | 42 SectionIdentifierLearnMore = kSectionIdentifierEnumZero, |
| 41 SectionIdentifierApps, | 43 SectionIdentifierApps, |
| 42 }; | 44 }; |
| 43 | 45 |
| 44 typedef NS_ENUM(NSInteger, ItemType) { | 46 typedef NS_ENUM(NSInteger, ItemType) { |
| 45 ItemTypeApp = kItemTypeEnumZero, | 47 ItemTypeApp = kItemTypeEnumZero, |
| 46 ItemTypeLearnMore, | 48 ItemTypeLearnMore, |
| 47 }; | 49 }; |
| 48 | 50 |
| 49 } // namespace | 51 } // namespace |
| 50 | 52 |
| 51 @interface NativeAppsCollectionViewController ()< | 53 @interface NativeAppsCollectionViewController ()< |
| 52 SKStoreProductViewControllerDelegate> { | 54 SKStoreProductViewControllerDelegate> { |
| 53 net::URLRequestContextGetter* _requestContextGetter; // weak | 55 std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> _imageFetcher; |
| 54 base::scoped_nsobject<NSArray> _nativeAppsInSettings; | 56 base::scoped_nsobject<NSArray> _nativeAppsInSettings; |
| 55 BOOL _userDidSomething; | 57 BOOL _userDidSomething; |
| 56 } | 58 } |
| 57 | 59 |
| 58 // List of the native apps visible in Settings. | 60 // List of the native apps visible in Settings. |
| 59 @property(nonatomic, copy) NSArray* appsInSettings; | 61 @property(nonatomic, copy) NSArray* appsInSettings; |
| 60 | 62 |
| 61 // Delegate for App-Store-related operations. | 63 // Delegate for App-Store-related operations. |
| 62 @property(nonatomic, assign) id<StoreKitLauncher> storeKitLauncher; | 64 @property(nonatomic, assign) id<StoreKitLauncher> storeKitLauncher; |
| 63 | 65 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 93 @end | 95 @end |
| 94 | 96 |
| 95 @implementation NativeAppsCollectionViewController | 97 @implementation NativeAppsCollectionViewController |
| 96 | 98 |
| 97 @synthesize storeKitLauncher = _storeKitLauncher; | 99 @synthesize storeKitLauncher = _storeKitLauncher; |
| 98 | 100 |
| 99 - (id)initWithURLRequestContextGetter: | 101 - (id)initWithURLRequestContextGetter: |
| 100 (net::URLRequestContextGetter*)requestContextGetter { | 102 (net::URLRequestContextGetter*)requestContextGetter { |
| 101 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 103 self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |
| 102 if (self) { | 104 if (self) { |
| 103 _requestContextGetter = requestContextGetter; | 105 _imageFetcher = base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>( |
| 106 requestContextGetter, web::WebThread::GetBlockingPool()); |
| 104 base::RecordAction(base::UserMetricsAction("MobileGALOpenSettings")); | 107 base::RecordAction(base::UserMetricsAction("MobileGALOpenSettings")); |
| 105 _storeKitLauncher = self; | 108 _storeKitLauncher = self; |
| 106 | 109 |
| 107 [self loadModel]; | 110 [self loadModel]; |
| 108 } | 111 } |
| 109 return self; | 112 return self; |
| 110 } | 113 } |
| 111 | 114 |
| 112 #pragma mark - View lifecycle | 115 #pragma mark - View lifecycle |
| 113 | 116 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 [appCell.installButton addTarget:self | 206 [appCell.installButton addTarget:self |
| 204 action:@selector(installApp:) | 207 action:@selector(installApp:) |
| 205 forControlEvents:UIControlEventTouchUpInside]; | 208 forControlEvents:UIControlEventTouchUpInside]; |
| 206 CollectionViewItem* item = | 209 CollectionViewItem* item = |
| 207 [self.collectionViewModel itemAtIndexPath:indexPath]; | 210 [self.collectionViewModel itemAtIndexPath:indexPath]; |
| 208 NativeAppItem* appItem = base::mac::ObjCCastStrict<NativeAppItem>(item); | 211 NativeAppItem* appItem = base::mac::ObjCCastStrict<NativeAppItem>(item); |
| 209 if (!appItem.icon) { | 212 if (!appItem.icon) { |
| 210 // Fetch the real icon. | 213 // Fetch the real icon. |
| 211 base::WeakNSObject<NativeAppsCollectionViewController> weakSelf(self); | 214 base::WeakNSObject<NativeAppsCollectionViewController> weakSelf(self); |
| 212 id<NativeAppMetadata> metadata = [self nativeAppAtIndex:indexPath.item]; | 215 id<NativeAppMetadata> metadata = [self nativeAppAtIndex:indexPath.item]; |
| 213 [metadata | 216 [metadata fetchSmallIconWithImageFetcher:_imageFetcher.get() |
| 214 fetchSmallIconWithContext:_requestContextGetter | 217 completionBlock:^(UIImage* image) { |
| 215 completionBlock:^(UIImage* image) { | 218 base::scoped_nsobject< |
| 216 base::scoped_nsobject<NativeAppsCollectionViewController> | 219 NativeAppsCollectionViewController> |
| 217 strongSelf([weakSelf retain]); | 220 strongSelf([weakSelf retain]); |
| 218 if (!image || !strongSelf) | 221 if (!image || !strongSelf) |
| 219 return; | 222 return; |
| 220 appItem.icon = image; | 223 appItem.icon = image; |
| 221 [strongSelf.get().collectionView | 224 [strongSelf.get().collectionView |
| 222 reloadItemsAtIndexPaths:@[ indexPath ]]; | 225 reloadItemsAtIndexPaths:@[ indexPath ]]; |
| 223 }]; | 226 }]; |
| 224 } | 227 } |
| 225 } | 228 } |
| 226 | 229 |
| 227 - (CollectionViewItem*)learnMoreItem { | 230 - (CollectionViewItem*)learnMoreItem { |
| 228 NSString* learnMoreText = | 231 NSString* learnMoreText = |
| 229 l10n_util::GetNSString(IDS_IOS_GOOGLE_APPS_SM_SECTION_HEADER); | 232 l10n_util::GetNSString(IDS_IOS_GOOGLE_APPS_SM_SECTION_HEADER); |
| 230 CollectionViewFooterItem* learnMoreItem = [[[CollectionViewFooterItem alloc] | 233 CollectionViewFooterItem* learnMoreItem = [[[CollectionViewFooterItem alloc] |
| 231 initWithType:ItemTypeLearnMore] autorelease]; | 234 initWithType:ItemTypeLearnMore] autorelease]; |
| 232 learnMoreItem.text = learnMoreText; | 235 learnMoreItem.text = learnMoreText; |
| 233 return learnMoreItem; | 236 return learnMoreItem; |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 394 |
| 392 - (NSIndexPath*)indexPathForTag:(NSInteger)shiftedTag { | 395 - (NSIndexPath*)indexPathForTag:(NSInteger)shiftedTag { |
| 393 NSInteger unshiftedTag = shiftedTag - kTagShift; | 396 NSInteger unshiftedTag = shiftedTag - kTagShift; |
| 394 return [NSIndexPath | 397 return [NSIndexPath |
| 395 indexPathForItem:unshiftedTag | 398 indexPathForItem:unshiftedTag |
| 396 inSection:[self.collectionViewModel | 399 inSection:[self.collectionViewModel |
| 397 sectionForSectionIdentifier:SectionIdentifierApps]]; | 400 sectionForSectionIdentifier:SectionIdentifierApps]]; |
| 398 } | 401 } |
| 399 | 402 |
| 400 @end | 403 @end |
| OLD | NEW |