OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/voicesearch_collection_view_controller.h
" | 5 #import "ios/chrome/browser/ui/settings/voicesearch_collection_view_controller.h
" |
6 | 6 |
7 #import "base/ios/weak_nsobject.h" | |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #include "base/mac/foundation_util.h" | 8 #include "base/mac/foundation_util.h" |
10 #import "base/mac/scoped_nsobject.h" | |
11 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
12 #include "components/prefs/pref_member.h" | 10 #include "components/prefs/pref_member.h" |
13 #include "components/prefs/pref_service.h" | 11 #include "components/prefs/pref_service.h" |
14 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" | 12 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_switch_item
.h" |
15 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" | 13 #import "ios/chrome/browser/ui/collection_view/cells/collection_view_text_item.h
" |
16 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" | 14 #import "ios/chrome/browser/ui/collection_view/collection_view_model.h" |
17 #include "ios/chrome/browser/voice/speech_input_locale_config.h" | 15 #include "ios/chrome/browser/voice/speech_input_locale_config.h" |
18 #include "ios/chrome/grit/ios_strings.h" | 16 #include "ios/chrome/grit/ios_strings.h" |
19 #include "ios/public/provider/chrome/browser/voice/voice_search_prefs.h" | 17 #include "ios/public/provider/chrome/browser/voice/voice_search_prefs.h" |
20 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" | 18 #import "ios/third_party/material_components_ios/src/components/CollectionCells/
src/MaterialCollectionCells.h" |
21 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/l10n/l10n_util_mac.h" | 20 #include "ui/base/l10n/l10n_util_mac.h" |
23 | 21 |
| 22 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 23 #error "This file requires ARC support." |
| 24 #endif |
| 25 |
24 namespace { | 26 namespace { |
25 | 27 |
26 typedef NS_ENUM(NSInteger, SectionIdentifier) { | 28 typedef NS_ENUM(NSInteger, SectionIdentifier) { |
27 SectionIdentifierTTS = kSectionIdentifierEnumZero, | 29 SectionIdentifierTTS = kSectionIdentifierEnumZero, |
28 SectionIdentifierLanguages, | 30 SectionIdentifierLanguages, |
29 }; | 31 }; |
30 | 32 |
31 typedef NS_ENUM(NSInteger, ItemType) { | 33 typedef NS_ENUM(NSInteger, ItemType) { |
32 ItemTypeTTSEnabled = kItemTypeEnumZero, | 34 ItemTypeTTSEnabled = kItemTypeEnumZero, |
33 ItemTypeLanguagesLanguageOption, | 35 ItemTypeLanguagesLanguageOption, |
(...skipping 28 matching lines...) Expand all Loading... |
62 } | 64 } |
63 return self; | 65 return self; |
64 } | 66 } |
65 | 67 |
66 - (void)loadModel { | 68 - (void)loadModel { |
67 [super loadModel]; | 69 [super loadModel]; |
68 CollectionViewModel* model = self.collectionViewModel; | 70 CollectionViewModel* model = self.collectionViewModel; |
69 | 71 |
70 // TTS section. | 72 // TTS section. |
71 [model addSectionWithIdentifier:SectionIdentifierTTS]; | 73 [model addSectionWithIdentifier:SectionIdentifierTTS]; |
72 CollectionViewSwitchItem* tts = [[[CollectionViewSwitchItem alloc] | 74 CollectionViewSwitchItem* tts = |
73 initWithType:ItemTypeTTSEnabled] autorelease]; | 75 [[CollectionViewSwitchItem alloc] initWithType:ItemTypeTTSEnabled]; |
74 tts.text = l10n_util::GetNSString(IDS_IOS_VOICE_SEARCH_SETTING_TTS); | 76 tts.text = l10n_util::GetNSString(IDS_IOS_VOICE_SEARCH_SETTING_TTS); |
75 tts.on = _ttsEnabled.GetValue(); | 77 tts.on = _ttsEnabled.GetValue(); |
76 tts.enabled = [self currentLanguageSupportsTTS]; | 78 tts.enabled = [self currentLanguageSupportsTTS]; |
77 [model addItem:tts toSectionWithIdentifier:SectionIdentifierTTS]; | 79 [model addItem:tts toSectionWithIdentifier:SectionIdentifierTTS]; |
78 | 80 |
79 // Variables used to populate the languages section. | 81 // Variables used to populate the languages section. |
80 voice::SpeechInputLocaleConfig* localeConfig = | 82 voice::SpeechInputLocaleConfig* localeConfig = |
81 voice::SpeechInputLocaleConfig::GetInstance(); | 83 voice::SpeechInputLocaleConfig::GetInstance(); |
82 const std::vector<voice::SpeechInputLocale>& locales = | 84 const std::vector<voice::SpeechInputLocale>& locales = |
83 localeConfig->GetAvailableLocales(); | 85 localeConfig->GetAvailableLocales(); |
84 std::string selectedLocaleCode = _selectedLanguage.GetValue(); | 86 std::string selectedLocaleCode = _selectedLanguage.GetValue(); |
85 | 87 |
86 // Section with the list of voice search languages. | 88 // Section with the list of voice search languages. |
87 [model addSectionWithIdentifier:SectionIdentifierLanguages]; | 89 [model addSectionWithIdentifier:SectionIdentifierLanguages]; |
88 // Add default locale option. Using an empty string for the voice search | 90 // Add default locale option. Using an empty string for the voice search |
89 // locale pref indicates using the default locale. | 91 // locale pref indicates using the default locale. |
90 CollectionViewTextItem* defaultItem = [[[CollectionViewTextItem alloc] | 92 CollectionViewTextItem* defaultItem = [[CollectionViewTextItem alloc] |
91 initWithType:ItemTypeLanguagesLanguageOption] autorelease]; | 93 initWithType:ItemTypeLanguagesLanguageOption]; |
92 defaultItem.text = | 94 defaultItem.text = |
93 l10n_util::GetNSStringF(IDS_IOS_VOICE_SEARCH_SETTINGS_DEFAULT_LOCALE, | 95 l10n_util::GetNSStringF(IDS_IOS_VOICE_SEARCH_SETTINGS_DEFAULT_LOCALE, |
94 localeConfig->GetDefaultLocale().display_name); | 96 localeConfig->GetDefaultLocale().display_name); |
95 defaultItem.accessoryType = selectedLocaleCode.empty() | 97 defaultItem.accessoryType = selectedLocaleCode.empty() |
96 ? MDCCollectionViewCellAccessoryCheckmark | 98 ? MDCCollectionViewCellAccessoryCheckmark |
97 : MDCCollectionViewCellAccessoryNone; | 99 : MDCCollectionViewCellAccessoryNone; |
98 [model addItem:defaultItem | 100 [model addItem:defaultItem |
99 toSectionWithIdentifier:SectionIdentifierLanguages]; | 101 toSectionWithIdentifier:SectionIdentifierLanguages]; |
100 // Add locale list. | 102 // Add locale list. |
101 for (NSUInteger ii = 0; ii < locales.size(); ii++) { | 103 for (NSUInteger ii = 0; ii < locales.size(); ii++) { |
102 voice::SpeechInputLocale locale = locales[ii]; | 104 voice::SpeechInputLocale locale = locales[ii]; |
103 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); | 105 NSString* languageName = base::SysUTF16ToNSString(locale.display_name); |
104 BOOL checked = (locale.code == selectedLocaleCode); | 106 BOOL checked = (locale.code == selectedLocaleCode); |
105 | 107 |
106 CollectionViewTextItem* languageItem = [[[CollectionViewTextItem alloc] | 108 CollectionViewTextItem* languageItem = [[CollectionViewTextItem alloc] |
107 initWithType:ItemTypeLanguagesLanguageOption] autorelease]; | 109 initWithType:ItemTypeLanguagesLanguageOption]; |
108 languageItem.text = languageName; | 110 languageItem.text = languageName; |
109 languageItem.accessoryType = checked | 111 languageItem.accessoryType = checked |
110 ? MDCCollectionViewCellAccessoryCheckmark | 112 ? MDCCollectionViewCellAccessoryCheckmark |
111 : MDCCollectionViewCellAccessoryNone; | 113 : MDCCollectionViewCellAccessoryNone; |
112 [model addItem:languageItem | 114 [model addItem:languageItem |
113 toSectionWithIdentifier:SectionIdentifierLanguages]; | 115 toSectionWithIdentifier:SectionIdentifierLanguages]; |
114 } | 116 } |
115 } | 117 } |
116 | 118 |
117 #pragma mark - UICollectionViewDelegate | 119 #pragma mark - UICollectionViewDelegate |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 - (BOOL)currentLanguageSupportsTTS { | 252 - (BOOL)currentLanguageSupportsTTS { |
251 voice::SpeechInputLocaleConfig* localeConfig = | 253 voice::SpeechInputLocaleConfig* localeConfig = |
252 voice::SpeechInputLocaleConfig::GetInstance(); | 254 voice::SpeechInputLocaleConfig::GetInstance(); |
253 std::string localeCode = _selectedLanguage.GetValue().empty() | 255 std::string localeCode = _selectedLanguage.GetValue().empty() |
254 ? localeConfig->GetDefaultLocale().code | 256 ? localeConfig->GetDefaultLocale().code |
255 : _selectedLanguage.GetValue(); | 257 : _selectedLanguage.GetValue(); |
256 return localeConfig->IsTextToSpeechEnabledForCode(localeCode); | 258 return localeConfig->IsTextToSpeechEnabledForCode(localeCode); |
257 } | 259 } |
258 | 260 |
259 @end | 261 @end |
OLD | NEW |