CCSettings.m 30 KB

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