CCSettings.m 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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. /*
  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. }
  105. */
  106. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"darkMode" rowType:XLFormRowDescriptorTypeBooleanSwitch title:[NSString stringWithFormat:@"%@ (beta)", NSLocalizedString(@"_dark_mode_", nil)]];
  107. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  108. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"themeLightDark"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  109. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  110. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  111. if (@available(iOS 13.0, *)) {
  112. row.hidden = [NSString stringWithFormat:@"$%@==1", @"darkModeDetect"];
  113. }
  114. [section addFormRow:row];
  115. // Section : E2EEncryption --------------------------------------------------------------
  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. // Section Advanced -------------------------------------------------
  128. section = [XLFormSectionDescriptor formSection];
  129. [form addFormSection:section];
  130. // Advanced
  131. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"advanced" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_advanced_", nil)];
  132. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  133. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  134. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  135. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settings"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  136. row.action.viewControllerClass = [CCAdvanced class];
  137. [section addFormRow:row];
  138. // Section : INFORMATION ------------------------------------------------
  139. section = [XLFormSectionDescriptor formSectionWithTitle:NSLocalizedString(@"_information_", nil)];
  140. [form addFormSection:section];
  141. // Acknowledgements
  142. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"buttonLeftAligned" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_acknowledgements_", nil)];
  143. row.cellConfigAtConfigure[@"backgroundColor"] = NCBrandColor.sharedInstance.backgroundView;
  144. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0] forKey:@"textLabel.font"];
  145. [row.cellConfig setObject:@(NSTextAlignmentLeft) forKey:@"textLabel.textAlignment"];
  146. [row.cellConfig setObject:NCBrandColor.sharedInstance.textView forKey:@"textLabel.textColor"];
  147. [row.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"acknowledgements"] width:50 height:50 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  148. row.action.formBlock = ^(XLFormRowDescriptor * sender){
  149. [self performSegueWithIdentifier:@"AcknowledgementsSegue" sender:sender];
  150. [self deselectFormRow:sender];
  151. };
  152. [section addFormRow:row];
  153. self.tableView.showsVerticalScrollIndicator = NO;
  154. self.form = form;
  155. }
  156. - (void)viewDidLoad
  157. {
  158. [super viewDidLoad];
  159. appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  160. // changeTheming
  161. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheming) name:@"changeTheming" object:nil];
  162. [self changeTheming];
  163. }
  164. - (void)changeTheming
  165. {
  166. [appDelegate changeTheming:self tableView:self.tableView collectionView:nil form:true];
  167. [self initializeForm];
  168. [self reloadForm];
  169. }
  170. #pragma --------------------------------------------------------------------------------------------
  171. #pragma mark === Chiamate dal Form ===
  172. #pragma --------------------------------------------------------------------------------------------
  173. - (void)reloadForm
  174. {
  175. self.form.delegate = nil;
  176. // ------------------------------------------------------------------
  177. XLFormRowDescriptor *rowBloccoPasscode = [self.form formRowWithTag:@"bloccopasscode"];
  178. XLFormRowDescriptor *rowSimplyPasscode = [self.form formRowWithTag:@"simplypasscode"];
  179. XLFormRowDescriptor *rowOnlyLockDir = [self.form formRowWithTag:@"onlylockdir"];
  180. XLFormRowDescriptor *rowFavoriteOffline = [self.form formRowWithTag:@"favoriteoffline"];
  181. XLFormRowDescriptor *rowDarkModeDetect = [self.form formRowWithTag:@"darkModeDetect"];
  182. XLFormRowDescriptor *rowDarkMode = [self.form formRowWithTag:@"darkMode"];
  183. // ------------------------------------------------------------------
  184. if ([[CCUtility getBlockCode] length]) {
  185. rowBloccoPasscode.title = NSLocalizedString(@"_lock_active_", nil);
  186. [rowBloccoPasscode.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeYES"] multiplier:2 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  187. } else {
  188. rowBloccoPasscode.title = NSLocalizedString(@"_lock_not_active_", nil);
  189. [rowBloccoPasscode.cellConfig setObject:[CCGraphics changeThemingColorImage:[UIImage imageNamed:@"settingsPasscodeNO"] multiplier:2 color:NCBrandColor.sharedInstance.icon] forKey:@"imageView.image"];
  190. }
  191. if ([CCUtility getSimplyBlockCode]) [rowSimplyPasscode setValue:@1]; else [rowSimplyPasscode setValue:@0];
  192. if ([CCUtility getOnlyLockDir]) [rowOnlyLockDir setValue:@1]; else [rowOnlyLockDir setValue:@0];
  193. if ([CCUtility getFavoriteOffline]) [rowFavoriteOffline setValue:@1]; else [rowFavoriteOffline setValue:@0];
  194. if ([CCUtility getDarkModeDetect]) [rowDarkModeDetect setValue:@1]; else [rowDarkModeDetect setValue:@0];
  195. if ([CCUtility getDarkMode]) [rowDarkMode setValue:@1]; else [rowDarkMode setValue:@0];
  196. // -----------------------------------------------------------------
  197. [self.tableView reloadData];
  198. self.form.delegate = self;
  199. }
  200. - (void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  201. {
  202. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  203. if ([rowDescriptor.tag isEqualToString:@"onlylockdir"]) {
  204. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  205. [CCUtility setOnlyLockDir:true];
  206. } else {
  207. [CCUtility setOnlyLockDir:false];
  208. }
  209. }
  210. if ([rowDescriptor.tag isEqualToString:@"simplypasscode"]) {
  211. if ([[CCUtility getBlockCode] length] == 0)
  212. [CCUtility setSimplyBlockCode:[[rowDescriptor.value valueData] boolValue]];
  213. else
  214. [self changeSimplyPassword];
  215. }
  216. if ([rowDescriptor.tag isEqualToString:@"favoriteoffline"]) {
  217. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  218. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_continue_request_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
  219. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_ok_", nil) style:UIAlertActionStyleDestructive handler:^(UIAlertAction *action) {
  220. [CCUtility setFavoriteOffline:true];
  221. [self synchronizeFavorites];
  222. }]];
  223. [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_cancel_", nil) style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
  224. [self reloadForm];
  225. }]];
  226. alertController.popoverPresentationController.sourceView = self.view;
  227. NSIndexPath *indexPath = [self.form indexPathOfFormRow:rowDescriptor];
  228. CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
  229. alertController.popoverPresentationController.sourceRect = CGRectOffset(cellRect, -self.tableView.contentOffset.x, -self.tableView.contentOffset.y);
  230. [self presentViewController:alertController animated:YES completion:nil];
  231. } else {
  232. [CCUtility setFavoriteOffline:false];
  233. }
  234. }
  235. if ([rowDescriptor.tag isEqualToString:@"darkMode"]) {
  236. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  237. [CCUtility setDarkMode:true];
  238. } else {
  239. [CCUtility setDarkMode:false];
  240. }
  241. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"changeTheming" object:nil];
  242. }
  243. if ([rowDescriptor.tag isEqualToString:@"darkModeDetect"]) {
  244. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  245. [CCUtility setDarkModeDetect:true];
  246. // detect Dark Mode
  247. if (@available(iOS 12.0, *)) {
  248. appDelegate.preferredUserInterfaceStyle = self.traitCollection.userInterfaceStyle;
  249. if (appDelegate.preferredUserInterfaceStyle == UIUserInterfaceStyleDark) {
  250. [CCUtility setDarkMode:YES];
  251. } else {
  252. [CCUtility setDarkMode:NO];
  253. }
  254. }
  255. } else {
  256. [CCUtility setDarkModeDetect:false];
  257. }
  258. [[NSNotificationCenter defaultCenter] postNotificationOnMainThreadName:@"changeTheming" object:nil];
  259. }
  260. }
  261. - (void)changeSimplyPassword
  262. {
  263. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  264. viewController.delegate = self;
  265. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  266. viewController.fromType = CCBKPasscodeFromSimply;
  267. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  268. viewController.inputViewTitlePassword = YES;
  269. if ([CCUtility getSimplyBlockCode]) {
  270. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  271. viewController.passcodeInputView.maximumLength = 6;
  272. } else {
  273. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  274. viewController.passcodeInputView.maximumLength = 64;
  275. }
  276. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  277. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  278. viewController.touchIDManager = touchIDManager;
  279. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  280. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  281. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  282. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  283. [self presentViewController:navigationController animated:YES completion:nil];
  284. }
  285. - (void)bloccoPassword
  286. {
  287. // ATTIVAZIONE LOCK PASSWORD
  288. if ([[CCUtility getBlockCode] length] == 0) {
  289. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  290. viewController.delegate = self;
  291. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  292. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  293. viewController.inputViewTitlePassword = YES;
  294. if ([CCUtility getSimplyBlockCode]) {
  295. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  296. viewController.passcodeInputView.maximumLength = 6;
  297. } else {
  298. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  299. viewController.passcodeInputView.maximumLength = 64;
  300. }
  301. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  302. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  303. viewController.touchIDManager = touchIDManager;
  304. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  305. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  306. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  307. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  308. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  309. [self presentViewController:navigationController animated:YES completion:nil];
  310. } else {
  311. // OFF LOCK PASSWORD
  312. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  313. viewController.delegate = self;
  314. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  315. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  316. viewController.inputViewTitlePassword = YES;
  317. if ([CCUtility getSimplyBlockCode]) {
  318. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  319. viewController.passcodeInputView.maximumLength = 6;
  320. } else {
  321. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  322. viewController.passcodeInputView.maximumLength = 64;
  323. }
  324. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  325. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  326. viewController.touchIDManager = touchIDManager;
  327. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  328. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  329. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  330. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  331. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  332. [self presentViewController:navigationController animated:YES completion:nil];
  333. }
  334. }
  335. - (void)synchronizeFavorites
  336. {
  337. NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND favorite == true", appDelegate.activeAccount] sorted:nil ascending:NO];
  338. for (tableMetadata *metadata in metadatas) {
  339. if (metadata.directory) {
  340. NSString *serverUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
  341. NSString *serverUrlBeginWith = serverUrl;
  342. if (![serverUrl hasSuffix:@"/"])
  343. serverUrlBeginWith = [serverUrl stringByAppendingString:@"/"];
  344. NSArray *directories = [[NCManageDatabase sharedInstance] getTablesDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (serverUrl == %@ OR serverUrl BEGINSWITH %@)", appDelegate.activeAccount, serverUrl, serverUrlBeginWith] sorted:@"serverUrl" ascending:true];
  345. for (tableDirectory *directory in directories)
  346. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:directory.serverUrl account:appDelegate.activeAccount];
  347. }
  348. }
  349. [appDelegate.activeFavorites listingFavorites];
  350. }
  351. #pragma --------------------------------------------------------------------------------------------
  352. #pragma mark === Table View ===
  353. #pragma --------------------------------------------------------------------------------------------
  354. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  355. {
  356. NSString *sectionName;
  357. switch (section)
  358. {
  359. case 1: {
  360. sectionName = NSLocalizedString(@"_favorite_offline_footer_", nil);
  361. }
  362. break;
  363. case 2: {
  364. sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
  365. }
  366. break;
  367. case 5: {
  368. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:appDelegate.activeAccount];
  369. NSString *versionServer = capabilities.versionString;
  370. NSString *versionApp = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  371. NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudServer, versionServer];
  372. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudiOS, versionApp];
  373. NSString *nameSlogan = [NSString stringWithFormat:@"%@ - %@", capabilities.themingName, capabilities.themingSlogan];
  374. sectionName = [NSString stringWithFormat:@"%@\n\n%@\n%@", versionNextcloudiOS, versionNextcloud, nameSlogan];
  375. }
  376. break;
  377. }
  378. return sectionName;
  379. }
  380. #pragma --------------------------------------------------------------------------------------------
  381. #pragma mark === Mail ===
  382. #pragma --------------------------------------------------------------------------------------------
  383. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  384. {
  385. switch (result)
  386. {
  387. case MFMailComposeResultCancelled:
  388. [appDelegate messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  389. break;
  390. case MFMailComposeResultSaved:
  391. [appDelegate messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  392. break;
  393. case MFMailComposeResultSent:
  394. [appDelegate messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  395. break;
  396. case MFMailComposeResultFailed: {
  397. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  398. [appDelegate messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  399. }
  400. break;
  401. default:
  402. break;
  403. }
  404. // Close the Mail Interface
  405. [self dismissViewControllerAnimated:YES completion:NULL];
  406. }
  407. - (void)sendMail:(XLFormRowDescriptor *)sender
  408. {
  409. if ([MFMailComposeViewController canSendMail]) {
  410. // Email Subject
  411. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  412. // Email Content
  413. NSString *messageBody;
  414. // Email Recipents
  415. NSArray *toRecipents;
  416. messageBody = [NSString stringWithFormat:@"%@\n\n\n\n%@ Version %@ (%@) - iOS %@", NSLocalizedString(@"_write_in_english_", nil), [NCBrandOptions sharedInstance].brand, [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], [[UIDevice currentDevice] systemVersion]];
  417. toRecipents = [NSArray arrayWithObject:[NCBrandOptions sharedInstance].mailMe];
  418. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  419. mc.mailComposeDelegate = self;
  420. [mc setSubject:emailTitle];
  421. [mc setMessageBody:messageBody isHTML:NO];
  422. [mc setToRecipients:toRecipents];
  423. // Present mail view controller on screen
  424. [self presentViewController:mc animated:YES completion:NULL];
  425. }
  426. }
  427. #pragma --------------------------------------------------------------------------------------------
  428. #pragma mark === BKPasscodeViewController ===
  429. #pragma --------------------------------------------------------------------------------------------
  430. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  431. {
  432. [aViewController dismissViewControllerAnimated:YES completion:nil];
  433. switch (aViewController.type) {
  434. case BKPasscodeViewControllerNewPasscodeType: {
  435. // enable passcode
  436. [CCUtility setBlockCode:aPasscode];
  437. }
  438. break;
  439. case BKPasscodeViewControllerCheckPasscodeType: {
  440. // disable passcode
  441. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  442. [CCUtility setBlockCode:@""];
  443. [[NCManageDatabase sharedInstance] setAllDirectoryUnLockWithAccount:appDelegate.activeAccount];
  444. [appDelegate.activeMain.tableView reloadData];
  445. }
  446. // change simply
  447. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  448. // disable passcode
  449. [CCUtility setBlockCode:@""];
  450. [[NCManageDatabase sharedInstance] setAllDirectoryUnLockWithAccount:appDelegate.activeAccount];
  451. [appDelegate.activeMain.tableView reloadData];
  452. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  453. // Call new passcode
  454. [self bloccoPassword];
  455. }
  456. }
  457. break;
  458. default:
  459. break;
  460. }
  461. [self reloadForm];
  462. }
  463. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  464. {
  465. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  466. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  467. self.lockUntilDate = nil;
  468. self.failedAttempts = 0;
  469. aResultHandler(YES);
  470. } else aResultHandler(NO);
  471. }
  472. }
  473. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  474. {
  475. self.failedAttempts++;
  476. if (self.failedAttempts > 5) {
  477. NSTimeInterval timeInterval = 60;
  478. if (self.failedAttempts > 6) {
  479. NSUInteger multiplier = self.failedAttempts - 6;
  480. timeInterval = (5 * 60) * multiplier;
  481. if (timeInterval > 3600 * 24) {
  482. timeInterval = 3600 * 24;
  483. }
  484. }
  485. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  486. }
  487. }
  488. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  489. {
  490. return self.failedAttempts;
  491. }
  492. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  493. {
  494. return self.lockUntilDate;
  495. }
  496. - (void)passcodeViewCloseButtonPressed:(id)sender
  497. {
  498. [self dismissViewControllerAnimated:YES completion:nil];
  499. }
  500. @end