VLCSettingsController.m 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*****************************************************************************
  2. * VLCSettingsController.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2013 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Felix Paul Kühne <fkuehne # videolan.org>
  9. * Gleb Pinigin <gpinigin # gmail.com>
  10. * Carola Nitz <nitz.carola # googlemail.com>
  11. *
  12. * Refer to the COPYING file of the official project for license.
  13. *****************************************************************************/
  14. #import "VLCSettingsController.h"
  15. #import "VLCLibraryViewController.h"
  16. #import "IASKSettingsReader.h"
  17. #import "PAPasscodeViewController.h"
  18. #import "VLCKeychainCoordinator.h"
  19. @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
  20. @end
  21. @implementation VLCSettingsController
  22. - (instancetype)initWithStyle:(UITableViewStyle)style
  23. {
  24. self = [super initWithStyle:style];
  25. if (self) {
  26. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  27. }
  28. return self;
  29. }
  30. - (void)viewDidLoad
  31. {
  32. self.navigationItem.leftBarButtonItem = [UIBarButtonItem themedRevealMenuButtonWithTarget:self andSelector:@selector(dismiss:)];
  33. self.modalPresentationStyle = UIModalPresentationFormSheet;
  34. self.delegate = self;
  35. self.showDoneButton = NO;
  36. self.showCreditsFooter = NO;
  37. }
  38. - (void)viewWillAppear:(BOOL)animated
  39. {
  40. [super viewWillAppear:animated];
  41. [self filterCellsWithAnimation:NO];
  42. }
  43. - (void)filterCellsWithAnimation:(BOOL)shouldAnimate
  44. {
  45. NSMutableSet *hideKeys = [[NSMutableSet alloc] init];
  46. VLCKeychainCoordinator *keychainCoordinator = [VLCKeychainCoordinator defaultCoordinator];
  47. if (![keychainCoordinator passcodeLockEnabled])
  48. [hideKeys addObject:kVLCSettingPasscodeAllowTouchID];
  49. [self setHiddenKeys:hideKeys animated:shouldAnimate];
  50. }
  51. - (void)settingDidChange:(NSNotification*)notification
  52. {
  53. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  54. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  55. if (passcodeOn) {
  56. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  57. passcodeLockController.delegate = self;
  58. [self presentViewController:passcodeLockController animated:YES completion:nil];
  59. } else {
  60. [[VLCKeychainCoordinator defaultCoordinator] setPasscode:nil];
  61. [self didChangePasscodeStatus:NO];
  62. }
  63. }
  64. }
  65. - (void)didChangePasscodeStatus:(BOOL)passcodeEnabled
  66. {
  67. [self filterCellsWithAnimation:YES];
  68. BOOL spotlightEnabled = !passcodeEnabled;
  69. [[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:spotlightEnabled];
  70. if (!spotlightEnabled) {
  71. // delete whole index for VLC
  72. [[CSSearchableIndex defaultSearchableIndex] deleteAllSearchableItemsWithCompletionHandler:nil];
  73. }
  74. }
  75. #pragma mark - IASKSettings delegate
  76. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  77. {
  78. [[VLCSidebarController sharedInstance] toggleSidebar];
  79. }
  80. #pragma mark - PAPasscode delegate
  81. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  82. {
  83. [[VLCKeychainCoordinator defaultCoordinator] setPasscode:nil];
  84. //Set manually the value to NO to disable the UISwitch.
  85. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kVLCSettingPasscodeOnKey];
  86. [self didChangePasscodeStatus:NO];
  87. [controller dismissViewControllerAnimated:YES completion:nil];
  88. }
  89. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  90. {
  91. [[VLCKeychainCoordinator defaultCoordinator] setPasscode:controller.passcode];
  92. [self didChangePasscodeStatus:YES];
  93. [controller dismissViewControllerAnimated:YES completion:nil];
  94. }
  95. @end