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

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

Issue 2889183005: Show all mailto: handlers, but dim unavailable ones. (Closed)
Patch Set: add deps 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/compose_email_handler_collection_view_co ntroller.h" 5 #import "ios/chrome/browser/ui/settings/compose_email_handler_collection_view_co ntroller.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h " 8 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h "
9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
rohitrao (ping after 24h) 2017/05/22 12:50:37 If all you need is greyColor, you should be able t
pkl (ping after 24h if needed) 2017/05/22 20:27:09 Thanks! Makes sense.
9 #import "ios/chrome/browser/web/mailto_handler.h" 10 #import "ios/chrome/browser/web/mailto_handler.h"
10 #import "ios/chrome/browser/web/mailto_url_rewriter.h" 11 #import "ios/chrome/browser/web/mailto_url_rewriter.h"
11 #include "ios/chrome/grit/ios_strings.h" 12 #include "ios/chrome/grit/ios_strings.h"
12 #include "ui/base/l10n/l10n_util.h" 13 #include "ui/base/l10n/l10n_util.h"
13 #include "ui/base/l10n/l10n_util_mac.h" 14 #include "ui/base/l10n/l10n_util_mac.h"
14 15
15 #if !defined(__has_feature) || !__has_feature(objc_arc) 16 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support." 17 #error "This file requires ARC support."
17 #endif 18 #endif
18 19
(...skipping 30 matching lines...) Expand all
49 50
50 - (void)loadModel { 51 - (void)loadModel {
51 [super loadModel]; 52 [super loadModel];
52 CollectionViewModel* model = self.collectionViewModel; 53 CollectionViewModel* model = self.collectionViewModel;
53 [model addSectionWithIdentifier:SectionIdentifierMailtoHandlers]; 54 [model addSectionWithIdentifier:SectionIdentifierMailtoHandlers];
54 55
55 // Since this is a one-of-several selection UI, there must be more than one 56 // Since this is a one-of-several selection UI, there must be more than one
56 // choice available to the user. If this UI is being presented when there is 57 // choice available to the user. If this UI is being presented when there is
57 // only one choice, it is considered a software error. 58 // only one choice, it is considered a software error.
58 NSArray<MailtoHandler*>* handlers = [_rewriter defaultHandlers]; 59 NSArray<MailtoHandler*>* handlers = [_rewriter defaultHandlers];
59 DCHECK([handlers count] > 1);
60 NSString* currentHandlerID = [_rewriter defaultHandlerID]; 60 NSString* currentHandlerID = [_rewriter defaultHandlerID];
61 for (MailtoHandler* handler in handlers) { 61 for (MailtoHandler* handler in handlers) {
62 CollectionViewTextItem* item = 62 CollectionViewTextItem* item =
63 [[CollectionViewTextItem alloc] initWithType:ItemTypeMailtoHandlers]; 63 [[CollectionViewTextItem alloc] initWithType:ItemTypeMailtoHandlers];
64 [item setText:[handler appName]]; 64 [item setText:[handler appName]];
65 [item setAccessibilityTraits:UIAccessibilityTraitButton]; 65 if ([handler isAvailable]) {
66 [item setTextColor:[[MDCPalette greyPalette] tint900]];
67 [item setAccessibilityTraits:UIAccessibilityTraitButton];
68 } else {
69 [item setTextColor:[[MDCPalette greyPalette] tint500]];
70 [item setAccessibilityTraits:UIAccessibilityTraitNotEnabled];
71 }
66 if ([currentHandlerID isEqualToString:[handler appStoreID]]) 72 if ([currentHandlerID isEqualToString:[handler appStoreID]])
67 [item setAccessoryType:MDCCollectionViewCellAccessoryCheckmark]; 73 [item setAccessoryType:MDCCollectionViewCellAccessoryCheckmark];
68 [model addItem:item 74 [model addItem:item
69 toSectionWithIdentifier:SectionIdentifierMailtoHandlers]; 75 toSectionWithIdentifier:SectionIdentifierMailtoHandlers];
70 } 76 }
71 } 77 }
72 78
73 #pragma mark UICollectionViewDelegate 79 #pragma mark UICollectionViewDelegate
74 80
75 - (void)collectionView:(UICollectionView*)collectionView 81 - (void)collectionView:(UICollectionView*)collectionView
76 didSelectItemAtIndexPath:(NSIndexPath*)indexPath { 82 didSelectItemAtIndexPath:(NSIndexPath*)indexPath {
77 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath]; 83 [super collectionView:collectionView didSelectItemAtIndexPath:indexPath];
78 CollectionViewModel* model = self.collectionViewModel; 84 CollectionViewModel* model = self.collectionViewModel;
79 85
80 // The items created in -loadModel are all MailtoHandlers type. 86 // The items created in -loadModel are all MailtoHandlers type.
81 CollectionViewTextItem* selectedItem = 87 CollectionViewTextItem* selectedItem =
82 base::mac::ObjCCastStrict<CollectionViewTextItem>( 88 base::mac::ObjCCastStrict<CollectionViewTextItem>(
83 [model itemAtIndexPath:indexPath]); 89 [model itemAtIndexPath:indexPath]);
84 DCHECK_EQ(ItemTypeMailtoHandlers, selectedItem.type); 90 DCHECK_EQ(ItemTypeMailtoHandlers, selectedItem.type);
85 91
86 // Do nothing if the tapped row is already chosen as the default. 92 // Do nothing if the tapped row is already chosen as the default.
87 if (selectedItem.accessoryType == MDCCollectionViewCellAccessoryCheckmark) 93 if (selectedItem.accessoryType == MDCCollectionViewCellAccessoryCheckmark)
88 return; 94 return;
89 95
96 // Do nothing if the handler for the tapped row is not available.
rohitrao (ping after 24h) 2017/05/22 12:50:37 Consider handling this in shouldSelectItemAtIndexP
pkl (ping after 24h if needed) 2017/05/22 20:27:09 Added shouldSelectItemAtIndexPath:, however it doe
97 NSUInteger handlerIndex = [model indexInItemTypeForIndexPath:indexPath];
98 MailtoHandler* handler =
99 [[_rewriter defaultHandlers] objectAtIndex:handlerIndex];
100 if (![handler isAvailable])
101 return;
102
90 // Iterate through the rows and remove the checkmark from any that has it. 103 // Iterate through the rows and remove the checkmark from any that has it.
91 NSMutableArray* modifiedItems = [NSMutableArray array]; 104 NSMutableArray* modifiedItems = [NSMutableArray array];
92 for (id item in 105 for (id item in
93 [model itemsInSectionWithIdentifier:SectionIdentifierMailtoHandlers]) { 106 [model itemsInSectionWithIdentifier:SectionIdentifierMailtoHandlers]) {
94 CollectionViewTextItem* textItem = 107 CollectionViewTextItem* textItem =
95 base::mac::ObjCCastStrict<CollectionViewTextItem>(item); 108 base::mac::ObjCCastStrict<CollectionViewTextItem>(item);
96 DCHECK_EQ(ItemTypeMailtoHandlers, textItem.type); 109 DCHECK_EQ(ItemTypeMailtoHandlers, textItem.type);
97 if (textItem == selectedItem) { 110 if (textItem == selectedItem) {
98 // Shows the checkmark on the new default mailto: URL handler. 111 // Shows the checkmark on the new default mailto: URL handler.
99 textItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark; 112 textItem.accessoryType = MDCCollectionViewCellAccessoryCheckmark;
100 [modifiedItems addObject:textItem]; 113 [modifiedItems addObject:textItem];
101 } else if (textItem.accessoryType == 114 } else if (textItem.accessoryType ==
102 MDCCollectionViewCellAccessoryCheckmark) { 115 MDCCollectionViewCellAccessoryCheckmark) {
103 // Unchecks any currently checked selection. 116 // Unchecks any currently checked selection.
104 textItem.accessoryType = MDCCollectionViewCellAccessoryNone; 117 textItem.accessoryType = MDCCollectionViewCellAccessoryNone;
105 [modifiedItems addObject:textItem]; 118 [modifiedItems addObject:textItem];
106 } 119 }
107 } 120 }
108 121
109 NSUInteger handlerIndex = [model indexInItemTypeForIndexPath:indexPath];
110 MailtoHandler* handler =
111 [[_rewriter defaultHandlers] objectAtIndex:handlerIndex];
112 [_rewriter setDefaultHandlerID:[handler appStoreID]]; 122 [_rewriter setDefaultHandlerID:[handler appStoreID]];
113 123
114 [self reconfigureCellsForItems:modifiedItems]; 124 [self reconfigureCellsForItems:modifiedItems];
115 } 125 }
116 126
117 @end 127 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698