CCSettings.m 33 KB

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