VLCPasscodeLockViewController.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // VLCPasscodeLockViewController.m
  3. // VLC for iOS
  4. //
  5. // Created by Felix Paul Kühne on 18.05.13.
  6. // Copyright (c) 2013 VideoLAN. All rights reserved.
  7. //
  8. #import "VLCPasscodeLockViewController.h"
  9. #import "VLCAppDelegate.h"
  10. #import "VLCPlaylistViewController.h"
  11. @implementation VLCPasscodeLockViewController
  12. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  13. {
  14. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  15. return self;
  16. }
  17. - (void)viewDidLoad
  18. {
  19. [super viewDidLoad];
  20. self.enterCodeField.secureTextEntry = YES;
  21. }
  22. - (void)viewWillAppear:(BOOL)animated
  23. {
  24. NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  25. _passcode = [defaults objectForKey:@"Passcode"];
  26. self.enterPasscodeLabel.text = NSLocalizedString(@"ENTER_PASSCODE", @"");
  27. [self.navigationController setNavigationBarHidden:YES animated:NO];
  28. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
  29. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent;
  30. self.enterCodeField.text = @"";
  31. [self.enterCodeField becomeFirstResponder];
  32. [super viewWillAppear:animated];
  33. }
  34. - (void)viewWillDisappear:(BOOL)animated
  35. {
  36. [self.navigationController setNavigationBarHidden:NO animated:YES];
  37. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
  38. [super viewWillDisappear:animated];
  39. }
  40. - (IBAction)textFieldValueChanged:(id)sender
  41. {
  42. if (self.enterCodeField.text.length == 4) {
  43. VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
  44. if (_resetStage == 1) {
  45. _tmpPasscode = self.enterCodeField.text;
  46. self.enterCodeField.text = @"";
  47. self.enterPasscodeLabel.text = NSLocalizedString(@"REENTER_PASSCODE", @"");
  48. _resetStage = 2;
  49. } else if (_resetStage == 2) {
  50. if ([self.enterCodeField.text isEqualToString:_tmpPasscode]) {
  51. NSUserDefaults *defaults;
  52. [defaults setObject:@1 forKey:@"PasscodeProtection"];
  53. [defaults setObject:_tmpPasscode forKey:@"Passcode"];
  54. [defaults synchronize];
  55. _passcode = _tmpPasscode;
  56. _resetStage = 0;
  57. appDelegate.playlistViewController.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300]; // five min
  58. appDelegate.playlistViewController.passcodeValidated = YES;
  59. [self.view removeFromSuperview];
  60. }
  61. } else if ([self.enterCodeField.text isEqualToString:_passcode]) {
  62. appDelegate.playlistViewController.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300]; // five min
  63. appDelegate.playlistViewController.passcodeValidated = YES;
  64. [self.navigationController popViewControllerAnimated:YES];
  65. }
  66. }
  67. }
  68. - (void)resetPasscode
  69. {
  70. _resetStage = 1;
  71. }
  72. @end