forked from videolan/vlc-ios
/
VLCSettingsController.m
212 lines (182 loc) · 7.98 KB
/
VLCSettingsController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*****************************************************************************
* VLCSettingsController.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2013 VideoLAN. All rights reserved.
* $Id$
*
* Authors: Felix Paul Kühne <fkuehne # videolan.org>
* Gleb Pinigin <gpinigin # gmail.com>
* Carola Nitz <nitz.carola # googlemail.com>
*
* Refer to the COPYING file of the official project for license.
*****************************************************************************/
#import "VLCSettingsController.h"
#import "IASKSettingsReader.h"
#import "PAPasscodeViewController.h"
#import <LocalAuthentication/LocalAuthentication.h>
#import "VLC_iOS-Swift.h"
NSString * const kVLCSectionTableHeaderViewIdentifier = @"VLCSectionTableHeaderViewIdentifier";
@interface VLCSettingsController ()<PAPasscodeViewControllerDelegate>
@end
@implementation VLCSettingsController
- (instancetype)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
[self setupUI];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
}
return self;
}
- (void)setupUI
{
self.title = NSLocalizedString(@"Settings", nil);
self.tabBarItem = [[UITabBarItem alloc] initWithTitle: NSLocalizedString(@"Settings", nil)
image: [UIImage imageNamed:@"Settings"]
selectedImage: [UIImage imageNamed:@"Settings"]];
self.tabBarItem.accessibilityIdentifier = VLCAccessibilityIdentifier.settings;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.modalPresentationStyle = UIModalPresentationFormSheet;
self.delegate = self;
self.showDoneButton = NO;
self.showCreditsFooter = NO;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"BUTTON_ABOUT", nil) style:UIBarButtonItemStylePlain target:self action:@selector(showAbout)];
self.navigationItem.leftBarButtonItem.accessibilityIdentifier = VLCAccessibilityIdentifier.about;
self.neverShowPrivacySettings = YES;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 100;
self.tableView.sectionHeaderHeight = UITableViewAutomaticDimension;
self.tableView.estimatedSectionHeaderHeight = 64;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.tableView registerClass:[VLCSectionTableHeaderView class] forHeaderFooterViewReuseIdentifier:kVLCSectionTableHeaderViewIdentifier];
[self themeDidChange];
}
- (void)themeDidChange
{
self.view.backgroundColor = PresentationTheme.current.colors.background;
[self setNeedsStatusBarAppearanceUpdate];
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self filterCellsWithAnimation:NO];
}
- (UIStatusBarStyle)preferredStatusBarStyle
{
return PresentationTheme.current.colors.statusBarStyle;
}
- (NSSet *)hiddenBiometryKeys
{
if (@available(iOS 11.0.1, *)) {
LAContext *laContext = [[LAContext alloc] init];
if ([laContext canEvaluatePolicy:LAPolicyDeviceOwnerAuthenticationWithBiometrics error:nil]) {
switch (laContext.biometryType) {
case LABiometryTypeFaceID:
return [NSSet setWithObject:kVLCSettingPasscodeAllowTouchID];
case LABiometryTypeTouchID:
return [NSSet setWithObject:kVLCSettingPasscodeAllowFaceID];
case LABiometryNone:
return [NSSet setWithObjects:kVLCSettingPasscodeAllowFaceID, kVLCSettingPasscodeAllowTouchID, nil];
}
}
return [NSSet setWithObjects:kVLCSettingPasscodeAllowFaceID, kVLCSettingPasscodeAllowTouchID, nil];
}
return [NSSet setWithObject:kVLCSettingPasscodeAllowFaceID];
}
- (void)filterCellsWithAnimation:(BOOL)shouldAnimate
{
NSMutableSet *hideKeys = [[NSMutableSet alloc] init];
if (![VLCKeychainCoordinator passcodeLockEnabled]) {
[hideKeys addObject:kVLCSettingPasscodeAllowTouchID];
[hideKeys addObject:kVLCSettingPasscodeAllowFaceID];
[self setHiddenKeys:hideKeys animated:shouldAnimate];
return;
}
[self setHiddenKeys:[self hiddenBiometryKeys] animated:shouldAnimate];
}
- (void)settingDidChange:(NSNotification*)notification
{
if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
if (passcodeOn) {
PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
passcodeLockController.delegate = self;
[self presentViewController:passcodeLockController animated:YES completion:nil];
} else {
[self updateForPasscode:nil];
}
}
if ([notification.object isEqual:kVLCSettingAppTheme]) {
BOOL darkTheme = [[notification.userInfo objectForKey:kVLCSettingAppTheme] boolValue];
PresentationTheme.current = darkTheme ? PresentationTheme.darkTheme : PresentationTheme.brightTheme;
[self themeDidChange];
}
}
- (void)updateUIAndCoreSpotlightForPasscodeSetting:(BOOL)passcodeOn
{
[self filterCellsWithAnimation:YES];
[[MLMediaLibrary sharedMediaLibrary] setSpotlightIndexingEnabled:!passcodeOn];
if (passcodeOn) {
// delete whole index for VLC
[[CSSearchableIndex defaultSearchableIndex] deleteAllSearchableItemsWithCompletionHandler:nil];
}
}
- (void)showAbout
{
VLCAboutViewController *aboutVC = [[VLCAboutViewController alloc] init];
UINavigationController *modalNavigationController = [[UINavigationController alloc] initWithRootViewController:aboutVC];
[self presentViewController:modalNavigationController animated:YES completion:nil];
}
#pragma mark - PAPasscode delegate
- (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
{
[self updateForPasscode:nil];
}
- (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
{
[self updateForPasscode:controller.passcode];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
IASKSpecifier *specifier = [self.settingsReader specifierForIndexPath:indexPath];
VLCSettingsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:specifier.type];
if (!cell) {
cell = [[VLCSettingsTableViewCell alloc] initWithReuseIdentifier:specifier.type target:self];
}
[cell configureWithSpecifier:specifier settingsValue:[self.settingsStore objectForKey:specifier.key]];
return cell;
}
- (void)updateForPasscode:(NSString *)passcode
{
NSError *error = nil;
[VLCKeychainCoordinator setPasscodeWithPasscode:passcode error:&error];
if (error == nil) {
if (passcode == nil) {
//Set manually the value to NO to disable the UISwitch.
[[NSUserDefaults standardUserDefaults] setBool:NO forKey:kVLCSettingPasscodeOnKey];
}
[self updateUIAndCoreSpotlightForPasscodeSetting:passcode != nil];
}
if ([self.navigationController.presentedViewController isKindOfClass:[PAPasscodeViewController class]]) {
[self.navigationController.presentedViewController dismissViewControllerAnimated:YES completion:nil];
}
}
#pragma mark - InAppSettings customization
- (UIView *)settingsViewController:(id<IASKViewController>)settingsViewController tableView:(UITableView *)tableView viewForHeaderForSection:(NSInteger)section
{
if (section == 0) {
return nil;
}
VLCSectionTableHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kVLCSectionTableHeaderViewIdentifier];
header.label.text = [self.settingsReader titleForSection:section];
return header;
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return nil;
}
@end