| OLD | NEW | 
|    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/ui/settings/time_range_selector_collection_view_cont
     roller.h" |    5 #import "ios/chrome/browser/ui/settings/time_range_selector_collection_view_cont
     roller.h" | 
|    6  |    6  | 
|    7 #import "base/ios/weak_nsobject.h" |  | 
|    8 #import "base/mac/foundation_util.h" |    7 #import "base/mac/foundation_util.h" | 
|    9 #import "base/mac/scoped_nsobject.h" |  | 
|   10 #include "components/browsing_data/core/pref_names.h" |    8 #include "components/browsing_data/core/pref_names.h" | 
|   11 #include "components/prefs/pref_member.h" |    9 #include "components/prefs/pref_member.h" | 
|   12 #include "components/prefs/pref_service.h" |   10 #include "components/prefs/pref_service.h" | 
|   13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
     " |   11 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
     " | 
|   14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |   12 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 
|   15 #include "ios/chrome/grit/ios_strings.h" |   13 #include "ios/chrome/grit/ios_strings.h" | 
|   16 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
     src/MaterialCollectionCells.h" |   14 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
     src/MaterialCollectionCells.h" | 
|   17 #include "ui/base/l10n/l10n_util_mac.h" |   15 #include "ui/base/l10n/l10n_util_mac.h" | 
|   18  |   16  | 
 |   17 #if !defined(__has_feature) || !__has_feature(objc_arc) | 
 |   18 #error "This file requires ARC support." | 
 |   19 #endif | 
 |   20  | 
