VLCSettingsController.m 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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 "IASKSettingsReader.h"
  16. #import "PAPasscodeViewController.h"
  17. #import <LocalAuthentication/LocalAuthentication.h>
  18. #import "VLC_iOS-Swift.h"
  19. @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate>
  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. [super viewDidLoad];
  33. self.modalPresentationStyle = UIModalPresentationFormSheet;
  34. self.delegate = self;
  35. self.showDoneButton = NO;
  36. self.showCreditsFooter = NO;
  37. self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_ABOUT", nil) style:UIBarButtonItemStylePlain target:self action:@selector(showAbout)];
  38. self.navigationItem.leftBarButtonItem.accessibilityIdentifier = VLCAccessibilityIdentifier.about;
  39. [self themeDidChange];
  40. }
  41. - (void)themeDidChange
  42. {
  43. self.view.backgroundColor = PresentationTheme.current.colors.settingsBackground;
  44. self.tableView.separatorColor = PresentationTheme.current.colors.separatorColor;
  45. [self.tableView reloadData];
  46. [self setNeedsStatusBarAppearanceUpdate];
  47. }
  48. - (void)viewWillAppear:(BOOL)animated
  49. {
  50. [super viewWillAppear:animated];
  51. [self filterCellsWithAnimation:NO];
  52. }
  53. - (UIStatusBarStyle)preferredStatusBarStyle
  54. {
  55. return PresentationTheme.current.colors.statusBarStyle;
  56. }
  57. - (NSSet *)hiddenBiometryKeys
  58. {
  59. if (@available(iOS 11.0.1, *)) {
  60. LAContext *laContext = [[LAContext alloc] init];
  61. if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
  62. switch (laContext.biometryType) {
  63. case LABiometryTypeFaceID:
  64. return [NSSet setWithObject:kVLCSettingPasscodeAllowTouchID];
  65. case LABiometryTypeTouchID:
  66. return [NSSet setWithObject:kVLCSettingPasscodeAllowFaceID];
  67. case LABiometryNone:
  68. return [NSSet setWithObjects:kVLCSettingPasscodeAllowFaceID, kVLCSettingPasscodeAllowTouchID, nil];
  69. }
  70. }
  71. return [NSSet setWithObjects:kVLCSettingPasscodeAllowFaceID, kVLCSettingPasscodeAllowTouchID, nil];
  72. }
  73. return [NSSet setWithObject:kVLCSettingPasscodeAllowFaceID];
  74. }
  75. - (void)filterCellsWithAnimation:(BOOL)shouldAnimate
  76. {
  77. NSMutableSet *hideKeys = [[NSMutableSet alloc] init];
  78. if (![VLCKeychainCoordinator passcodeLockEnabled]) {
  79. [hideKeys addObject:kVLCSettingPasscodeAllowTouchID];
  80. [hideKeys addObject:kVLCSettingPasscodeAllowFaceID];
  81. [self setHiddenKeys:hideKeys animated:shouldAnimate];
  82. return;
  83. }
  84. [self setHiddenKeys:[self hiddenBiometryKeys] animated:shouldAnimate];
  85. }
  86. - (void)settingDidChange:(NSNotification*)notification
  87. {
  88. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  89. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  90. if (passcodeOn) {
  91. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  92. passcodeLockController.delegate = self;
  93. [self presentViewController:passcodeLockController animated:YES completion:nil];
  94. } else {
  95. [self updateForPasscode:nil];
  96. }
  97. }
  98. if ([notification.object isEqual:kVLCSettingAppTheme]) {
  99. BOOL darkTheme = [[notification.userInfo objectForKey:kVLCSettingAppTheme] boolValue];
  100. PresentationTheme.current = darkTheme ? PresentationTheme.darkTheme : PresentationTheme.brightTheme;
  101. [self themeDidChange];
  102. }
  103. }
  104. - (void)updateUIAndCoreSpotlightForPasscodeSetting:(BOOL)passcodeOn
  105. {
  106. [self filterCellsWithAnimation:YES];
  107. [[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:!passcodeOn];
  108. if (passcodeOn) {
  109. // delete whole index for VLC
  110. [[CSSearchableIndex defaultSearchableIndex] deleteAllSearchableItemsWithCompletionHandler:nil];
  111. }
  112. }
  113. - (void)showAbout
  114. {
  115. VLCAboutViewController *aboutVC = [[VLCAboutViewController alloc] init];
  116. UINavigationController *modalNavigationController = [[UINavigationController alloc] initWithRootViewController:aboutVC];
  117. [self presentViewController:modalNavigationController animated:YES completion:nil];
  118. }
  119. #pragma mark - PAPasscode delegate
  120. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  121. {
  122. [self updateForPasscode:nil];
  123. }
  124. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  125. {
  126. [self updateForPasscode:controller.passcode];
  127. }
  128. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  129. {
  130. UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];
  131. cell.backgroundColor = PresentationTheme.current.colors.settingsCellBackground;
  132. cell.textLabel.textColor = PresentationTheme.current.colors.cellTextColor;
  133. cell.detailTextLabel.textColor = PresentationTheme.current.colors.cellDetailTextColor;
  134. return cell;
  135. }
  136. - (void)updateForPasscode:(NSString *)passcode
  137. {
  138. NSError *error = nil;
  139. [VLCKeychainCoordinator setPasscodeWithPasscode:passcode error:&error];
  140. if (error == nil) {
  141. if (passcode == nil) {
  142. //Set manually the value to NO to disable the UISwitch.
  143. [[NSUserDefaults standardUserDefaults] setBool:NO forKey:kVLCSettingPasscodeOnKey];
  144. }
  145. [self updateUIAndCoreSpotlightForPasscodeSetting:passcode != nil];
  146. }
  147. if ([self.navigationController.presentedViewController isKindOfClass:[PAPasscodeViewController class]]) {
  148. [self.navigationController.presentedViewController dismissViewControllerAnimated:YES completion:nil];
  149. }
  150. }
  151. @end