VLCSettingsController.m 2.52 KB
Newer Older
Felix Paul Kühne's avatar
Felix Paul Kühne committed
1 2 3 4
//
//  VLCSettingsViewController.m
//  VLC for iOS
//
5
//  Created by Felix Paul Kühne on 23.05.13.
Felix Paul Kühne's avatar
Felix Paul Kühne committed
6 7
//  Copyright (c) 2013 VideoLAN. All rights reserved.
//
8 9
//  Refer to the COPYING file of the official project for license.
//
Felix Paul Kühne's avatar
Felix Paul Kühne committed
10

11
#import "VLCSettingsController.h"
Felix Paul Kühne's avatar
Felix Paul Kühne committed
12
#import "VLCAppDelegate.h"
13
#import "VLCPlaylistViewController.h"
14
#import "IASKSettingsReader.h"
15
#import <DropboxSDK/DropboxSDK.h>
16

17
@implementation VLCSettingsController
Felix Paul Kühne's avatar
Felix Paul Kühne committed
18

19
- (id)init
Felix Paul Kühne's avatar
Felix Paul Kühne committed
20
{
21 22 23 24
    self = [super init];
    if (self)
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];

Felix Paul Kühne's avatar
Felix Paul Kühne committed
25 26 27
    return self;
}

28
- (void)dealloc
Felix Paul Kühne's avatar
Felix Paul Kühne committed
29
{
30
    [[NSNotificationCenter defaultCenter] removeObserver:self];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
31 32
}

33
- (void)settingDidChange:(NSNotification*)notification
34
{
35
    if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
36
        BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
37

38 39 40
        if (passcodeOn) {
            PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
            passcodeLockController.delegate = self;
41
            [self.viewController presentModalViewController:passcodeLockController animated:YES];
42 43
        }
    }
44 45
}

46 47
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
{
48
    [self.viewController.navigationController dismissModalViewControllerAnimated:YES];
49 50
}

51
- (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier {
52
    if ([specifier.key isEqualToString:@"UnlinkDropbox"])
53 54 55
        [[DBSession sharedSession] unlinkAll];
}

56 57 58 59
#pragma mark - PAPasscode delegate

- (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
{
60 61 62
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
    [defaults synchronize];
63 64 65 66 67 68
    [controller dismissModalViewControllerAnimated:YES];
}

- (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
69
    [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
70 71 72 73
    [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
    [defaults synchronize];
    VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
    appDelegate.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300];
74

75 76 77
    [controller dismissModalViewControllerAnimated:YES];
}

Felix Paul Kühne's avatar
Felix Paul Kühne committed
78
@end