|   19 namespace { |   21 namespace { | 
|   20  |   22  | 
|   21 typedef NS_ENUM(NSInteger, SectionIdentifier) { |   23 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 
|   22   SectionIdentifierOptions = kSectionIdentifierEnumZero, |   24   SectionIdentifierOptions = kSectionIdentifierEnumZero, | 
|   23 }; |   25 }; | 
|   24  |   26  | 
|   25 typedef NS_ENUM(NSInteger, ItemType) { |   27 typedef NS_ENUM(NSInteger, ItemType) { | 
|   26   ItemTypePastHour = kItemTypeEnumZero, |   28   ItemTypePastHour = kItemTypeEnumZero, | 
|   27   ItemTypePastDay, |   29   ItemTypePastDay, | 
|   28   ItemTypePastWeek, |   30   ItemTypePastWeek, | 
| (...skipping 11 matching lines...) Expand all  Loading... | 
|   40 static_assert( |   42 static_assert( | 
|   41     arraysize(kStringIDS) == |   43     arraysize(kStringIDS) == | 
|   42         static_cast<int>(browsing_data::TimePeriod::TIME_PERIOD_LAST) + 1, |   44         static_cast<int>(browsing_data::TimePeriod::TIME_PERIOD_LAST) + 1, | 
|   43     "Strings have to match the enum values."); |   45     "Strings have to match the enum values."); | 
|   44  |   46  | 
|   45 }  // namespace |   47 }  // namespace | 
|   46  |   48  | 
|   47 @interface TimeRangeSelectorCollectionViewController () { |   49 @interface TimeRangeSelectorCollectionViewController () { | 
|   48   // Instance of the parent view controller needed in order to set the time |   50   // Instance of the parent view controller needed in order to set the time | 
|   49   // range for the browsing data deletion. |   51   // range for the browsing data deletion. | 
|   50   base::WeakNSProtocol<id<TimeRangeSelectorCollectionViewControllerDelegate>> |   52   __weak id<TimeRangeSelectorCollectionViewControllerDelegate> _weakDelegate; | 
|   51       _weakDelegate; |  | 
|   52   IntegerPrefMember timeRangePref_; |   53   IntegerPrefMember timeRangePref_; | 
|   53 } |   54 } | 
|   54  |   55  | 
|   55 // Updates the checked state of the cells to match the preferences. |   56 // Updates the checked state of the cells to match the preferences. | 
|   56 - (void)updateCheckedState; |   57 - (void)updateCheckedState; | 
|   57  |   58  | 
|   58 // Updates the PrefService with the given value. |   59 // Updates the PrefService with the given value. | 
|   59 - (void)updatePrefValue:(int)prefValue; |   60 - (void)updatePrefValue:(int)prefValue; | 
|   60 @end |   61 @end | 
|   61  |   62  | 
|   62 @implementation TimeRangeSelectorCollectionViewController |   63 @implementation TimeRangeSelectorCollectionViewController | 
|   63  |   64  | 
|   64 #pragma mark Initialization |   65 #pragma mark Initialization | 
|   65  |   66  | 
|   66 - (instancetype) |   67 - (instancetype) | 
|   67 initWithPrefs:(PrefService*)prefs |   68 initWithPrefs:(PrefService*)prefs | 
|   68      delegate:(id<TimeRangeSelectorCollectionViewControllerDelegate>)delegate { |   69      delegate:(id<TimeRangeSelectorCollectionViewControllerDelegate>)delegate { | 
|   69   self = [super initWithStyle:CollectionViewControllerStyleAppBar]; |   70   self = [super initWithStyle:CollectionViewControllerStyleAppBar]; | 
|   70   if (self) { |   71   if (self) { | 
|   71     _weakDelegate.reset(delegate); |   72     _weakDelegate = delegate; | 
|   72     self.title = l10n_util::GetNSString( |   73     self.title = l10n_util::GetNSString( | 
|   73         IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_SELECTOR_TITLE); |   74         IDS_IOS_CLEAR_BROWSING_DATA_TIME_RANGE_SELECTOR_TITLE); | 
|   74     timeRangePref_.Init(browsing_data::prefs::kDeleteTimePeriod, prefs); |   75     timeRangePref_.Init(browsing_data::prefs::kDeleteTimePeriod, prefs); | 
|   75     [self loadModel]; |   76     [self loadModel]; | 
|   76     self.shouldHideDoneButton = YES; |   77     self.shouldHideDoneButton = YES; | 
|   77   } |   78   } | 
|   78   return self; |   79   return self; | 
|   79 } |   80 } | 
|   80  |   81  | 
|   81 - (void)loadModel { |   82 - (void)loadModel { | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  130 } |  131 } | 
|  131  |  132  | 
|  132 - (void)updatePrefValue:(int)prefValue { |  133 - (void)updatePrefValue:(int)prefValue { | 
|  133   timeRangePref_.SetValue(prefValue); |  134   timeRangePref_.SetValue(prefValue); | 
|  134   [self updateCheckedState]; |  135   [self updateCheckedState]; | 
|  135 } |  136 } | 
|  136  |  137  | 
|  137 - (CollectionViewTextItem*)timeRangeItemWithOption:(ItemType)itemOption |  138 - (CollectionViewTextItem*)timeRangeItemWithOption:(ItemType)itemOption | 
|  138                                      textMessageID:(int)textMessageID { |  139                                      textMessageID:(int)textMessageID { | 
|  139   CollectionViewTextItem* item = |  140   CollectionViewTextItem* item = | 
|  140       [[[CollectionViewTextItem alloc] initWithType:itemOption] autorelease]; |  141       [[CollectionViewTextItem alloc] initWithType:itemOption]; | 
|  141   [item setText:l10n_util::GetNSString(textMessageID)]; |  142   [item setText:l10n_util::GetNSString(textMessageID)]; | 
|  142   [item setAccessibilityTraits:UIAccessibilityTraitButton]; |  143   [item setAccessibilityTraits:UIAccessibilityTraitButton]; | 
|  143   return item; |  144   return item; | 
|  144 } |  145 } | 
|  145  |  146  | 
|  146 #pragma mark - UICollectionViewDelegate |  147 #pragma mark - UICollectionViewDelegate | 
|  147  |  148  | 
|  148 - (void)collectionView:(UICollectionView*)collectionView |  149 - (void)collectionView:(UICollectionView*)collectionView | 
|  149     didSelectItemAtIndexPath:(NSIndexPath*)indexPath { |  150     didSelectItemAtIndexPath:(NSIndexPath*)indexPath { | 
|  150   [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; |  151   [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
|  165 + (NSString*)timePeriodLabelForPrefs:(PrefService*)prefs { |  166 + (NSString*)timePeriodLabelForPrefs:(PrefService*)prefs { | 
|  166   if (!prefs) |  167   if (!prefs) | 
|  167     return nil; |  168     return nil; | 
|  168   int prefValue = prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); |  169   int prefValue = prefs->GetInteger(browsing_data::prefs::kDeleteTimePeriod); | 
|  169   if (prefValue < 0 || static_cast<size_t>(prefValue) >= arraysize(kStringIDS)) |  170   if (prefValue < 0 || static_cast<size_t>(prefValue) >= arraysize(kStringIDS)) | 
|  170     return nil; |  171     return nil; | 
|  171   return l10n_util::GetNSString(kStringIDS[prefValue]); |  172   return l10n_util::GetNSString(kStringIDS[prefValue]); | 
|  172 } |  173 } | 
|  173  |  174  | 
|  174 @end |  175 @end | 
| OLD | NEW |