ソースを参照

expand passcode validator to serve as a way to set the code

Felix Paul Kühne 12 年 前
コミット
6ec312e542

+ 3 - 0
AspenProject/VLCPasscodeLockViewController.h

@@ -11,6 +11,9 @@
 @interface VLCPasscodeLockViewController : UIViewController
 {
     NSString *_passcode;
+    NSString *_tmpPasscode;
+
+    NSUInteger _resetStage;
 }
 
 @property (nonatomic, strong) IBOutlet UILabel *enterPasscodeLabel;

+ 21 - 3
AspenProject/VLCPasscodeLockViewController.m

@@ -30,6 +30,8 @@
     NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
     _passcode = [defaults objectForKey:@"Passcode"];
 
+    self.enterPasscodeLabel.text = NSLocalizedString(@"ENTER_PASSCODE", @"");
+
     [self.navigationController setNavigationBarHidden:YES animated:NO];
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
         [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackTranslucent;
@@ -48,8 +50,24 @@
 - (IBAction)textFieldValueChanged:(id)sender
 {
     if (self.enterCodeField.text.length == 4) {
-        if ([self.enterCodeField.text isEqualToString:_passcode]) {
-            VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
+        VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
+        if (_resetStage == 1) {
+            _tmpPasscode = self.enterCodeField.text;
+            self.enterCodeField.text = @"";
+            self.enterPasscodeLabel.text = NSLocalizedString(@"REENTER_PASSCODE", @"");
+            _resetStage = 2;
+        } else if (_resetStage == 2) {
+            if ([self.enterCodeField.text isEqualToString:_tmpPasscode]) {
+                NSUserDefaults *defaults;
+                [defaults setObject:@1 forKey:@"PasscodeProtection"];
+                [defaults setObject:_tmpPasscode forKey:@"Passcode"];
+                _passcode = _tmpPasscode;
+                _resetStage = 0;
+                appDelegate.playlistViewController.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300]; // five min
+                appDelegate.playlistViewController.passcodeValidated = YES;
+                [self.view removeFromSuperview];
+            }
+        } else if ([self.enterCodeField.text isEqualToString:_passcode]) {
             appDelegate.playlistViewController.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300]; // five min
             appDelegate.playlistViewController.passcodeValidated = YES;
             [self.navigationController popViewControllerAnimated:YES];
@@ -59,7 +77,7 @@
 
 - (void)resetPasscode
 {
-    
+    _resetStage = 1;
 }
 
 @end

+ 2 - 3
AspenProject/VLCPlaylistViewController.m

@@ -52,6 +52,8 @@
     self.emptyLibraryLongDescriptionLabel.numberOfLines = 0;
     self.emptyLibraryLongDescriptionLabel.text = NSLocalizedString(@"EMPTY_LIBRARY_LONG", @"");
     [self.emptyLibraryLongDescriptionLabel sizeToFit];
+
+    self.passcodeLockViewController = [[VLCPasscodeLockViewController alloc] initWithNibName:@"VLCPasscodeLockViewController" bundle:nil];
 }
 
 - (void)viewWillAppear:(BOOL)animated
@@ -117,9 +119,6 @@
         return;
     }
 
-    if (!self.passcodeLockViewController)
-        self.passcodeLockViewController = [[VLCPasscodeLockViewController alloc] initWithNibName:@"VLCPasscodeLockViewController" bundle:nil];
-
     if (!self.passcodeValidated) {
         if ([self.nextPasscodeCheckDate earlierDate:[NSDate date]] == self.nextPasscodeCheckDate)
             [self.navigationController pushViewController:self.passcodeLockViewController animated:YES];

+ 1 - 0
AspenProject/VLCSettingsViewController.m

@@ -39,6 +39,7 @@
 {
     if (self.passcodeLockSwitch.on) {
         VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
+        [self.view addSubview:appDelegate.playlistViewController.passcodeLockViewController.view];
         [appDelegate.playlistViewController.passcodeLockViewController resetPasscode];
     } else
         [[NSUserDefaults standardUserDefaults] setObject:@0 forKey:@"PasscodeProtection"];

+ 9 - 1
Resources/VLCPasscodeLockViewController~iphone.xib

@@ -162,6 +162,14 @@
 					<int key="connectionID">32</int>
 				</object>
 				<object class="IBConnectionRecord">
+					<object class="IBCocoaTouchOutletConnection" key="connection">
+						<string key="label">enterPasscodeLabel</string>
+						<reference key="source" ref="372490531"/>
+						<reference key="destination" ref="186196614"/>
+					</object>
+					<int key="connectionID">36</int>
+				</object>
+				<object class="IBConnectionRecord">
 					<object class="IBCocoaTouchEventConnection" key="connection">
 						<string key="label">textFieldValueChanged:</string>
 						<reference key="source" ref="39256385"/>
@@ -258,7 +266,7 @@
 			<nil key="activeLocalization"/>
 			<dictionary class="NSMutableDictionary" key="localizations"/>
 			<nil key="sourceID"/>
-			<int key="maxID">35</int>
+			<int key="maxID">36</int>
 		</object>
 		<object class="IBClassDescriber" key="IBDocument.Classes">
 			<array class="NSMutableArray" key="referencedPartialClassDescriptions">

BIN
Resources/de.lproj/Localizable.strings


BIN
Resources/en.lproj/Localizable.strings


BIN
Resources/fr.lproj/Localizable.strings


BIN
Resources/ru.lproj/Localizable.strings