7
7
//
8
8
9
9
#import " AutoFillPreferencesViewController.h"
10
- #import " AutoFillSettings.h"
10
+ #import " AppPreferences.h"
11
+ #import " AutoFillManager.h"
12
+ #import " NSArray+Extensions.h"
13
+ #import " SelectItemTableViewController.h"
14
+ #import " Utils.h"
11
15
12
16
@interface AutoFillPreferencesViewController ()
13
17
14
18
@property (weak , nonatomic ) IBOutlet UISwitch *autoProceed;
15
19
@property (weak , nonatomic ) IBOutlet UISwitch *addServiceIds;
16
20
@property (weak , nonatomic ) IBOutlet UISwitch *useHostOnlyUrl;
17
- @property (weak , nonatomic ) IBOutlet UISwitch *mainAppSyncReminder;
21
+
22
+ @property (weak , nonatomic ) IBOutlet UISwitch *switchAutoFill;
23
+ @property (weak , nonatomic ) IBOutlet UISwitch *switchQuickTypeAutoFill;
24
+ @property (weak , nonatomic ) IBOutlet UITableViewCell *cellQuickTypeFormat;
25
+ @property (weak , nonatomic ) IBOutlet UILabel *labelQuickTypeFormat;
26
+ @property (weak , nonatomic ) IBOutlet UITableViewCell *cellConvenienceAutoUnlock;
27
+ @property (weak , nonatomic ) IBOutlet UILabel *labelConvenienceAutoUnlockTimeout;
28
+ @property (weak , nonatomic ) IBOutlet UISwitch *switchCopyTOTP;
29
+ @property (weak , nonatomic ) IBOutlet UISwitch *switchAutoLaunchSingle;
30
+ @property (weak , nonatomic ) IBOutlet UISwitch *switchShowPinned;
18
31
19
32
@end
20
33
@@ -27,23 +40,212 @@ - (void)viewDidLoad {
27
40
}
28
41
29
42
- (void )bind {
30
- self.autoProceed .on = AutoFillSettings.sharedInstance .autoProceedOnSingleMatch ;
31
- self.addServiceIds .on = AutoFillSettings.sharedInstance .storeAutoFillServiceIdentifiersInNotes ;
32
- self.useHostOnlyUrl .on = !AutoFillSettings.sharedInstance .useFullUrlAsURLSuggestion ;
33
- self.mainAppSyncReminder .on = !AutoFillSettings.sharedInstance .dontNotifyToSwitchToMainAppForSync ;
43
+ self.autoProceed .on = AppPreferences.sharedInstance .autoProceedOnSingleMatch ;
44
+ self.addServiceIds .on = AppPreferences.sharedInstance .storeAutoFillServiceIdentifiersInNotes ;
45
+ self.useHostOnlyUrl .on = !AppPreferences.sharedInstance .useFullUrlAsURLSuggestion ;
46
+
47
+ self.switchAutoFill .on = self.viewModel .metadata .autoFillEnabled ;
48
+
49
+
50
+
51
+ self.switchQuickTypeAutoFill .on = self.viewModel .metadata .autoFillEnabled && self.viewModel .metadata .quickTypeEnabled ;
52
+ self.switchQuickTypeAutoFill .enabled = self.switchAutoFill .on ;
53
+
54
+
55
+
56
+ self.cellQuickTypeFormat .userInteractionEnabled = self.switchQuickTypeAutoFill .on ;
57
+ self.labelQuickTypeFormat .text = quickTypeFormatString (self.viewModel .metadata .quickTypeDisplayFormat );
58
+ if (@available (iOS 13.0 , *)) {
59
+ self.labelQuickTypeFormat .textColor = self.switchQuickTypeAutoFill .on ? UIColor.labelColor : UIColor.secondaryLabelColor ;
60
+ }
61
+ else {
62
+ self.labelQuickTypeFormat .textColor = self.switchQuickTypeAutoFill .on ? UIColor.blackColor : UIColor.lightGrayColor ;
63
+ }
64
+
65
+
66
+
67
+ self.cellConvenienceAutoUnlock .userInteractionEnabled = self.viewModel .metadata .autoFillEnabled ;
68
+ self.labelConvenienceAutoUnlockTimeout .text = stringForConvenienceAutoUnlock (self.viewModel .metadata .autoFillConvenienceAutoUnlockTimeout );
69
+
70
+ if (@available (iOS 13.0 , *)) {
71
+ self.labelConvenienceAutoUnlockTimeout .textColor = self.viewModel .metadata .autoFillEnabled ? UIColor.labelColor : UIColor.secondaryLabelColor ;
72
+ }
73
+ else {
74
+ self.labelConvenienceAutoUnlockTimeout .textColor = self.viewModel .metadata .autoFillEnabled ? UIColor.blackColor : UIColor.lightGrayColor ;
75
+ }
76
+
77
+
78
+
79
+ self.switchAutoLaunchSingle .on = AppPreferences.sharedInstance .autoFillAutoLaunchSingleDatabase ;
80
+
81
+
82
+
83
+ self.switchCopyTOTP .on = self.viewModel .metadata .autoFillCopyTotp ;
84
+
85
+
86
+
87
+ self.switchShowPinned .on = AppPreferences.sharedInstance .autoFillShowPinned ;
88
+ }
89
+
90
+ static NSString * stringForConvenienceAutoUnlock (NSInteger val) {
91
+ if (val == -1 ) {
92
+ return NSLocalizedString(@" generic_preference_not_configured" , @" Not Configured" );
93
+ }
94
+ else if ( val == 0 ) {
95
+ return NSLocalizedString(@" prefs_vc_setting_disabled" , @" Disabled" );
96
+ }
97
+ else {
98
+ return [Utils formatTimeInterval: val];
99
+ }
34
100
}
35
101
36
102
- (IBAction )onDone : (id )sender {
37
103
[self .presentingViewController dismissViewControllerAnimated: YES completion: nil ];
38
104
}
39
105
40
106
- (IBAction )onChanged : (id )sender {
41
- AutoFillSettings.sharedInstance .autoProceedOnSingleMatch = self.autoProceed .on ;
42
- AutoFillSettings.sharedInstance .storeAutoFillServiceIdentifiersInNotes = self.addServiceIds .on ;
43
- AutoFillSettings.sharedInstance .useFullUrlAsURLSuggestion = !self.useHostOnlyUrl .on ;
44
- AutoFillSettings.sharedInstance .dontNotifyToSwitchToMainAppForSync = !self.mainAppSyncReminder .on ;
107
+ AppPreferences.sharedInstance .autoProceedOnSingleMatch = self.autoProceed .on ;
108
+ AppPreferences.sharedInstance .storeAutoFillServiceIdentifiersInNotes = self.addServiceIds .on ;
109
+ AppPreferences.sharedInstance .useFullUrlAsURLSuggestion = !self.useHostOnlyUrl .on ;
110
+ AppPreferences.sharedInstance .autoFillAutoLaunchSingleDatabase = self.switchAutoLaunchSingle .on ;
111
+ AppPreferences.sharedInstance .autoFillShowPinned = self.switchShowPinned .on ;
45
112
46
113
[self bind ];
47
114
}
48
115
116
+ - (IBAction )onCopyTotp : (id )sender {
117
+ self.viewModel .metadata .autoFillCopyTotp = self.switchCopyTOTP .on ;
118
+ [[SafesList sharedInstance ] update: self .viewModel.metadata];
119
+
120
+ [self bind ];
121
+ }
122
+
123
+ - (IBAction )onSwitchQuickTypeAutoFill : (id )sender {
124
+ if ( !self.switchQuickTypeAutoFill .on ) {
125
+ [AutoFillManager.sharedInstance clearAutoFillQuickTypeDatabase ];
126
+ }
127
+ else {
128
+ [AutoFillManager.sharedInstance updateAutoFillQuickTypeDatabase: self .viewModel.database
129
+ databaseUuid: self .viewModel.metadata.uuid
130
+ displayFormat: self .viewModel.metadata.quickTypeDisplayFormat];
131
+ }
132
+
133
+ self.viewModel .metadata .quickTypeEnabled = self.switchQuickTypeAutoFill .on ;
134
+ [[SafesList sharedInstance ] update: self .viewModel.metadata];
135
+
136
+ [self bind ];
137
+ }
138
+
139
+ - (IBAction )onSwitchAutoFill : (id )sender {
140
+ if (!self.switchAutoFill .on ) {
141
+ [self .viewModel disableAndClearAutoFill ];
142
+ [self bind ];
143
+ }
144
+ else {
145
+ [self .viewModel enableAutoFill ];
146
+
147
+ if ( self.viewModel .metadata .quickTypeEnabled ) {
148
+ [AutoFillManager.sharedInstance updateAutoFillQuickTypeDatabase: self .viewModel.database
149
+ databaseUuid: self .viewModel.metadata.uuid
150
+ displayFormat: self .viewModel.metadata.quickTypeDisplayFormat];
151
+ }
152
+
153
+ [self bind ];
154
+ }
155
+ }
156
+
157
+ - (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath {
158
+ UITableViewCell* cell = [self .tableView cellForRowAtIndexPath: indexPath];
159
+
160
+ if ( cell == self.cellQuickTypeFormat ) {
161
+ [self promptForQuickTypeFormat ];
162
+ }
163
+ else if ( cell == self.cellConvenienceAutoUnlock ) {
164
+ [self promptForConvenienceAutoUnlock ];
165
+ }
166
+
167
+ [self .tableView deselectRowAtIndexPath: indexPath animated: YES ];
168
+ }
169
+
170
+ - (void )promptForConvenienceAutoUnlock {
171
+ NSArray <NSNumber *>* options = @[@(0 ), @(15 ), @(30 ), @(60 ), @(120 ), @(180 ), @(300 ), @(600 ), @(1200 ), @(1800 ), @(3600 ), @(2 * 3600 ), @(8 * 3600 ), @(24 * 3600 ), @(48 * 3600 ), @(72 * 3600 )];
172
+
173
+ NSArray <NSString *>* optionsStrings = [options map: ^id _Nonnull (NSNumber * _Nonnull obj, NSUInteger idx) {
174
+ return stringForConvenienceAutoUnlock (obj.integerValue );
175
+ }];
176
+
177
+ NSUInteger currentlySelected = [options indexOfObject: @(self .viewModel.metadata.autoFillConvenienceAutoUnlockTimeout)];
178
+
179
+ [self promptForChoice: NSLocalizedString(@" prefs_vc_autofill_convenience_auto_unlock" , @" Convenience Auto Unlock" )
180
+ options: optionsStrings
181
+ currentlySelectIndex: currentlySelected
182
+ completion: ^(BOOL success, NSInteger selectedIndex) {
183
+ if (success) {
184
+ NSNumber *numFormat = options[selectedIndex];
185
+ self.viewModel .metadata .autoFillConvenienceAutoUnlockTimeout = numFormat.integerValue ;
186
+ [SafesList.sharedInstance update: self .viewModel.metadata];
187
+
188
+ if (self.viewModel .metadata .autoFillConvenienceAutoUnlockTimeout == 0 ) {
189
+ self.viewModel .metadata .autoFillConvenienceAutoUnlockPassword = nil ;
190
+ }
191
+
192
+ [self bind ];
193
+ }
194
+ }];
195
+ }
196
+
197
+ - (void )promptForQuickTypeFormat {
198
+ NSArray <NSNumber *>* options = @[@(kQuickTypeFormatTitleThenUsername ),
199
+ @(kQuickTypeFormatUsernameOnly ),
200
+ @(kQuickTypeFormatTitleOnly )];
201
+
202
+ NSArray <NSString *>* optionsStrings = [options map: ^id _Nonnull (NSNumber * _Nonnull obj, NSUInteger idx) {
203
+ return quickTypeFormatString (obj.integerValue );
204
+ }];
205
+
206
+ NSUInteger currentlySelected = [options indexOfObject: @(self .viewModel.metadata.quickTypeDisplayFormat)];
207
+
208
+ [self promptForChoice: NSLocalizedString(@" prefs_vc_quick_type_format" , @" QuickType Format" )
209
+ options: optionsStrings
210
+ currentlySelectIndex: currentlySelected
211
+ completion: ^(BOOL success, NSInteger selectedIndex) {
212
+ if (success) {
213
+ NSNumber *numFormat = options[selectedIndex];
214
+ self.viewModel .metadata .quickTypeDisplayFormat = numFormat.integerValue ;
215
+ [SafesList.sharedInstance update: self .viewModel.metadata];
216
+
217
+
218
+ [AutoFillManager.sharedInstance updateAutoFillQuickTypeDatabase: self .viewModel.database
219
+ databaseUuid: self .viewModel.metadata.uuid
220
+ displayFormat: self .viewModel.metadata.quickTypeDisplayFormat];
221
+
222
+ [self bind ];
223
+ }
224
+ }];
225
+ }
226
+
227
+ - (void )promptForChoice : (NSString *)title
228
+ options : (NSArray <NSString*>*)items
229
+ currentlySelectIndex : (NSUInteger )currentlySelectIndex
230
+ completion : (void (^)(BOOL success, NSInteger selectedIndex))completion {
231
+ UIStoryboard* storyboard = [UIStoryboard storyboardWithName: @" SelectItem" bundle: nil ];
232
+ UINavigationController* nav = (UINavigationController*)[storyboard instantiateInitialViewController ];
233
+ SelectItemTableViewController *vc = (SelectItemTableViewController*)nav.topViewController ;
234
+
235
+ vc.groupItems = @[items];
236
+
237
+ if ( currentlySelectIndex != NSNotFound ) {
238
+ vc.selectedIndexPaths = @[[NSIndexSet indexSetWithIndex: currentlySelectIndex]];
239
+ }
240
+
241
+ vc.onSelectionChange = ^(NSArray <NSIndexSet *> * _Nonnull selectedIndices) {
242
+ NSIndexSet * set = selectedIndices.firstObject ;
243
+ [self .navigationController popViewControllerAnimated: YES ];
244
+ completion (YES , set.firstIndex );
245
+ };
246
+
247
+ vc.title = title;
248
+ [self .navigationController pushViewController: vc animated: YES ];
249
+ }
250
+
49
251
@end
0 commit comments