1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
|
//
// NCSettings.m
// Nextcloud
//
// Created by Marino Faggiana on 24/11/14.
// Copyright (c) 2014 Marino Faggiana. All rights reserved.
//
// Author Marino Faggiana <marino.faggiana@nextcloud.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
#import "NCSettings.h"
#import "AppDelegate.h"
#import "CCAdvanced.h"
#import "CCManageAccount.h"
#import "NCManageEndToEndEncryption.h"
#import "NCBridgeSwift.h"
#import "NSNotificationCenter+MainThread.h"
#import <TOPasscodeViewController/TOPasscodeViewController.h>
#define alertViewEsci 1
#define alertViewAzzeraCache 2
@interface NCSettings () <TOPasscodeSettingsViewControllerDelegate, TOPasscodeViewControllerDelegate>
{
AppDelegate *appDelegate;
TOPasscodeViewController *passcodeViewController;
TOPasscodeSettingsViewController *passcodeSettingsViewController;
}
@end
@implementation NCSettings
- (void)initializeForm
{
XLFormDescriptor *form = [XLFormDescriptor formDescriptor];
XLFormSectionDescriptor *section;
XLFormRowDescriptor *row;
//NSInteger serverVersionMajor = [[NCManageDatabase shared] getCapabilitiesServerIntWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesVersionMajor];
form.rowNavigationOptions = XLFormRowNavigationOptionNone;
// Section AUTO UPLOAD OF CAMERA IMAGES ----------------------------
section = [XLFormSectionDescriptor formSection];
[form addFormSection:section];
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_settings_autoupload_", nil)];
row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
[row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
[row.cellConfig setObject:[[UIImage imageNamed:@"autoUpload"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
row.action.viewControllerClass = [CCManageAutoUpload class];
[section addFormRow:row];
// Section : LOCK --------------------------------------------------------------
section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_lock_", nil)];
[form addFormSection:section];
// Lock active YES/NO
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
[row.cellConfig setObject:[[UIImage imageNamed:@"settingsPasscodeNO"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
[row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
[row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
//[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
row.action.formSelector = @selector(passcode:);
[section addFormRow:row];
// Enable Touch ID
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"enableTouchDaceID" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_enable_touch_face_id_", nil)];
row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
[row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
[section addFormRow:row];
// Lock no screen
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"notPasscodeAtStart" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_no_screen_", nil)];
row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
[row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
[section addFormRow:row];
// Section : Screen --------------------------------------------------------------
section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_screen_", nil)];
[form addFormSection:section];
// Dark Mode
if (@available(iOS 13.0, *)) {
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"darkModeDetect" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_dark_mode_detect_", nil)];
row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
[row.cellConfig setObject:[[UIImage imageNamed:@"darkModeDetect"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
[row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
if ([CCUtility getDarkModeDetect]) row.value = @1;
else row.value = @0;
[section addFormRow:row];
} else {
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"darkMode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_dark_mode_", nil)];
row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
[row.cellConfig setObject:[[UIImage imageNamed:@"themeLightDark"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
[row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
if ([CCUtility getDarkMode]) row.value = @1;
else row.value = @0;
[section addFormRow:row];
}
// Section : E2EEncryption --------------------------------------------------------------
section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_title_", nil)];
[form addFormSection:section];
// EndToEnd Encryption
NSString *title = [NSString stringWithFormat:@"%@ (%@)",NSLocalizedString(@"_e2e_settings_", nil), NSLocalizedString(@"_experimental_", nil)];
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"e2eEncryption" rowType:XLFormRowDescriptorTypeButton title:title];
row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
[row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
[row.cellConfig setObject:[[UIImage imageNamed:@"lock"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
row.action.viewControllerClass = [NCManageEndToEndEncryption class];
[section addFormRow:row];
// Section Advanced -------------------------------------------------
section = [XLFormSectionDescriptor formSection];
[form addFormSection:section];
// Advanced
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_advanced_", nil)];
row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
[row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
[row.cellConfig setObject:[[UIImage imageNamed:@"settings"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
row.action.viewControllerClass = [CCAdvanced class];
[section addFormRow:row];
// Section : INFORMATION ------------------------------------------------
section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
[form addFormSection:section];
// Acknowledgements
row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.shared.backgroundCell;
[row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
[row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
[row.cellConfig setObject:NCBrandColor.shared.textView forKey:@"textLabel.textColor"];
[row.cellConfig setObject:[[UIImage imageNamed:@"acknowledgements"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
row.action.formBlock = ^(XLFormRowDescriptor * sender){
[self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
[self deselectFormRow:sender];
};
[section addFormRow:row];
self.tableView.showsVerticalScrollIndicator = NO;
self.tableView.contentInset = UIEdgeInsetsMake(0, 0, 35, 0);
self.form = form;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = NSLocalizedString(@"_settings_", nil);
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:NCBrandGlobal.shared.notificationCenterChangeTheming object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidEnterBackground) name:NCBrandGlobal.shared.notificationCenterApplicationDidEnterBackground object:nil];
[self changeTheming];
}
- (void)changeTheming
{
self.view.backgroundColor = NCBrandColor.shared.backgroundForm;
self.tableView.backgroundColor = NCBrandColor.shared.backgroundForm;
[self.tableView reloadData];
[self initializeForm];
[self reloadForm];
}
- (void)applicationDidEnterBackground
{
if (passcodeViewController.view.window != nil) {
[passcodeViewController dismissViewControllerAnimated:true completion:nil];
}
if (passcodeSettingsViewController.view.window != nil) {
[passcodeSettingsViewController dismissViewControllerAnimated:true completion:nil];
}
}
#pragma --------------------------------------------------------------------------------------------
#pragma mark === Chiamate dal Form ===
#pragma --------------------------------------------------------------------------------------------
- (void)reloadForm
{
self.form.delegate = nil;
// ------------------------------------------------------------------
XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
XLFormRowDescriptor *rowNotPasscodeAtStart = [self.form formRowWithTag:@"notPasscodeAtStart"];
XLFormRowDescriptor *rowEnableTouchDaceID = [self.form formRowWithTag:@"enableTouchDaceID"];
XLFormRowDescriptor *rowDarkModeDetect = [self.form formRowWithTag:@"darkModeDetect"];
XLFormRowDescriptor *rowDarkMode = [self.form formRowWithTag:@"darkMode"];
// ------------------------------------------------------------------
if ([[CCUtility getPasscode] length]) {
rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
[rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"settingsPasscodeYES"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
} else {
rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
[rowBloccoPasscode.cellConfig setObject:[[UIImage imageNamed:@"settingsPasscodeNO"] imageWithColor:NCBrandColor.shared.icon size:25] forKey:@"imageView.image"];
}
if ([CCUtility getEnableTouchFaceID]) [rowEnableTouchDaceID setValue:@1]; else [rowEnableTouchDaceID setValue:@0];
if ([CCUtility getNotPasscodeAtStart]) [rowNotPasscodeAtStart setValue:@1]; else [rowNotPasscodeAtStart setValue:@0];
if ([CCUtility getDarkModeDetect]) [rowDarkModeDetect setValue:@1]; else [rowDarkModeDetect setValue:@0];
if ([CCUtility getDarkMode]) [rowDarkMode setValue:@1]; else [rowDarkMode setValue:@0];
// -----------------------------------------------------------------
[self.tableView reloadData];
self.form.delegate = self;
}
- (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
{
[super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
if ([rowDescriptor.tag isEqualToString:@"notPasscodeAtStart"]) {
if ([[rowDescriptor.value valueData] boolValue] == YES) {
[CCUtility setNotPasscodeAtStart:true];
} else {
[CCUtility setNotPasscodeAtStart:false];
}
}
if ([rowDescriptor.tag isEqualToString:@"enableTouchDaceID"]) {
if ([[rowDescriptor.value valueData] boolValue] == YES) {
[CCUtility setEnableTouchFaceID:true];
} else {
[CCUtility setEnableTouchFaceID:false];
}
}
if ([rowDescriptor.tag isEqualToString:@"darkMode"]) {
if ([[rowDescriptor.value valueData] boolValue] == YES) {
[CCUtility setDarkMode:true];
} else {
[CCUtility setDarkMode:false];
}
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCBrandGlobal.shared.notificationCenterChangeTheming object:nil];
}
if ([rowDescriptor.tag isEqualToString:@"darkModeDetect"]) {
if ([[rowDescriptor.value valueData] boolValue] == YES) {
[CCUtility setDarkModeDetect:true];
// detect Dark Mode
if (@available(iOS 12.0, *)) {
appDelegate.preferredUserInterfaceStyle = self.traitCollection.userInterfaceStyle;
if (appDelegate.preferredUserInterfaceStyle == UIUserInterfaceStyleDark) {
[CCUtility setDarkMode:YES];
} else {
[CCUtility setDarkMode:NO];
}
}
} else {
[CCUtility setDarkModeDetect:false];
[CCUtility setDarkMode:false];
}
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:NCBrandGlobal.shared.notificationCenterChangeTheming object:nil];
}
}
#pragma mark - Passcode -
- (void)didPerformBiometricValidationRequestInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
{
[[LAContext new] evaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics localizedReason:[[NCBrandOptions shared] brand] reply:^(BOOL success, NSError * _Nullable error) {
if (success) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
[CCUtility setPasscode:@""];
[passcodeViewController dismissViewControllerAnimated:YES completion:nil];
[self reloadForm];
});
}
}];
}
- (void)passcodeSettingsViewController:(TOPasscodeSettingsViewController *)passcodeSettingsViewController didChangeToNewPasscode:(NSString *)passcode ofType:(TOPasscodeType)type
{
[CCUtility setPasscode:passcode];
[passcodeSettingsViewController dismissViewControllerAnimated:YES completion:nil];
[self reloadForm];
}
- (void)didTapCancelInPasscodeViewController:(TOPasscodeViewController *)passcodeViewController
{
[passcodeViewController dismissViewControllerAnimated:YES completion:nil];
}
- (BOOL)passcodeViewController:(TOPasscodeViewController *)passcodeViewController isCorrectCode:(NSString *)code
{
if ([code isEqualToString:[CCUtility getPasscode]]) {
[CCUtility setPasscode:@""];
[self reloadForm];
return YES;
}
return NO;
}
- (void)passcode:(XLFormRowDescriptor *)sender
{
LAContext *laContext = [LAContext new];
NSError *error;
[self deselectFormRow:sender];
if ([[CCUtility getPasscode] length] == 0) {
passcodeSettingsViewController = [[TOPasscodeSettingsViewController alloc] init];
if (@available(iOS 13.0, *)) {
if ([[UITraitCollection currentTraitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark) {
passcodeSettingsViewController.style = TOPasscodeSettingsViewStyleDark;
}
}
passcodeSettingsViewController.hideOptionsButton = YES;
passcodeSettingsViewController.requireCurrentPasscode = NO;
passcodeSettingsViewController.passcodeType = TOPasscodeTypeSixDigits;
passcodeSettingsViewController.delegate = self;
[self presentViewController:passcodeSettingsViewController animated:YES completion:nil];
} else {
passcodeViewController = [[TOPasscodeViewController alloc] initWithStyle:TOPasscodeViewStyleTranslucentLight passcodeType:TOPasscodeTypeSixDigits];
if (@available(iOS 13.0, *)) {
if ([[UITraitCollection currentTraitCollection] userInterfaceStyle] == UIUserInterfaceStyleDark) {
passcodeViewController.style = TOPasscodeViewStyleTranslucentDark;
}
}
passcodeViewController.allowCancel = true;
passcodeViewController.delegate = self;
passcodeViewController.keypadButtonShowLettering = false;
if (CCUtility.getEnableTouchFaceID && [laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:&error]) {
if (error == NULL) {
if (laContext.biometryType == LABiometryTypeFaceID) {
passcodeViewController.biometryType = TOPasscodeBiometryTypeFaceID;
passcodeViewController.allowBiometricValidation = true;
passcodeViewController.automaticallyPromptForBiometricValidation = true;
} else if (laContext.biometryType == LABiometryTypeTouchID) {
passcodeViewController.biometryType = TOPasscodeBiometryTypeTouchID;
passcodeViewController.allowBiometricValidation = true;
passcodeViewController.automaticallyPromptForBiometricValidation = true;
} else {
NSLog(@"No Biometric support");
}
}
}
[self presentViewController:passcodeViewController animated:YES completion:nil];
}
}
#pragma --------------------------------------------------------------------------------------------
#pragma mark === Table View ===
#pragma --------------------------------------------------------------------------------------------
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
NSString *sectionName;
switch (section)
{
case 1: {
sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
}
break;
case 5: {
NSString *versionServer = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesVersionString];
NSString *themingName = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesThemingName];
NSString *themingSlogan = [[NCManageDatabase shared] getCapabilitiesServerStringWithAccount:appDelegate.account elements:NCElementsJSON.shared.capabilitiesThemingSlogan];
NSString *versionApp = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudServer, versionServer];
NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions shared].textCopyrightNextcloudiOS, versionApp];
NSString *nameSlogan = [NSString stringWithFormat:@"%@ - %@", themingName, themingSlogan];
sectionName = [NSString stringWithFormat:@"\n%@\n\n%@\n%@", versionNextcloudiOS, versionNextcloud, nameSlogan];
}
break;
}
return sectionName;
}
@end
|