VLCSettingsController.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. @interface VLCSettingsController ()<PAPasscodeViewControllerDelegate, IASKSettingsDelegate>
  18. @end
  19. @implementation VLCSettingsController
  20. - (id)init
  21. {
  22. self = [super init];
  23. if (self)
  24. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  25. return self;
  26. }
  27. - (void)dealloc
  28. {
  29. [[NSNotificationCenter defaultCenter] removeObserver:self];
  30. }
  31. - (void)settingDidChange:(NSNotification*)notification
  32. {
  33. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  34. BOOL passcodeOn = [[notification.userInfo objectForKey:kVLCSettingPasscodeOnKey] boolValue];
  35. if (passcodeOn) {
  36. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  37. passcodeLockController.delegate = self;
  38. [self.viewController presentViewController:passcodeLockController animated:YES completion:nil];
  39. }
  40. }
  41. }
  42. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  43. {
  44. [[(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController] toggleSidebar:![(VLCAppDelegate*)[UIApplication sharedApplication].delegate revealController].sidebarShowing duration:kGHRevealSidebarDefaultAnimationDuration];
  45. }
  46. - (void)settingsViewController:(IASKAppSettingsViewController*)sender buttonTappedForSpecifier:(IASKSpecifier*)specifier {
  47. if ([specifier.key isEqualToString:@"UnlinkDropbox"])
  48. [[DBSession sharedSession] unlinkAll];
  49. }
  50. #pragma mark - PAPasscode delegate
  51. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  52. {
  53. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  54. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  55. [defaults synchronize];
  56. [controller dismissViewControllerAnimated:YES completion:nil];
  57. }
  58. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  59. {
  60. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  61. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  62. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  63. [defaults synchronize];
  64. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  65. appDelegate.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300];
  66. [controller dismissViewControllerAnimated:YES completion:nil];
  67. }
  68. @end