CCSettings.m 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  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 tableView:self.tableView collectionView:nil];
  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. // detect Dark Mode
  271. if (@available(iOS 12.0, *)) {
  272. appDelegate.preferredUserInterfaceStyle = self.traitCollection.userInterfaceStyle;
  273. if (appDelegate.preferredUserInterfaceStyle == UIUserInterfaceStyleDark) {
  274. [CCUtility setDarkMode:YES];
  275. } else {
  276. [CCUtility setDarkMode:NO];
  277. }
  278. [appDelegate settingDarkMode];
  279. }
  280. } else {
  281. [CCUtility setDarkModeDetect:false];
  282. [appDelegate settingDarkMode];
  283. [appDelegate aspectNavigationControllerBar:self.navigationController.navigationBar online:[appDelegate.reachability isReachable] hidden:NO];
  284. [appDelegate aspectTabBar:self.tabBarController.tabBar hidden:NO];
  285. self.tableView.backgroundColor = NCBrandColor.sharedInstance.backgroundView;
  286. [self initializeForm];
  287. [self reloadForm];
  288. }
  289. }
  290. }
  291. - (void)changeSimplyPassword
  292. {
  293. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  294. viewController.delegate = self;
  295. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  296. viewController.fromType = CCBKPasscodeFromSimply;
  297. viewController.title = NSLocalizedString(@"_change_simply_passcode_", nil);
  298. viewController.inputViewTitlePassword = YES;
  299. if ([CCUtility getSimplyBlockCode]) {
  300. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  301. viewController.passcodeInputView.maximumLength = 6;
  302. } else {
  303. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  304. viewController.passcodeInputView.maximumLength = 64;
  305. }
  306. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  307. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  308. viewController.touchIDManager = touchIDManager;
  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. }
  315. - (void)bloccoPassword
  316. {
  317. // ATTIVAZIONE LOCK PASSWORD
  318. if ([[CCUtility getBlockCode] length] == 0) {
  319. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  320. viewController.delegate = self;
  321. viewController.type = BKPasscodeViewControllerNewPasscodeType;
  322. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  323. viewController.inputViewTitlePassword = YES;
  324. if ([CCUtility getSimplyBlockCode]) {
  325. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  326. viewController.passcodeInputView.maximumLength = 6;
  327. } else {
  328. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  329. viewController.passcodeInputView.maximumLength = 64;
  330. }
  331. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  332. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  333. viewController.touchIDManager = touchIDManager;
  334. viewController.title = NSLocalizedString(@"_passcode_activate_", nil);
  335. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  336. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  337. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  338. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  339. [self presentViewController:navigationController animated:YES completion:nil];
  340. } else {
  341. // OFF LOCK PASSWORD
  342. CCBKPasscode *viewController = [[CCBKPasscode alloc] initWithNibName:nil bundle:nil];
  343. viewController.delegate = self;
  344. viewController.type = BKPasscodeViewControllerCheckPasscodeType;
  345. viewController.fromType = CCBKPasscodeFromSettingsPasscode;
  346. viewController.inputViewTitlePassword = YES;
  347. if ([CCUtility getSimplyBlockCode]) {
  348. viewController.passcodeStyle = BKPasscodeInputViewNumericPasscodeStyle;
  349. viewController.passcodeInputView.maximumLength = 6;
  350. } else {
  351. viewController.passcodeStyle = BKPasscodeInputViewNormalPasscodeStyle;
  352. viewController.passcodeInputView.maximumLength = 64;
  353. }
  354. BKTouchIDManager *touchIDManager = [[BKTouchIDManager alloc] initWithKeychainServiceName:k_serviceShareKeyChain];
  355. touchIDManager.promptText = NSLocalizedString(@"_scan_fingerprint_", nil);
  356. viewController.touchIDManager = touchIDManager;
  357. viewController.title = NSLocalizedString(@"_disabling_passcode_", nil);
  358. viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(passcodeViewCloseButtonPressed:)];
  359. viewController.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
  360. UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  361. navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
  362. [self presentViewController:navigationController animated:YES completion:nil];
  363. }
  364. }
  365. - (void)synchronizeFavorites
  366. {
  367. NSArray *metadatas = [[NCManageDatabase sharedInstance] getMetadatasWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND favorite == true", appDelegate.activeAccount] sorted:nil ascending:NO];
  368. for (tableMetadata *metadata in metadatas) {
  369. if (metadata.directory) {
  370. NSString *serverUrl = [CCUtility stringAppendServerUrl:metadata.serverUrl addFileName:metadata.fileName];
  371. NSString *serverUrlBeginWith = serverUrl;
  372. if (![serverUrl hasSuffix:@"/"])
  373. serverUrlBeginWith = [serverUrl stringByAppendingString:@"/"];
  374. NSArray *directories = [[NCManageDatabase sharedInstance] getTablesDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND (serverUrl == %@ OR serverUrl BEGINSWITH %@)", appDelegate.activeAccount, serverUrl, serverUrlBeginWith] sorted:@"serverUrl" ascending:true];
  375. for (tableDirectory *directory in directories)
  376. [[NCManageDatabase sharedInstance] clearDateReadWithServerUrl:directory.serverUrl account:appDelegate.activeAccount];
  377. }
  378. }
  379. [appDelegate.activeFavorites listingFavorites];
  380. }
  381. #pragma --------------------------------------------------------------------------------------------
  382. #pragma mark === Table View ===
  383. #pragma --------------------------------------------------------------------------------------------
  384. - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
  385. {
  386. NSString *sectionName;
  387. switch (section)
  388. {
  389. case 1: {
  390. sectionName = NSLocalizedString(@"_favorite_offline_footer_", nil);
  391. }
  392. break;
  393. case 2: {
  394. sectionName = NSLocalizedString(@"_lock_protection_no_screen_footer_", nil);
  395. }
  396. break;
  397. case 5: {
  398. tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:appDelegate.activeAccount];
  399. NSString *versionServer = capabilities.versionString;
  400. NSString *versionApp = [NSString stringWithFormat:@"%@.%@", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"], [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]];
  401. NSString *versionNextcloud = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudServer, versionServer];
  402. NSString *versionNextcloudiOS = [NSString stringWithFormat:[NCBrandOptions sharedInstance].textCopyrightNextcloudiOS, versionApp];
  403. NSString *nameSlogan = [NSString stringWithFormat:@"%@ - %@", capabilities.themingName, capabilities.themingSlogan];
  404. sectionName = [NSString stringWithFormat:@"%@\n\n%@\n%@", versionNextcloudiOS, versionNextcloud, nameSlogan];
  405. }
  406. break;
  407. }
  408. return sectionName;
  409. }
  410. #pragma --------------------------------------------------------------------------------------------
  411. #pragma mark === Mail ===
  412. #pragma --------------------------------------------------------------------------------------------
  413. - (void) mailComposeController:(MFMailComposeViewController *)vc didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
  414. {
  415. switch (result)
  416. {
  417. case MFMailComposeResultCancelled:
  418. [appDelegate messageNotification:@"_info_" description:@"_mail_deleted_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  419. break;
  420. case MFMailComposeResultSaved:
  421. [appDelegate messageNotification:@"_info_" description:@"_mail_saved_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  422. break;
  423. case MFMailComposeResultSent:
  424. [appDelegate messageNotification:@"_info_" description:@"_mail_sent_" visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeSuccess errorCode:error.code];
  425. break;
  426. case MFMailComposeResultFailed: {
  427. NSString *msg = [NSString stringWithFormat:NSLocalizedString(@"_mail_failure_", nil), [error localizedDescription]];
  428. [appDelegate messageNotification:@"_error_" description:msg visible:YES delay:k_dismissAfterSecond type:TWMessageBarMessageTypeError errorCode:error.code];
  429. }
  430. break;
  431. default:
  432. break;
  433. }
  434. // Close the Mail Interface
  435. [self dismissViewControllerAnimated:YES completion:NULL];
  436. }
  437. - (void)sendMail:(XLFormRowDescriptor *)sender
  438. {
  439. if ([MFMailComposeViewController canSendMail]) {
  440. // Email Subject
  441. NSString *emailTitle = NSLocalizedString(@"_information_req_", nil);
  442. // Email Content
  443. NSString *messageBody;
  444. // Email Recipents
  445. NSArray *toRecipents;
  446. 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]];
  447. toRecipents = [NSArray arrayWithObject:[NCBrandOptions sharedInstance].mailMe];
  448. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  449. mc.mailComposeDelegate = self;
  450. [mc setSubject:emailTitle];
  451. [mc setMessageBody:messageBody isHTML:NO];
  452. [mc setToRecipients:toRecipents];
  453. // Present mail view controller on screen
  454. [self presentViewController:mc animated:YES completion:NULL];
  455. }
  456. }
  457. #pragma --------------------------------------------------------------------------------------------
  458. #pragma mark === BKPasscodeViewController ===
  459. #pragma --------------------------------------------------------------------------------------------
  460. - (void)passcodeViewController:(CCBKPasscode *)aViewController didFinishWithPasscode:(NSString *)aPasscode
  461. {
  462. [aViewController dismissViewControllerAnimated:YES completion:nil];
  463. switch (aViewController.type) {
  464. case BKPasscodeViewControllerNewPasscodeType: {
  465. // enable passcode
  466. [CCUtility setBlockCode:aPasscode];
  467. }
  468. break;
  469. case BKPasscodeViewControllerCheckPasscodeType: {
  470. // disable passcode
  471. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode) {
  472. [CCUtility setBlockCode:@""];
  473. [[NCManageDatabase sharedInstance] setAllDirectoryUnLockWithAccount:appDelegate.activeAccount];
  474. [appDelegate.activeMain.tableView reloadData];
  475. }
  476. // change simply
  477. if (aViewController.fromType == CCBKPasscodeFromSimply) {
  478. // disable passcode
  479. [CCUtility setBlockCode:@""];
  480. [[NCManageDatabase sharedInstance] setAllDirectoryUnLockWithAccount:appDelegate.activeAccount];
  481. [appDelegate.activeMain.tableView reloadData];
  482. [CCUtility setSimplyBlockCode:![CCUtility getSimplyBlockCode]];
  483. // Call new passcode
  484. [self bloccoPassword];
  485. }
  486. }
  487. break;
  488. default:
  489. break;
  490. }
  491. [self reloadForm];
  492. }
  493. - (void)passcodeViewController:(CCBKPasscode *)aViewController authenticatePasscode:(NSString *)aPasscode resultHandler:(void (^)(BOOL))aResultHandler
  494. {
  495. if (aViewController.fromType == CCBKPasscodeFromSettingsPasscode || aViewController.fromType == CCBKPasscodeFromSimply) {
  496. if ([aPasscode isEqualToString:[CCUtility getBlockCode]]) {
  497. self.lockUntilDate = nil;
  498. self.failedAttempts = 0;
  499. aResultHandler(YES);
  500. } else aResultHandler(NO);
  501. }
  502. }
  503. - (void)passcodeViewControllerDidFailAttempt:(CCBKPasscode *)aViewController
  504. {
  505. self.failedAttempts++;
  506. if (self.failedAttempts > 5) {
  507. NSTimeInterval timeInterval = 60;
  508. if (self.failedAttempts > 6) {
  509. NSUInteger multiplier = self.failedAttempts - 6;
  510. timeInterval = (5 * 60) * multiplier;
  511. if (timeInterval > 3600 * 24) {
  512. timeInterval = 3600 * 24;
  513. }
  514. }
  515. self.lockUntilDate = [NSDate dateWithTimeIntervalSinceNow:timeInterval];
  516. }
  517. }
  518. - (NSUInteger)passcodeViewControllerNumberOfFailedAttempts:(CCBKPasscode *)aViewController
  519. {
  520. return self.failedAttempts;
  521. }
  522. - (NSDate *)passcodeViewControllerLockUntilDate:(CCBKPasscode *)aViewController
  523. {
  524. return self.lockUntilDate;
  525. }
  526. - (void)passcodeViewCloseButtonPressed:(id)sender
  527. {
  528. [self dismissViewControllerAnimated:YES completion:nil];
  529. }
  530. @end