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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/settings/about_chrome_collection_view_controller.mm
diff --git a/ios/chrome/browser/ui/settings/about_chrome_collection_view_controller.mm b/ios/chrome/browser/ui/settings/about_chrome_collection_view_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..178ee0c3bfec39ddffc5123466473a6f686c22b5
--- /dev/null
+++ b/ios/chrome/browser/ui/settings/about_chrome_collection_view_controller.mm
@@ -0,0 +1,185 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/ui/settings/about_chrome_collection_view_controller.h"
+
+#include "base/ios/block_types.h"
+#include "base/logging.h"
+#import "base/mac/foundation_util.h"
+#include "base/mac/scoped_nsobject.h"
+#include "base/strings/sys_string_conversions.h"
+#include "base/strings/utf_string_conversions.h"
+#include "components/version_info/version_info.h"
+#include "ios/chrome/browser/chrome_url_constants.h"
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
+#import "ios/chrome/browser/ui/collection_view/collection_view_model.h"
+#import "ios/chrome/browser/ui/settings/cells/version_item.h"
+#import "ios/chrome/browser/ui/settings/settings_utils.h"
+#include "ios/chrome/common/channel_info.h"
+#include "ios/chrome/grit/ios_chromium_strings.h"
+#include "ios/chrome/grit/ios_strings.h"
+#import "ios/third_party/material_components_ios/src/components/CollectionCells/src/MaterialCollectionCells.h"
+#import "ios/third_party/material_components_ios/src/components/Snackbar/src/MaterialSnackbar.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/l10n/l10n_util_mac.h"
+#include "url/gurl.h"
+
+namespace {
+
+typedef NS_ENUM(NSInteger, SectionIdentifier) {
+ SectionIdentifierLinks = kSectionIdentifierEnumZero,
+ SectionIdentifierFooter,
+};
+
+typedef NS_ENUM(NSInteger, ItemType) {
+ ItemTypeLinksCredits = kItemTypeEnumZero,
+ ItemTypeLinksTerms,
+ ItemTypeLinksPrivacy,
+ ItemTypeVersion,
+};
+
+} // namespace
+
+@implementation AboutChromeCollectionViewController
+
+#pragma mark Initialization
+
+- (instancetype)init {
+ self = [super initWithStyle:CollectionViewControllerStyleAppBar];
+ if (self) {
+ self.title = l10n_util::GetNSString(IDS_IOS_ABOUT_PRODUCT_NAME);
+ [self loadModel];
+ }
+ return self;
+}
+
+#pragma mark SettingsRootCollectionViewController
+
+- (void)loadModel {
+ [super loadModel];
+ CollectionViewModel* model = self.collectionViewModel;
+
+ [model addSectionWithIdentifier:SectionIdentifierLinks];
+
+ base::scoped_nsobject<CollectionViewTextItem> credits(
+ [[CollectionViewTextItem alloc] initWithType:ItemTypeLinksCredits]);
+ credits.get().text = l10n_util::GetNSString(IDS_IOS_OPEN_SOURCE_LICENSES);
+ credits.get().accessoryType =
+ MDCCollectionViewCellAccessoryDisclosureIndicator;
+ credits.get().accessibilityTraits = UIAccessibilityTraitButton;
+ [model addItem:credits toSectionWithIdentifier:SectionIdentifierLinks];
+
+ base::scoped_nsobject<CollectionViewTextItem> terms(
+ [[CollectionViewTextItem alloc] initWithType:ItemTypeLinksTerms]);
+ terms.get().text = l10n_util::GetNSString(IDS_IOS_TERMS_OF_SERVICE);
+ terms.get().accessoryType = MDCCollectionViewCellAccessoryDisclosureIndicator;
+ terms.get().accessibilityTraits = UIAccessibilityTraitButton;
+ [model addItem:terms toSectionWithIdentifier:SectionIdentifierLinks];
+
+ base::scoped_nsobject<CollectionViewTextItem> privacy(
+ [[CollectionViewTextItem alloc] initWithType:ItemTypeLinksPrivacy]);
+ privacy.get().text = l10n_util::GetNSString(IDS_IOS_PRIVACY_POLICY);
+ privacy.get().accessoryType =
+ MDCCollectionViewCellAccessoryDisclosureIndicator;
+ privacy.get().accessibilityTraits = UIAccessibilityTraitButton;
+ [model addItem:privacy toSectionWithIdentifier:SectionIdentifierLinks];
+
+ [model addSectionWithIdentifier:SectionIdentifierFooter];
+
+ base::scoped_nsobject<VersionItem> version(
+ [[VersionItem alloc] initWithType:ItemTypeVersion]);
+ version.get().text = [self versionDescriptionString];
+ version.get().accessibilityTraits = UIAccessibilityTraitButton;
+ [model addItem:version toSectionWithIdentifier:SectionIdentifierFooter];
+}
+
+#pragma mark UICollectionViewDelegate
+
+- (void)collectionView:(UICollectionView*)collectionView
+ didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
+ [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
+ NSInteger itemType =
+ [self.collectionViewModel itemTypeForIndexPath:indexPath];
+ switch (itemType) {
+ case ItemTypeLinksCredits:
+ [self openURL:GURL(kChromeUICreditsURL)];
+ break;
+ case ItemTypeLinksTerms:
+ [self openURL:GURL(kChromeUITermsURL)];
+ break;
+ case ItemTypeLinksPrivacy:
+ [self openURL:GURL(l10n_util::GetStringUTF8(IDS_IOS_PRIVACY_POLICY_URL))];
+ break;
+ case ItemTypeVersion:
+ [self copyVersionToPasteboard];
+ break;
+ default:
+ NOTREACHED();
+ break;
+ }
+}
+
+#pragma mark MDCCollectionViewStylingDelegate
+
+// MDCCollectionViewStylingDelegate protocol is implemented so that the version
+// cell has an invisible background.
+- (MDCCollectionViewCellStyle)collectionView:(UICollectionView*)collectionView
+ cellStyleForSection:(NSInteger)section {
+ NSInteger sectionIdentifier =
+ [self.collectionViewModel sectionIdentifierForSection:section];
+ switch (sectionIdentifier) {
+ case SectionIdentifierFooter:
+ return MDCCollectionViewCellStyleDefault;
+ default:
+ return self.styler.cellStyle;
+ }
+}
+
+- (BOOL)collectionView:(UICollectionView*)collectionView
+ shouldHideItemBackgroundAtIndexPath:(NSIndexPath*)indexPath {
+ NSInteger sectionIdentifier =
+ [self.collectionViewModel sectionIdentifierForSection:indexPath.section];
+ switch (sectionIdentifier) {
+ case SectionIdentifierFooter:
+ return YES;
+ default:
+ return NO;
+ }
+}
+
+#pragma mark Private methods
+
+- (void)openURL:(GURL)URL {
+ ios_internal_settings::BlockToOpenURL(self)(URL);
+}
+
+- (void)copyVersionToPasteboard {
+ [[UIPasteboard generalPasteboard] setString:[self versionOnlyString]];
+ NSString* messageText = l10n_util::GetNSString(IDS_IOS_VERSION_COPIED);
+ MDCSnackbarMessage* message =
+ [MDCSnackbarMessage messageWithText:messageText];
+ message.category = @"version copied";
+ [MDCSnackbarManager showMessage:message];
+}
+
+- (std::string)versionString {
+ std::string versionString = version_info::GetVersionNumber();
+ std::string versionStringModifier = GetChannelString();
+ if (!versionStringModifier.empty()) {
+ versionString = versionString + " " + versionStringModifier;
+ }
+ return versionString;
+}
+
+- (NSString*)versionDescriptionString {
+ return l10n_util::GetNSStringF(IDS_IOS_VERSION,
+ base::UTF8ToUTF16([self versionString]));
+}
+
+- (NSString*)versionOnlyString {
+ return base::SysUTF8ToNSString([self versionString]);
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698