VLCSettingsViewController.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. //
  2. // VLCSettingsViewController.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 19.05.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCSettingsViewController.h"
  9. #import "VLCPlaylistViewController.h"
  10. #import "PAPasscodeViewController.h"
  11. #import "VLCAppDelegate.h"
  12. #import "IASKSettingsReader.h"
  13. @implementation VLCSettingsViewController
  14. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  15. {
  16. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  17. return self;
  18. }
  19. - (void)dealloc
  20. {
  21. [[NSNotificationCenter defaultCenter] removeObserver:self];
  22. }
  23. - (IASKAppSettingsViewController*)appSettingsViewController {
  24. if (!_appSettingsViewController) {
  25. _appSettingsViewController = [[IASKAppSettingsViewController alloc] init];
  26. _appSettingsViewController.delegate = self;
  27. }
  28. return _appSettingsViewController;
  29. }
  30. - (void)viewDidLoad
  31. {
  32. self.dismissButton.title = NSLocalizedString(@"BUTTON_DONE", @"");
  33. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(settingDidChange:) name:kIASKAppSettingChanged object:nil];
  34. CGRect frame = self.view.frame;
  35. CGFloat toolbarHeight = self.topToolbar.frame.size.height;
  36. frame.size.height = frame.size.height - toolbarHeight;
  37. frame.origin.y = frame.origin.y + toolbarHeight;
  38. self.appSettingsViewController.tableView.frame = frame;
  39. [self.view addSubview:self.appSettingsViewController.tableView];
  40. [super viewDidLoad];
  41. }
  42. - (void)viewWillDisappear:(BOOL)animated
  43. {
  44. }
  45. - (void)viewWillAppear:(BOOL)animated
  46. {
  47. [super viewWillAppear:animated];
  48. }
  49. - (IBAction)dismiss:(id)sender
  50. {
  51. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  52. [appDelegate.playlistViewController.navigationController dismissModalViewControllerAnimated:YES];
  53. }
  54. #pragma mark - IASKAppSettingsViewController delegate
  55. - (void)settingsViewControllerDidEnd:(IASKAppSettingsViewController*)sender
  56. {
  57. // adapt app behavior if needed
  58. }
  59. - (void)settingDidChange:(NSNotification*)notification
  60. {
  61. if ([notification.object isEqual:kVLCSettingPasscodeOnKey]) {
  62. BOOL passcodeOn = (BOOL)[[notification.userInfo objectForKey:@"PasscodeProtection"] intValue];
  63. if (passcodeOn) {
  64. PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
  65. passcodeLockController.delegate = self;
  66. [self presentModalViewController:passcodeLockController animated:YES];
  67. }
  68. }
  69. }
  70. #pragma mark - PAPasscode delegate
  71. - (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
  72. {
  73. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  74. [defaults setObject:@(NO) forKey:kVLCSettingPasscodeOnKey];
  75. [defaults synchronize];
  76. [controller dismissModalViewControllerAnimated:YES];
  77. }
  78. - (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
  79. {
  80. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  81. [defaults setObject:@(YES) forKey:kVLCSettingPasscodeOnKey];
  82. [defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
  83. [defaults synchronize];
  84. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  85. appDelegate.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300];
  86. [controller dismissModalViewControllerAnimated:YES];
  87. }
  88. @end