| 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/bandwidth_management_collection_view_con
troller.h" | 5 #import "ios/chrome/browser/ui/settings/bandwidth_management_collection_view_con
troller.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #import "base/mac/scoped_nsobject.h" | |
| 9 #include "components/prefs/pref_change_registrar.h" | 8 #include "components/prefs/pref_change_registrar.h" |
| 10 #include "components/prefs/pref_service.h" | 9 #include "components/prefs/pref_service.h" |
| 11 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 10 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 12 #include "ios/chrome/browser/pref_names.h" | 11 #include "ios/chrome/browser/pref_names.h" |
| 13 #import "ios/chrome/browser/prefs/pref_observer_bridge.h" | 12 #import "ios/chrome/browser/prefs/pref_observer_bridge.h" |
| 14 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" | 13 #import "ios/chrome/browser/ui/collection_view/cells/MDCCollectionViewCell+Chrom
e.h" |
| 15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" | 14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_detail_item
.h" |
| 16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" | 15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_footer_item
.h" |
| 17 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
| 18 #import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controlle
r.h" | 17 #import "ios/chrome/browser/ui/settings/dataplan_usage_collection_view_controlle
r.h" |
| 19 #import "ios/chrome/browser/ui/settings/settings_utils.h" | 18 #import "ios/chrome/browser/ui/settings/settings_utils.h" |
| 20 #include "ios/chrome/grit/ios_chromium_strings.h" | 19 #include "ios/chrome/grit/ios_chromium_strings.h" |
| 21 #include "ios/chrome/grit/ios_strings.h" | 20 #include "ios/chrome/grit/ios_strings.h" |
| 22 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" | 21 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
| 23 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 22 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/l10n/l10n_util_mac.h" | 24 #include "ui/base/l10n/l10n_util_mac.h" |
| 26 #include "url/gurl.h" | 25 #include "url/gurl.h" |
| 27 | 26 |
| 27 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 28 #error "This file requires ARC support." |
| 29 #endif |
| 30 |
| 28 namespace { | 31 namespace { |
| 29 | 32 |
| 30 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 33 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
| 31 SectionIdentifierActions = kSectionIdentifierEnumZero, | 34 SectionIdentifierActions = kSectionIdentifierEnumZero, |
| 32 SectionIdentifierFooter, | 35 SectionIdentifierFooter, |
| 33 }; | 36 }; |
| 34 | 37 |
| 35 typedef NS_ENUM(NSInteger, ItemType) { | 38 typedef NS_ENUM(NSInteger, ItemType) { |
| 36 ItemTypePreload = kItemTypeEnumZero, | 39 ItemTypePreload = kItemTypeEnumZero, |
| 37 ItemTypeFooter, | 40 ItemTypeFooter, |
| 38 }; | 41 }; |
| 39 | 42 |
| 40 } // namespace | 43 } // namespace |
| 41 | 44 |
| 42 @interface BandwidthManagementCollectionViewController ()< | 45 @interface BandwidthManagementCollectionViewController ()< |
| 43 PrefObserverDelegate> { | 46 PrefObserverDelegate> { |
| 44 ios::ChromeBrowserState* _browserState; // weak | 47 ios::ChromeBrowserState* _browserState; // weak |
| 45 | 48 |
| 46 // Pref observer to track changes to prefs. | 49 // Pref observer to track changes to prefs. |
| 47 std::unique_ptr<PrefObserverBridge> _prefObserverBridge; | 50 std::unique_ptr<PrefObserverBridge> _prefObserverBridge; |
| 48 // Registrar for pref changes notifications. | 51 // Registrar for pref changes notifications. |
| 49 PrefChangeRegistrar _prefChangeRegistrarApplicationContext; | 52 PrefChangeRegistrar _prefChangeRegistrarApplicationContext; |
| 50 | 53 |
| 51 // Updatable Items | 54 // Updatable Items |
| 52 base::scoped_nsobject<CollectionViewDetailItem> _preloadWebpagesDetailItem; | 55 CollectionViewDetailItem* _preloadWebpagesDetailItem; |
| 53 } | 56 } |
| 54 | 57 |
| 55 // Helpers to create collection view items. | 58 // Helpers to create collection view items. |
| 56 - (CollectionViewItem*)preloadWebpagesItem; | 59 - (CollectionViewItem*)preloadWebpagesItem; |
| 57 - (CollectionViewItem*)footerItem; | 60 - (CollectionViewItem*)footerItem; |
| 58 @end | 61 @end |
| 59 | 62 |
| 60 @implementation BandwidthManagementCollectionViewController | 63 @implementation BandwidthManagementCollectionViewController |
| 61 | 64 |
| 62 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { | 65 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 [model addSectionWithIdentifier:SectionIdentifierFooter]; | 98 [model addSectionWithIdentifier:SectionIdentifierFooter]; |
| 96 [model addItem:[self footerItem] | 99 [model addItem:[self footerItem] |
| 97 toSectionWithIdentifier:SectionIdentifierFooter]; | 100 toSectionWithIdentifier:SectionIdentifierFooter]; |
| 98 } | 101 } |
| 99 | 102 |
| 100 - (CollectionViewItem*)preloadWebpagesItem { | 103 - (CollectionViewItem*)preloadWebpagesItem { |
| 101 NSString* detailText = [DataplanUsageCollectionViewController | 104 NSString* detailText = [DataplanUsageCollectionViewController |
| 102 currentLabelForPreference:_browserState->GetPrefs() | 105 currentLabelForPreference:_browserState->GetPrefs() |
| 103 basePref:prefs::kNetworkPredictionEnabled | 106 basePref:prefs::kNetworkPredictionEnabled |
| 104 wifiPref:prefs::kNetworkPredictionWifiOnly]; | 107 wifiPref:prefs::kNetworkPredictionWifiOnly]; |
| 105 _preloadWebpagesDetailItem.reset( | 108 _preloadWebpagesDetailItem = |
| 106 [[CollectionViewDetailItem alloc] initWithType:ItemTypePreload]); | 109 [[CollectionViewDetailItem alloc] initWithType:ItemTypePreload]; |
| 107 | 110 |
| 108 _preloadWebpagesDetailItem.get().text = | 111 _preloadWebpagesDetailItem.text = |
| 109 l10n_util::GetNSString(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES); | 112 l10n_util::GetNSString(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES); |
| 110 _preloadWebpagesDetailItem.get().detailText = detailText; | 113 _preloadWebpagesDetailItem.detailText = detailText; |
| 111 _preloadWebpagesDetailItem.get().accessoryType = | 114 _preloadWebpagesDetailItem.accessoryType = |
| 112 MDCCollectionViewCellAccessoryDisclosureIndicator; | 115 MDCCollectionViewCellAccessoryDisclosureIndicator; |
| 113 _preloadWebpagesDetailItem.get().accessibilityTraits |= | 116 _preloadWebpagesDetailItem.accessibilityTraits |= UIAccessibilityTraitButton; |
| 114 UIAccessibilityTraitButton; | |
| 115 return _preloadWebpagesDetailItem; | 117 return _preloadWebpagesDetailItem; |
| 116 } | 118 } |
| 117 | 119 |
| 118 - (CollectionViewItem*)footerItem { | 120 - (CollectionViewItem*)footerItem { |
| 119 CollectionViewFooterItem* item = [[[CollectionViewFooterItem alloc] | 121 CollectionViewFooterItem* item = |
| 120 initWithType:ItemTypeFooter] autorelease]; | 122 [[CollectionViewFooterItem alloc] initWithType:ItemTypeFooter]; |
| 121 | 123 |
| 122 item.text = l10n_util::GetNSString( | 124 item.text = l10n_util::GetNSString( |
| 123 IDS_IOS_BANDWIDTH_MANAGEMENT_DESCRIPTION_LEARN_MORE); | 125 IDS_IOS_BANDWIDTH_MANAGEMENT_DESCRIPTION_LEARN_MORE); |
| 124 item.linkURL = | 126 item.linkURL = |
| 125 GURL(l10n_util::GetStringUTF8(IDS_IOS_BANDWIDTH_MANAGEMENT_LEARN_URL)); | 127 GURL(l10n_util::GetStringUTF8(IDS_IOS_BANDWIDTH_MANAGEMENT_LEARN_URL)); |
| 126 item.linkDelegate = self; | 128 item.linkDelegate = self; |
| 127 item.accessibilityTraits |= UIAccessibilityTraitButton; | 129 item.accessibilityTraits |= UIAccessibilityTraitButton; |
| 128 return item; | 130 return item; |
| 129 } | 131 } |
| 130 | 132 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 141 } | 143 } |
| 142 | 144 |
| 143 - (void)collectionView:(UICollectionView*)collectionView | 145 - (void)collectionView:(UICollectionView*)collectionView |
| 144 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 146 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |
| 145 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 147 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |
| 146 | 148 |
| 147 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; | 149 NSInteger type = [self.collectionViewModel itemTypeForIndexPath:indexPath]; |
| 148 if (type == ItemTypePreload) { | 150 if (type == ItemTypePreload) { |
| 149 NSString* preloadTitle = | 151 NSString* preloadTitle = |
| 150 l10n_util::GetNSString(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES); | 152 l10n_util::GetNSString(IDS_IOS_OPTIONS_PRELOAD_WEBPAGES); |
| 151 base::scoped_nsobject<UIViewController> controller( | 153 UIViewController* controller = |
| 152 [[DataplanUsageCollectionViewController alloc] | 154 [[DataplanUsageCollectionViewController alloc] |
| 153 initWithPrefs:_browserState->GetPrefs() | 155 initWithPrefs:_browserState->GetPrefs() |
| 154 basePref:prefs::kNetworkPredictionEnabled | 156 basePref:prefs::kNetworkPredictionEnabled |
| 155 wifiPref:prefs::kNetworkPredictionWifiOnly | 157 wifiPref:prefs::kNetworkPredictionWifiOnly |
| 156 title:preloadTitle]); | 158 title:preloadTitle]; |
| 157 [self.navigationController pushViewController:controller animated:YES]; | 159 [self.navigationController pushViewController:controller animated:YES]; |
| 158 } | 160 } |
| 159 } | 161 } |
| 160 | 162 |
| 161 #pragma mark - MDCCollectionViewStylingDelegate | 163 #pragma mark - MDCCollectionViewStylingDelegate |
| 162 | 164 |
| 163 - (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView | 165 - (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView |
| 164 cellStyleForSection:(NSInteger)section { | 166 cellStyleForSection:(NSInteger)section { |
| 165 NSInteger sectionIdentifier = | 167 NSInteger sectionIdentifier = |
| 166 [self.collectionViewModel sectionIdentifierForSection:section]; | 168 [self.collectionViewModel sectionIdentifierForSection:section]; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 #pragma mark - PrefObserverDelegate | 205 #pragma mark - PrefObserverDelegate |
| 204 | 206 |
| 205 - (void)onPreferenceChanged:(const std::string&)preferenceName { | 207 - (void)onPreferenceChanged:(const std::string&)preferenceName { |
| 206 if (preferenceName == prefs::kNetworkPredictionEnabled || | 208 if (preferenceName == prefs::kNetworkPredictionEnabled || |
| 207 preferenceName == prefs::kNetworkPredictionWifiOnly) { | 209 preferenceName == prefs::kNetworkPredictionWifiOnly) { |
| 208 NSString* detailText = [DataplanUsageCollectionViewController | 210 NSString* detailText = [DataplanUsageCollectionViewController |
| 209 currentLabelForPreference:_browserState->GetPrefs() | 211 currentLabelForPreference:_browserState->GetPrefs() |
| 210 basePref:prefs::kNetworkPredictionEnabled | 212 basePref:prefs::kNetworkPredictionEnabled |
| 211 wifiPref:prefs::kNetworkPredictionWifiOnly]; | 213 wifiPref:prefs::kNetworkPredictionWifiOnly]; |
| 212 | 214 |
| 213 _preloadWebpagesDetailItem.get().detailText = detailText; | 215 _preloadWebpagesDetailItem.detailText = detailText; |
| 214 | 216 |
| 215 [self reconfigureCellsForItems:@[ _preloadWebpagesDetailItem ] | 217 [self reconfigureCellsForItems:@[ _preloadWebpagesDetailItem ] |
| 216 inSectionWithIdentifier:SectionIdentifierActions]; | 218 inSectionWithIdentifier:SectionIdentifierActions]; |
| 217 } | 219 } |
| 218 } | 220 } |
| 219 | 221 |
| 220 @end | 222 @end |
| OLD | NEW |