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

Unified Diff: ios/chrome/browser/ui/settings/compose_email_handler_collection_view_controller.mm

Issue 2870783002: Adds Compose Email Settings UI for deprecating Native App Launcher (Closed)
Patch Set: fixed comment Created 3 years, 7 months 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/compose_email_handler_collection_view_controller.mm
diff --git a/ios/chrome/browser/ui/settings/compose_email_handler_collection_view_controller.mm b/ios/chrome/browser/ui/settings/compose_email_handler_collection_view_controller.mm
new file mode 100644
index 0000000000000000000000000000000000000000..8a8cc5ae080aa55ce33f5c59c05452c26037abba
--- /dev/null
+++ b/ios/chrome/browser/ui/settings/compose_email_handler_collection_view_controller.mm
@@ -0,0 +1,121 @@
+// Copyright 2017 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/compose_email_handler_collection_view_controller.h"
+
+#include "base/mac/foundation_util.h"
+#import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h"
+#import "ios/chrome/browser/web/mailto_handler.h"
+#import "ios/chrome/browser/web/mailto_url_rewriter.h"
+#include "ios/chrome/grit/ios_strings.h"
+#include "ui/base/l10n/l10n_util.h"
+#include "ui/base/l10n/l10n_util_mac.h"
+
+#if !defined(__has_feature) || !__has_feature(objc_arc)
+#error "This file requires ARC support."
+#endif
+
+namespace {
+
+typedef NS_ENUM(NSInteger, SectionIdentifier) {
+ SectionIdentifierMailtoHandlers = kSectionIdentifierEnumZero,
+};
+
+typedef NS_ENUM(NSInteger, ItemType) {
+ ItemTypeMailtoHandlers = kItemTypeEnumZero,
+};
+
+} // namespace
+
+@interface ComposeEmailHandlerCollectionViewController () {
+ MailtoURLRewriter* _rewriter;
+}
+@end
+
+@implementation ComposeEmailHandlerCollectionViewController
+
+- (instancetype)initWithRewriter:(MailtoURLRewriter*)rewriter {
+ self = [super initWithStyle:CollectionViewControllerStyleAppBar];
+ if (self) {
+ self.title = l10n_util::GetNSString(IDS_IOS_COMPOSE_EMAIL_SETTING);
+ self.collectionViewAccessibilityIdentifier =
+ @"compose_email_handler_view_controller";
+ _rewriter = rewriter;
+ [self loadModel];
+ }
+ return self;
+}
+
+- (instancetype)initWithStyle:(CollectionViewControllerStyle)style {
rohitrao (ping after 24h) 2017/05/12 01:57:57 This implementation should not be necessary if you
pkl (ping after 24h if needed) 2017/05/12 18:01:19 Done.
+ NOTREACHED();
+ return nil;
+}
+
+- (void)loadModel {
+ [super loadModel];
+ CollectionViewModel* model = self.collectionViewModel;
+ [model addSectionWithIdentifier:SectionIdentifierMailtoHandlers];
+
+ // Since this is a one-of-several selection UI, there must be more than one
+ // choice available to the user. If this UI is being presented when there is
+ // only one choice, it is considered a software error.
rohitrao (ping after 24h) 2017/05/12 01:57:57 Why not always allow this UI to be shown, even if
pkl (ping after 24h if needed) 2017/05/12 18:01:19 I've started a comment thread on the design doc. I
+ NSArray<MailtoHandler*>* handlers = [_rewriter defaultHandlers];
+ DCHECK([handlers count] > 1);
+ NSString* currentHandlerID = [_rewriter defaultHandlerID];
+ for (MailtoHandler* handler in handlers) {
+ CollectionViewTextItem* item =
+ [[CollectionViewTextItem alloc] initWithType:ItemTypeMailtoHandlers];
+ [item setText:[handler appName]];
+ [item setAccessibilityTraits:UIAccessibilityTraitButton];
+ if ([currentHandlerID isEqualToString:[handler appStoreID]])
+ [item setAccessoryType:MDCCollectionViewCellAccessoryCheckmark];
+ [model addItem:item
+ toSectionWithIdentifier:SectionIdentifierMailtoHandlers];
+ }
+}
+
+#pragma mark UICollectionViewDelegate
+
+- (void)collectionView:(UICollectionView*)collectionView
+ didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
+ [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
+ CollectionViewModel* model = self.collectionViewModel;
+
+ // Only handle taps on Mailto Handler items.
+ CollectionViewTextItem* selectedItem =
+ base::mac::ObjCCastStrict<CollectionViewTextItem>(
rohitrao (ping after 24h) 2017/05/12 01:57:57 ObjCCastStrict will DCHECK if the item is of a dif
pkl (ping after 24h if needed) 2017/05/12 18:01:20 Using "strict" is right.
+ [model itemAtIndexPath:indexPath]);
+ if (selectedItem.type != ItemTypeMailtoHandlers)
rohitrao (ping after 24h) 2017/05/12 01:57:57 Do we display any rows that are not this type? Co
pkl (ping after 24h if needed) 2017/05/12 18:01:19 Since the items are created in loadModel, the chec
+ return;
+
+ // Do nothing if the tapped row was already chosen as the default.
+ if (selectedItem.accessoryType == MDCCollectionViewCellAccessoryCheckmark)
+ return;
+
+ // Iterate through the rows and remove the checkmark from any that has it.
+ NSMutableArray* modifiedItems = [NSMutableArray array];
+ for (CollectionViewTextItem* item in
rohitrao (ping after 24h) 2017/05/12 01:57:57 Are we somehow silently casting to CollectionViewT
pkl (ping after 24h if needed) 2017/05/12 18:01:19 Switched to use ObjCCastStrict<>.
+ [model itemsInSectionWithIdentifier:SectionIdentifierMailtoHandlers]) {
+ if (item.type != ItemTypeMailtoHandlers)
rohitrao (ping after 24h) 2017/05/12 01:57:57 Same question -- could this be a DCHECK, or do we
pkl (ping after 24h if needed) 2017/05/12 18:01:19 ...and made this a DCHECK_EQ
+ continue;
+ if (item == selectedItem) {
+ // Shows the checkmark on the new default mailto: URL handler.
+ item.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
+ [modifiedItems addObject:item];
+ } else if (item.accessoryType == MDCCollectionViewCellAccessoryCheckmark) {
+ // Unchecks any currently checked selection.
+ item.accessoryType = MDCCollectionViewCellAccessoryNone;
+ [modifiedItems addObject:item];
+ }
+ }
+
+ NSUInteger handlerIndex = [model indexInItemTypeForIndexPath:indexPath];
+ MailtoHandler* handler =
+ [[_rewriter defaultHandlers] objectAtIndex:handlerIndex];
+ [_rewriter setDefaultHandlerID:[handler appStoreID]];
+
+ [self reconfigureCellsForItems:modifiedItems];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698