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

Side by Side Diff: ios/chrome/browser/ui/settings/about_chrome_collection_view_controller.mm

Issue 2589583003: Upstream Chrome on iOS source code [7/11]. (Closed)
Patch Set: Created 4 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/settings/about_chrome_collection_view_controller. h"
6
7 #include "base/ios/block_types.h"
8 #include "base/logging.h"
9 #import "base/mac/foundation_util.h"
10 #include "base/mac/scoped_nsobject.h"
11 #include "base/strings/sys_string_conversions.h"
12 #include "base/strings/utf_string_conversions.h"
13 #include "components/version_info/version_info.h"
14 #include "ios/chrome/browser/chrome_url_constants.h"
15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
16 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
17 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
18 #import "ios/chrome/browser/ui/settings/cells/version_item.h"
19 #import "ios/chrome/browser/ui/settings/settings_utils.h"
20 #include "ios/chrome/common/channel_info.h"
21 #include "ios/chrome/grit/ios_chromium_strings.h"
22 #include "ios/chrome/grit/ios_strings.h"
23 #import "ios/third_party/material_components_ios/src/components/CollectionCells/ src/MaterialCollectionCells.h"
24 #import "ios/third_party/material_components_ios/src/components/Snackbar/src/Mat erialSnackbar.h"
25 #include "ui/base/l10n/l10n_util.h"
26 #include "ui/base/l10n/l10n_util_mac.h"
27 #include "url/gurl.h"
28
29 namespace {
30
31 typedef NS_ENUM(NSInteger, SectionIdentifier) {
32 SectionIdentifierLinks = kSectionIdentifierEnumZero,
33 SectionIdentifierFooter,
34 };
35
36 typedef NS_ENUM(NSInteger, ItemType) {
37 ItemTypeLinksCredits = kItemTypeEnumZero,
38 ItemTypeLinksTerms,
39 ItemTypeLinksPrivacy,
40 ItemTypeVersion,
41 };
42
43 } // namespace
44
45 @implementation AboutChromeCollectionViewController
46
47 #pragma mark Initialization
48
49 - (instancetype)init {
50 self = [super initWithStyle:CollectionViewControllerStyleAppBar];
51 if (self) {
52 self.title = l10n_util::GetNSString(IDS_IOS_ABOUT_PRODUCT_NAME);
53 [self loadModel];
54 }
55 return self;
56 }
57
58 #pragma mark SettingsRootCollectionViewController
59
60 - (void)loadModel {
61 [super loadModel];
62 CollectionViewModel* model = self.collectionViewModel;
63
64 [model addSectionWithIdentifier:SectionIdentifierLinks];
65
66 base::scoped_nsobject<CollectionViewTextItem> credits(
67 [[CollectionViewTextItem alloc] initWithType:ItemTypeLinksCredits]);
68 credits.get().text = l10n_util::GetNSString(IDS_IOS_OPEN_SOURCE_LICENSES);
69 credits.get().accessoryType =
70 MDCCollectionViewCellAccessoryDisclosureIndicator;
71 credits.get().accessibilityTraits = UIAccessibilityTraitButton;
72 [model addItem:credits toSectionWithIdentifier:SectionIdentifierLinks];
73
74 base::scoped_nsobject<CollectionViewTextItem> terms(
75 [[CollectionViewTextItem alloc] initWithType:ItemTypeLinksTerms]);
76 terms.get().text = l10n_util::GetNSString(IDS_IOS_TERMS_OF_SERVICE);
77 terms.get().accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator;
78 terms.get().accessibilityTraits = UIAccessibilityTraitButton;
79 [model addItem:terms toSectionWithIdentifier:SectionIdentifierLinks];
80
81 base::scoped_nsobject<CollectionViewTextItem> privacy(
82 [[CollectionViewTextItem alloc] initWithType:ItemTypeLinksPrivacy]);
83 privacy.get().text = l10n_util::GetNSString(IDS_IOS_PRIVACY_POLICY);
84 privacy.get().accessoryType =
85 MDCCollectionViewCellAccessoryDisclosureIndicator;
86 privacy.get().accessibilityTraits = UIAccessibilityTraitButton;
87 [model addItem:privacy toSectionWithIdentifier:SectionIdentifierLinks];
88
89 [model addSectionWithIdentifier:SectionIdentifierFooter];
90
91 base::scoped_nsobject<VersionItem> version(
92 [[VersionItem alloc] initWithType:ItemTypeVersion]);
93 version.get().text = [self versionDescriptionString];
94 version.get().accessibilityTraits = UIAccessibilityTraitButton;
95 [model addItem:version toSectionWithIdentifier:SectionIdentifierFooter];
96 }
97
98 #pragma mark UICollectionViewDelegate
99
100 - (void)collectionView:(UICollectionView*)collectionView
101 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
102 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
103 NSInteger itemType =
104 [self.collectionViewModel itemTypeForIndexPath:indexPath];
105 switch (itemType) {
106 case ItemTypeLinksCredits:
107 [self openURL:GURL(kChromeUICreditsURL)];
108 break;
109 case ItemTypeLinksTerms:
110 [self openURL:GURL(kChromeUITermsURL)];
111 break;
112 case ItemTypeLinksPrivacy:
113 [self openURL:GURL(l10n_util::GetStringUTF8(IDS_IOS_PRIVACY_POLICY_URL))];
114 break;
115 case ItemTypeVersion:
116 [self copyVersionToPasteboard];
117 break;
118 default:
119 NOTREACHED();
120 break;
121 }
122 }
123
124 #pragma mark MDCCollectionViewStylingDelegate
125
126 // MDCCollectionViewStylingDelegate protocol is implemented so that the version
127 // cell has an invisible background.
128 - (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView
129 cellStyleForSection:(NSInteger)section {
130 NSInteger sectionIdentifier =
131 [self.collectionViewModel sectionIdentifierForSection:section];
132 switch (sectionIdentifier) {
133 case SectionIdentifierFooter:
134 return MDCCollectionViewCellStyleDefault;
135 default:
136 return self.styler.cellStyle;
137 }
138 }
139
140 - (BOOL)collectionView:(UICollectionView*)collectionView
141 shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath {
142 NSInteger sectionIdentifier =
143 [self.collectionViewModel sectionIdentifierForSection:indexPath.section];
144 switch (sectionIdentifier) {
145 case SectionIdentifierFooter:
146 return YES;
147 default:
148 return NO;
149 }
150 }
151
152 #pragma mark Private methods
153
154 - (void)openURL:(GURL)URL {
155 ios_internal_settings::BlockToOpenURL(self)(URL);
156 }
157
158 - (void)copyVersionToPasteboard {
159 [[UIPasteboard generalPasteboard] setString:[self versionOnlyString]];
160 NSString* messageText = l10n_util::GetNSString(IDS_IOS_VERSION_COPIED);
161 MDCSnackbarMessage* message =
162 [MDCSnackbarMessage messageWithText:messageText];
163 message.category = @"version copied";
164 [MDCSnackbarManager showMessage:message];
165 }
166
167 - (std::string)versionString {
168 std::string versionString = version_info::GetVersionNumber();
169 std::string versionStringModifier = GetChannelString();
170 if (!versionStringModifier.empty()) {
171 versionString = versionString + " " + versionStringModifier;
172 }
173 return versionString;
174 }
175
176 - (NSString*)versionDescriptionString {
177 return l10n_util::GetNSStringF(IDS_IOS_VERSION,
178 base::UTF8ToUTF16([self versionString]));
179 }
180
181 - (NSString*)versionOnlyString {
182 return base::SysUTF8ToNSString([self versionString]);
183 }
184
185 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698