VLCSettingsViewController.m 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 "VLCPasscodeLockViewController.h"
  11. #import "VLCAppDelegate.h"
  12. @implementation VLCSettingsViewController
  13. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  14. {
  15. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  16. return self;
  17. }
  18. - (void)viewDidLoad
  19. {
  20. [super viewDidLoad];
  21. self.dismissButton.title = NSLocalizedString(@"BUTTON_DONE", @"");
  22. self.passcodeLockLabel.text = NSLocalizedString(@"PREF_PASSCODE", @"");
  23. self.audioPlaybackInBackgroundLabel.text = NSLocalizedString(@"PREF_AUDIOBACKGROUND", @"");
  24. }
  25. - (void)viewWillAppear:(BOOL)animated
  26. {
  27. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  28. self.passcodeLockSwitch.on = [[defaults objectForKey:kVLCSettingPasscodeOnKey] intValue];
  29. self.audioPlaybackInBackgroundSwitch.on = [[defaults objectForKey:kVLCSettingContinueAudioInBackgroundKey] intValue];
  30. [super viewWillAppear:animated];
  31. }
  32. - (IBAction)toggleSetting:(id)sender
  33. {
  34. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  35. if (sender == self.passcodeLockSwitch) {
  36. if (self.passcodeLockSwitch.on) {
  37. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  38. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  39. CGRect frame = self.view.frame;
  40. frame.size.height -= 44.;
  41. appDelegate.playlistViewController.passcodeLockViewController.view.frame = frame;
  42. }
  43. [self.view addSubview:appDelegate.playlistViewController.passcodeLockViewController.view];
  44. [appDelegate.playlistViewController.passcodeLockViewController resetPasscode];
  45. } else {
  46. [defaults setObject:@0 forKey:kVLCSettingPasscodeOnKey];
  47. }
  48. } else if (sender == self.audioPlaybackInBackgroundSwitch) {
  49. [defaults setObject:@(self.audioPlaybackInBackgroundSwitch.on) forKey:kVLCSettingContinueAudioInBackgroundKey];
  50. }
  51. [defaults synchronize];
  52. }
  53. - (IBAction)dismiss:(id)sender
  54. {
  55. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  56. [appDelegate.playlistViewController.navigationController dismissModalViewControllerAnimated:YES];
  57. }
  58. @end