CCSettings.m 31 KB

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