CCSettings.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. //
  2. // CCSettings.m
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 24/11/14.
  6. // Copyright (c) 2017 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. #import "CCSettings.h"
  24. #import "AppDelegate.h"
  25. #import "CCMain.h"
  26. #import "OCCapabilities.h"
  27. #import "CCSynchronize.h"
  28. #import "CCAdvanced.h"
  29. #import "CCManageAccount.h"
  30. #import "NCManageEndToEndEncryption.h"
  31. #import "NCBridgeSwift.h"
  32. #define alertViewEsci 1
  33. #define alertViewAzzeraCache 2
  34. @interface CCSettings ()
  35. {
  36. AppDelegate *appDelegate;
  37. }
  38. @end
  39. @implementation CCSettings
  40. - (void)initializeForm
  41. {
  42. XLFormDescriptor *form = [XLFormDescriptor formDescriptorWithTitle:NSLocalizedString(@"_settings_", nil)];
  43. XLFormSectionDescriptor *section;
  44. XLFormRowDescriptor *row;
  45. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  46. // Section AUTO UPLOAD OF CAMERA IMAGES ----------------------------
  47. section = [XLFormSectionDescriptor formSection];
  48. [form addFormSection:section];
  49. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"autoUpload" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_settings_autoupload_", nil)];
  50. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  51. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  52. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  53. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"autoUpload"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  54. row.action.viewControllerClass = [CCManageAutoUpload class];
  55. [section addFormRow:row];
  56. // Section FOLDERS FAVORITES OFFLINE ------------------------------------
  57. section = [XLFormSectionDescriptor formSection];
  58. [form addFormSection:section];
  59. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"favoriteoffline" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_favorite_offline_", nil)];
  60. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  61. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  62. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  63. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  64. [section addFormRow:row];
  65. // Section : LOCK --------------------------------------------------------------
  66. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_lock_", nil)];
  67. [form addFormSection:section];
  68. // Lock active YES/NO
  69. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"bloccopasscode" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_lock_not_active_", nil)];
  70. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  71. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeNO"] multiplier:2 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  72. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  73. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  74. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  75. //[row.cellConfig setObject:@(UITableViewCellAccessoryDisclosureIndicator) forKey:@"accessoryType"];
  76. row.action.formSelector = @selector(bloccoPassword);
  77. [section addFormRow:row];
  78. // Passcode simply
  79. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"simplypasscode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_simply_", nil)];
  80. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  81. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  82. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  83. [section addFormRow:row];
  84. // Lock no screen
  85. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"onlylockdir" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_lock_protection_no_screen_", nil)];
  86. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  87. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  88. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  89. [section addFormRow:row];
  90. // Section : Screen --------------------------------------------------------------
  91. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_screen_", nil)];
  92. [form addFormSection:section];
  93. // Dark Mode
  94. if (@available(iOS 13.0, *)) {
  95. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"darkModeDetect" rowType:XLFormRowDescriptorTypeBooleanSwitch title:[NSString stringWithFormat:@"%@ (beta)", NSLocalizedString(@"_dark_mode_detect_", nil)]];
  96. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  97. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"darkModeDetect"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  98. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  99. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  100. if ([CCUtility getDarkModeDetect]) row.value = @1;
  101. else row.value = @0;
  102. [section addFormRow:row];
  103. } else {
  104. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"darkMode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:[NSString stringWithFormat:@"%@ (beta)", NSLocalizedString(@"_dark_mode_", nil)]];
  105. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  106. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"themeLightDark"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  107. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  108. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  109. if ([CCUtility getDarkMode]) row.value = @1;
  110. else row.value = @0;
  111. [section addFormRow:row];
  112. }
  113. // Section : E2EEncryption --------------------------------------------------------------
  114. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_e2e_settings_title_", nil)];
  115. [form addFormSection:section];
  116. // EndToEnd Encryption
  117. NSString *title = [NSString stringWithFormat:@"%@ (%@)",NSLocalizedString(@"_e2e_settings_", nil), NSLocalizedString(@"_experimental_", nil)];
  118. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"e2eEncryption" rowType:XLFormRowDescriptorTypeButton title:title];
  119. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  120. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  121. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  122. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"lock"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  123. row.action.viewControllerClass = [NCManageEndToEndEncryption class];
  124. [section addFormRow:row];
  125. // Section Advanced -------------------------------------------------
  126. section = [XLFormSectionDescriptor formSection];
  127. [form addFormSection:section];
  128. // Advanced
  129. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_advanced_", nil)];
  130. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  131. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  132. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  133. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settings"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  134. row.action.viewControllerClass = [CCAdvanced class];
  135. [section addFormRow:row];
  136. // Section : INFORMATION ------------------------------------------------
  137. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
  138. [form addFormSection:section];
  139. // Acknowledgements
  140. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  141. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  142. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  143. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  144. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  145. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"acknowledgements"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  146. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  147. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  148. [self deselectFormRow:sender];
  149. };
  150. [section addFormRow:row];
  151. self.tableView.showsVerticalScrollIndicator = NO;
  152. self.form = form;
  153. }
  154. - (void)viewDidLoad
  155. {
  156. [super viewDidLoad];
  157. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  158. // changeTheming
  159. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:k_notificationCenter_changeTheming object:nil];
  160. [self changeTheming];
  161. }
  162. - (void)changeTheming
  163. {
  164. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:true];
  165. [self initializeForm];
  166. [self reloadForm];
  167. }
  168. #pragma --------------------------------------------------------------------------------------------
  169. #pragma mark === Chiamate dal Form ===
  170. #pragma --------------------------------------------------------------------------------------------
  171. - (void)reloadForm
  172. {
  173. self.form.delegate = nil;
  174. // ------------------------------------------------------------------
  175. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  176. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  177. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  178. XLFormRowDescriptor *rowFavoriteOffline = [self.form formRowWithTag:@"favoriteoffline"];
  179. XLFormRowDescriptor *rowDarkModeDetect = [self.form formRowWithTag:@"darkModeDetect"];
  180. XLFormRowDescriptor *rowDarkMode = [self.form formRowWithTag:@"darkMode"];
  181. // ------------------------------------------------------------------
  182. if ([[CCUtility getBlockCode] length]) {
  183. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  184. [rowBloccoPasscode.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeYES"] multiplier:2 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  185. } else {
  186. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  187. [rowBloccoPasscode.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeNO"] multiplier:2 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  188. }
  189. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  190. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  191. if ([CCUtility getFavoriteOffline]) [rowFavoriteOffline setValue:@1]; else [rowFavoriteOffline setValue:@0];
  192. if ([CCUtility getDarkModeDetect]) [rowDarkModeDetect setValue:@1]; else [rowDarkModeDetect setValue:@0];
  193. if ([CCUtility getDarkMode]) [rowDarkMode setValue:@1]; else [rowDarkMode setValue:@0];
  194. // -----------------------------------------------------------------
  195. [self.tableView reloadData];
  196. self.form.delegate = self;
  197. }
  198. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  199. {
  200. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  201. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  202. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  203. [CCUtility setOnlyLockDir:true];
  204. } else {
  205. [CCUtility setOnlyLockDir:false];
  206. }
  207. }
  208. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  209. if ([[CCUtility getBlockCode] length] == 0)
  210. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  211. else
  212. [self changeSimplyPassword];
  213. }
  214. if ([rowDescriptor.tag isEqualToString:@"favoriteoffline"]) {
  215. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  216. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_continue_request_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  217. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  218. [CCUtility setFavoriteOffline:true];
  219. [self synchronizeFavorites];
  220. }]];
  221. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  222. [self reloadForm];
  223. }]];
  224. alertController.popoverPresentationController.sourceView = self.view;
  225. NSIndexPath *indexPath = [self.form indexPathOfFormRow:rowDescriptor];
  226. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  227. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  228. [self presentViewController:alertController animated:YES completion:nil];
  229. } else {
  230. [CCUtility setFavoriteOffline:false];
  231. }
  232. }
  233. if ([rowDescriptor.tag isEqualToString:@"darkMode"]) {
  234. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  235. [CCUtility setDarkMode:true];
  236. } else {
  237. [CCUtility setDarkMode:false];
  238. }
  239. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_changeTheming object:nil];
  240. }
  241. if ([rowDescriptor.tag isEqualToString:@"darkModeDetect"]) {
  242. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  243. [CCUtility setDarkModeDetect:true];
  244. // detect Dark Mode
  245. if (@available(iOS 12.0, *)) {
  246. appDelegate.preferredUserInterfaceStyle = self.traitCollection.userInterfaceStyle;
  247. if (appDelegate.preferredUserInterfaceStyle == UIUserInterfaceStyleDark) {
  248. [CCUtility setDarkMode:YES];
  249. } else {
  250. [CCUtility setDarkMode:NO];
  251. }
  252. }
  253. } else {
  254. [CCUtility setDarkModeDetect:false];
  255. [CCUtility setDarkMode:false];
  256. }
  257. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:k_notificationCenter_changeTheming object:nil];
  258. }
  259. }
  260. - (void)changeSimplyPassword
  261. {
  262. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  263. viewController.delegate = self;
  264. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  265. viewController.fromType = CCBKPasscodeFromSimply;
  266. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  267. viewController.inputViewTitlePassword = YES;
  268. if ([CCUtility getSimplyBlockCode]) {
  269. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  270. viewController.passcodeInputView.maximumLength = 6;
  271. } else {
  272. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  273. viewController.passcodeInputView.maximumLength = 64;
  274. }
  275. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  276. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  277. viewController.touchIDManager = touchIDManager;
  278. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  279. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  280. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  281. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  282. [self presentViewController:navigationController animated:YES completion:nil];
  283. }
  284. - (void)bloccoPassword
  285. {
  286. // ATTIVAZIONE LOCK PASSWORD
  287. if ([[CCUtility getBlockCode] length] == 0) {
  288. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  289. viewController.delegate = self;
  290. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  291. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  292. viewController.inputViewTitlePassword = YES;
  293. if ([CCUtility getSimplyBlockCode]) {
  294. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  295. viewController.passcodeInputView.maximumLength = 6;
  296. } else {
  297. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  298. viewController.passcodeInputView.maximumLength = 64;
  299. }
  300. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  301. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  302. viewController.touchIDManager = touchIDManager;
  303. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  304. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  305. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  306. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  307. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  308. [self presentViewController:navigationController animated:YES completion:nil];
  309. } else {
  310. // OFF LOCK PASSWORD
  311. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  312. viewController.delegate = self;
  313. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  314. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  315. viewController.inputViewTitlePassword = YES;
  316. if ([CCUtility getSimplyBlockCode]) {
  317. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  318. viewController.passcodeInputView.maximumLength = 6;
  319. } else {
  320. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  321. viewController.passcodeInputView.maximumLength = 64;
  322. }
  323. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  324. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  325. viewController.touchIDManager = touchIDManager;
  326. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  327. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  328. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  329. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  330. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  331. [self presentViewController:navigationController animated:YES completion:nil];
  332. }
  333. }
  334. - (void)synchronizeFavorites
  335. {
  336. NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND favorite == true", appDelegate.activeAccount] sorted:nil ascending:NO];
  337. for (tableMetadata *metadata in metadatas) {
  338. if (metadata.directory) {
  339. NSString *serverUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
  340. NSString *serverUrlBeginWith = serverUrl;
  341. if (![serverUrl hasSuffix:@"/"])
  342. serverUrlBeginWith = [serverUrl stringByAppendingString:@"/"];
  343. NSArray *directories = [[NCManageDatabase sharedInstance] getTablesDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (serverUrl == %@ OR serverUrl BEGINSWITH %@)", appDelegate.activeAccount, serverUrl, serverUrlBeginWith] sorted:@"serverUrl" ascending:true];
  344. for (tableDirectory *directory in directories)
  345. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:directory.serverUrl account:appDelegate.activeAccount];
  346. }
  347. }
  348. [appDelegate.activeFavorites listingFavorites];
  349. }
  350. #pragma --------------------------------------------------------------------------------------------
  351. #pragma mark === Table View ===
  352. #pragma --------------------------------------------------------------------------------------------
  353. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  354. {
  355. NSString *sectionName;
  356. switch (section)
  357. {
  358. case 1: {
  359. sectionName = NSLocalizedString(@"_favorite_offline_footer_", nil);
  360. }
  361. break;
  362. case 2: {
  363. sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
  364. }
  365. break;
  366. case 5: {
  367. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:appDelegate.activeAccount];
  368. NSString *versionServer = capabilities.versionString;
  369. NSString *versionApp = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  370. NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudServer, versionServer];
  371. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudiOS, versionApp];
  372. NSString *nameSlogan = [NSString stringWithFormat:@"%@ - %@", capabilities.themingName, capabilities.themingSlogan];
  373. sectionName = [NSString stringWithFormat:@"%@\n\n%@\n%@", versionNextcloudiOS, versionNextcloud, nameSlogan];
  374. }
  375. break;
  376. }
  377. return sectionName;
  378. }
  379. #pragma --------------------------------------------------------------------------------------------
  380. #pragma mark === BKPasscodeViewController ===
  381. #pragma --------------------------------------------------------------------------------------------
  382. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  383. {
  384. [aViewController dismissViewControllerAnimated:YES completion:nil];
  385. switch (aViewController.type) {
  386. case BKPasscodeViewControllerNewPasscodeType: {
  387. // enable passcode
  388. [CCUtility setBlockCode:aPasscode];
  389. }
  390. break;
  391. case BKPasscodeViewControllerCheckPasscodeType: {
  392. // disable passcode
  393. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  394. [CCUtility setBlockCode:@""];
  395. [[NCManageDatabase sharedInstance] setAllDirectoryUnLockWithAccount:appDelegate.activeAccount];
  396. [appDelegate.activeMain.tableView reloadData];
  397. }
  398. // change simply
  399. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  400. // disable passcode
  401. [CCUtility setBlockCode:@""];
  402. [[NCManageDatabase sharedInstance] setAllDirectoryUnLockWithAccount:appDelegate.activeAccount];
  403. [appDelegate.activeMain.tableView reloadData];
  404. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  405. // Call new passcode
  406. [self bloccoPassword];
  407. }
  408. }
  409. break;
  410. default:
  411. break;
  412. }
  413. [self reloadForm];
  414. }
  415. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  416. {
  417. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  418. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  419. self.lockUntilDate = nil;
  420. self.failedAttempts = 0;
  421. aResultHandler(YES);
  422. } else aResultHandler(NO);
  423. }
  424. }
  425. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  426. {
  427. self.failedAttempts++;
  428. if (self.failedAttempts > 5) {
  429. NSTimeInterval timeInterval = 60;
  430. if (self.failedAttempts > 6) {
  431. NSUInteger multiplier = self.failedAttempts - 6;
  432. timeInterval = (5 * 60) * multiplier;
  433. if (timeInterval > 3600 * 24) {
  434. timeInterval = 3600 * 24;
  435. }
  436. }
  437. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  438. }
  439. }
  440. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  441. {
  442. return self.failedAttempts;
  443. }
  444. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  445. {
  446. return self.lockUntilDate;
  447. }
  448. - (void)passcodeViewCloseButtonPressed:(id)sender
  449. {
  450. [self dismissViewControllerAnimated:YES completion:nil];
  451. }
  452. @end