VLCSettingsController.m 2.84 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 16
#import "IASKAppSettingsViewController.h"
#import "PAPasscodeViewController.h"
17
#import <DropboxSDK/DropboxSDK.h>
18

19 20 21
@interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
@end

22
@implementation VLCSettingsController
Felix Paul Kühne's avatar
Felix Paul Kühne committed
23

24
- (id)init
Felix Paul Kühne's avatar
Felix Paul Kühne committed
25
{
26 27 28 29
    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
30 31 32
    return self;
}

33
- (void)dealloc
Felix Paul Kühne's avatar
Felix Paul Kühne committed
34
{
35
    [[NSNotificationCenter defaultCenter] removeObserver:self];
Felix Paul Kühne's avatar
Felix Paul Kühne committed
36 37
}

38
- (void)settingDidChange:(NSNotification*)notification
39
{
40
    if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
41
        BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
42

43 44 45
        if (passcodeOn) {
            PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
            passcodeLockController.delegate = self;
46
            [self.viewController presentModalViewController:passcodeLockController animated:YES];
47 48
        }
    }
49 50
}

51 52
- (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
{
53
    [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
54 55
}

56
- (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier {
57
    if ([specifier.key isEqualToString:@"UnlinkDropbox"])
58 59 60
        [[DBSession sharedSession] unlinkAll];
}

61 62 63 64
#pragma mark - PAPasscode delegate

- (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
{
65 66 67
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
    [defaults synchronize];
68 69 70 71 72 73
    [controller dismissModalViewControllerAnimated:YES];
}

- (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
74
    [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
75 76 77 78
    [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
    [defaults synchronize];
    VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
    appDelegate.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300];
79

80 81 82
    [controller dismissModalViewControllerAnimated:YES];
}

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