VLCSettingsController.m 6.3 KB

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