CCSettings.m 32 KB

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