CCSettings.m 31 KB

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