VLCSettingsController.m 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // VLCSettingsViewController.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 23.05.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. // Refer to the COPYING file of the official project for license.
  9. //
  10. #import "VLCSettingsController.h"
  11. #import "VLCAppDelegate.h"
  12. #import "VLCPlaylistViewController.h"
  13. #import "IASKSettingsReader.h"
  14. #import "IASKAppSettingsViewController.h"
  15. #import "PAPasscodeViewController.h"
  16. #import <DropboxSDK/DropboxSDK.h>
  17. #import "VLCGoogleDriveController.h"
  18. @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
  19. @end
  20. @implementation VLCSettingsController
  21. - (id)init
  22. {
  23. self = [super init];
  24. if (self)
  25. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  26. return self;
  27. }
  28. - (void)dealloc
  29. {
  30. [[NSNotificationCenter defaultCenter] removeObserver:self];
  31. }
  32. - (void)settingDidChange:(NSNotification*)notification
  33. {
  34. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  35. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  36. if (passcodeOn) {
  37. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  38. passcodeLockController.delegate = self;
  39. [self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
  40. }
  41. }
  42. }
  43. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  44. {
  45. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  46. }
  47. - (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier {
  48. if ([specifier.key isEqualToString:@"UnlinkDropbox"]) {
  49. [[DBSession sharedSession] unlinkAll];
  50. } else if ([specifier.key isEqualToString:@"UnlinkGoogleDrive"]) {
  51. [[VLCGoogleDriveController sharedInstance] logout];
  52. }
  53. }
  54. #pragma mark - PAPasscode delegate
  55. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  56. {
  57. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  58. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  59. [defaults synchronize];
  60. [controller dismissViewControllerAnimated:YES completion:nil];
  61. }
  62. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  63. {
  64. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  65. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  66. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  67. [defaults synchronize];
  68. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  69. appDelegate.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300];
  70. [controller dismissViewControllerAnimated:YES completion:nil];
  71. }
  72. @end