VLCSettingsController.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "IASKAppSettingsViewController.h"
  18. #import "PAPasscodeViewController.h"
  19. #import "VLCKeychainCoordinator.h"
  20. @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
  21. @end
  22. @implementation VLCSettingsController
  23. - (id)init
  24. {
  25. self = [super init];
  26. if (self)
  27. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  28. return self;
  29. }
  30. - (void)dealloc
  31. {
  32. [[NSNotificationCenter defaultCenter] removeObserver:self];
  33. }
  34. - (void)willShow
  35. {
  36. [self filterCellsWithAnimation:NO];
  37. }
  38. - (void)filterCellsWithAnimation:(BOOL)shouldAnimate
  39. {
  40. NSMutableSet *hideKeys = [[NSMutableSet alloc] init];
  41. VLCKeychainCoordinator *keychainCoordinator = [VLCKeychainCoordinator defaultCoordinator];
  42. if (![keychainCoordinator passcodeLockEnabled])
  43. [hideKeys addObject:kVLCSettingPasscodeAllowTouchID];
  44. [self.viewController setHiddenKeys:hideKeys animated:shouldAnimate];
  45. }
  46. - (void)settingDidChange:(NSNotification*)notification
  47. {
  48. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  49. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  50. if (passcodeOn) {
  51. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  52. passcodeLockController.delegate = self;
  53. [self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
  54. } else {
  55. [[VLCKeychainCoordinator defaultCoordinator] setPasscode:nil];
  56. [self didChangePasscodeStatus:NO];
  57. }
  58. }
  59. }
  60. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  61. {
  62. [[VLCSidebarController sharedInstance] toggleSidebar];
  63. }
  64. - (void)didChangePasscodeStatus:(BOOL)passcodeEnabled
  65. {
  66. [self filterCellsWithAnimation:YES];
  67. BOOL spotlightEnabled = !passcodeEnabled;
  68. [[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:spotlightEnabled];
  69. if (!spotlightEnabled) {
  70. // delete whole index for VLC
  71. [[CSSearchableIndex defaultSearchableIndex] deleteAllSearchableItemsWithCompletionHandler:nil];
  72. }
  73. }
  74. #pragma mark - PAPasscode delegate
  75. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  76. {
  77. [[VLCKeychainCoordinator defaultCoordinator] setPasscode:nil];
  78. [self didChangePasscodeStatus:NO];
  79. [controller dismissViewControllerAnimated:YES completion:nil];
  80. }
  81. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  82. {
  83. [[VLCKeychainCoordinator defaultCoordinator] setPasscode:controller.passcode];
  84. [self didChangePasscodeStatus:YES];
  85. [controller dismissViewControllerAnimated:YES completion:nil];
  86. }
  87. @end