CCSettings.m 28 KB

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