Commit 51658bd1 authored by Gleb Pinigin's avatar Gleb Pinigin

Replace passcode view controller with a nice one

parent 6f68321d
......@@ -7,11 +7,13 @@
//
#import <UIKit/UIKit.h>
#import "VLCPlaylistViewController.h"
@class VLCPlaylistViewController;
@class PAPasscodeViewController;
@interface VLCAppDelegate : UIResponder <UIApplicationDelegate>
{
NSURL *_tempURL;
PAPasscodeViewController *_passcodeLockController;
}
- (void)updateMediaList;
......@@ -22,4 +24,6 @@
@property (nonatomic, strong) UINavigationController *navigationController;
@property (nonatomic, retain) NSDate *nextPasscodeCheckDate;
@end
......@@ -9,8 +9,14 @@
#import "VLCAppDelegate.h"
#import "VLCPlaylistViewController.h"
#import "VLCMovieViewController.h"
#import "PAPasscodeViewController.h"
@interface VLCAppDelegate () <PAPasscodeViewControllerDelegate>
@property (nonatomic) BOOL passcodeValidated;
@end
@implementation VLCAppDelegate
......@@ -77,13 +83,7 @@
- (void)applicationWillEnterForeground:(UIApplication *)application
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if (![[defaults objectForKey:@"Passcode"] isEqualToString:@""])
self.playlistViewController.passcodeValidated = NO;
else
self.playlistViewController.passcodeValidated = YES;
NSLog(@"applicationWillEnterForeground: %i", self.playlistViewController.passcodeValidated);
NSLog(@"applicationWillEnterForeground: %i", self.passcodeValidated);
}
- (void)applicationDidBecomeActive:(UIApplication *)application
......@@ -91,6 +91,11 @@
[self updateMediaList];
}
- (void)applicationDidEnterBackground:(UIApplication *)application
{
[self validatePasscode]; // Lock library when going to background
}
- (void)applicationWillTerminate:(UIApplication *)application
{
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
......@@ -121,4 +126,43 @@
[_playlistViewController updateViewContents];
}
#pragma mark - pass code validation
- (void)validatePasscode
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *passcode = [defaults objectForKey:kVLCSettingPasscodeKey];
if ([passcode isEqualToString:@""]) {
self.passcodeValidated = YES;
return;
}
if (!self.passcodeValidated) {
if ([self.nextPasscodeCheckDate earlierDate:[NSDate date]] == self.nextPasscodeCheckDate) {
_passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionEnter];
_passcodeLockController.delegate = self;
_passcodeLockController.passcode = passcode;
self.window.rootViewController = _passcodeLockController;
} else
self.passcodeValidated = YES;
}
}
- (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
{
// TODO remove cancel button for Enter action
}
- (void)PAPasscodeViewControllerDidEnterPasscode:(PAPasscodeViewController *)controller
{
// TODO add transition animation
self.window.rootViewController = self.navigationController;
}
- (void)PAPasscodeViewController:(PAPasscodeViewController *)controller didFailToEnterPasscode:(NSInteger)attempts
{
// TODO handle error attempts
}
@end
//
// VLCPasscodeLockViewController.h
// VLC for iOS
//
// Created by Felix Paul Kühne on 18.05.13.
// Copyright (c) 2013 VideoLAN. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface VLCPasscodeLockViewController : UIViewController
{
NSString *_passcode;
NSString *_tmpPasscode;
NSUInteger _resetStage;
}
@property (nonatomic, strong) IBOutlet UILabel *enterPasscodeLabel;
@property (nonatomic, strong) IBOutlet UITextField *enterCodeField;
- (IBAction)textFieldValueChanged:(id)sender;
- (void)resetPasscode;
@end
//
// VLCPasscodeLockViewController.m
// VLC for iOS
//
// Created by Felix Paul Kühne on 18.05.13.
// Copyright (c) 2013 VideoLAN. All rights reserved.
//
#import "VLCPasscodeLockViewController.h"
#import "VLCAppDelegate.h"
#import "VLCPlaylistViewController.h"
@implementation VLCPasscodeLockViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.enterCodeField.secureTextEntry = YES;
}
- (void)viewWillAppear:(BOOL)animated
{
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;
self.enterCodeField.text = @"";
[self.enterCodeField becomeFirstResponder];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:YES];
[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleBlackOpaque;
[super viewWillDisappear:animated];
}
- (IBAction)textFieldValueChanged:(id)sender
{
if (self.enterCodeField.text.length == 4) {
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"];
[defaults synchronize];
_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];
}
}
}
- (void)resetPasscode
{
_resetStage = 1;
}
@end
......@@ -8,6 +8,7 @@
#import "VLCPlaylistGridView.h"
#import "VLCAppDelegate.h"
#import "VLCPlaylistViewController.h"
@interface VLCPlaylistGridView (Hack)
@property (nonatomic, retain) NSString *reuseIdentifier;
......
......@@ -11,7 +11,6 @@
@class VLCMovieViewController;
@class VLCAboutViewController;
@class VLCPasscodeLockViewController;
@class VLCAddMediaViewController;
@interface VLCPlaylistViewController : UIViewController <AQGridViewDataSource, AQGridViewDelegate, UITableViewDataSource, UITableViewDelegate, UITabBarDelegate, UIPopoverControllerDelegate>
......@@ -19,12 +18,8 @@
BOOL _editMode;
}
@property (nonatomic, retain) NSDate *nextPasscodeCheckDate;
@property (nonatomic) BOOL passcodeValidated;
@property (nonatomic, strong) VLCMovieViewController *movieViewController;
@property (nonatomic, strong) VLCAboutViewController *aboutViewController;
@property (nonatomic, strong) VLCPasscodeLockViewController *passcodeLockViewController;
@property (nonatomic, strong) VLCAddMediaViewController *addMediaViewController;
@property (nonatomic, strong) UIPopoverController *addMediaPopoverController;
......@@ -38,7 +33,6 @@
- (IBAction)leftButtonAction:(id)sender;
- (void)validatePasscode;
- (void)updateViewContents;
- (void)openMovieFromURL:(NSURL *)url;
- (void)removeMediaObject:(MLFile *)mediaObject;
......
......@@ -11,7 +11,6 @@
#import "VLCPlaylistTableViewCell.h"
#import "VLCPlaylistGridView.h"
#import "VLCAboutViewController.h"
#import "VLCPasscodeLockViewController.h"
#import "VLCAddMediaViewController.h"
@interface VLCPlaylistViewController () {
......@@ -65,8 +64,6 @@
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
......@@ -84,7 +81,6 @@
- (void)viewDidAppear:(BOOL)animated
{
[self validatePasscode];
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
self.tableView.hidden = NO;
else
......@@ -123,21 +119,6 @@
}
}
- (void)validatePasscode
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([[defaults objectForKey:@"Passcode"] isEqualToString:@""]) {
self.passcodeValidated = YES;
return;
}
if (!self.passcodeValidated) {
if ([self.nextPasscodeCheckDate earlierDate:[NSDate date]] == self.nextPasscodeCheckDate)
[self.navigationController pushViewController:self.passcodeLockViewController animated:YES];
else
self.passcodeValidated = YES;
}
}
- (void)updateViewContents
{
......
......@@ -8,10 +8,10 @@
#import "VLCSettingsViewController.h"
#import "VLCPlaylistViewController.h"
#import "VLCPasscodeLockViewController.h"
#import "PAPasscodeViewController.h"
#import "VLCAppDelegate.h"
@interface VLCSettingsViewController ()
@interface VLCSettingsViewController () <PAPasscodeViewControllerDelegate>
{
NSArray *_userFacingTextEncodingNames;
NSArray *_textEncodingNames;
......@@ -67,14 +67,9 @@
if (sender == self.passcodeLockSwitch) {
if (self.passcodeLockSwitch.on) {
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
CGRect frame = self.view.frame;
frame.size.height -= 44.;
appDelegate.playlistViewController.passcodeLockViewController.view.frame = frame;
}
[self.view addSubview:appDelegate.playlistViewController.passcodeLockViewController.view];
[appDelegate.playlistViewController.passcodeLockViewController resetPasscode];
PAPasscodeViewController *passcodeLockController = [[PAPasscodeViewController alloc] initForAction:PasscodeActionSet];
passcodeLockController.delegate = self;
[self presentModalViewController:passcodeLockController animated:YES];
} else {
[defaults setObject:@0 forKey:kVLCSettingPasscodeOnKey];
}
......@@ -125,4 +120,24 @@
return _textEncodingNames.count;
}
#pragma mark - PAPasscode delegate
- (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller
{
self.passcodeLockSwitch.on = NO;
[controller dismissModalViewControllerAnimated:YES];
}
- (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@(1) forKey:kVLCSettingPasscodeOnKey];
[defaults setObject:controller.passcode forKey:kVLCSettingPasscodeKey];
[defaults synchronize];
VLCAppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
appDelegate.nextPasscodeCheckDate = [NSDate dateWithTimeIntervalSinceNow:300];
[controller dismissModalViewControllerAnimated:YES];
}
@end
//
// PAPasscodeViewController.h
// PAPasscode
//
// Created by Denis Hennessy on 15/10/2012.
// Copyright (c) 2012 Peer Assembly. All rights reserved.
//
#import <UIKit/UIKit.h>
typedef enum {
PasscodeActionSet,
PasscodeActionEnter,
PasscodeActionChange
} PasscodeAction;
@class PAPasscodeViewController;
@protocol PAPasscodeViewControllerDelegate <NSObject>
@optional
- (void)PAPasscodeViewControllerDidCancel:(PAPasscodeViewController *)controller;
- (void)PAPasscodeViewControllerDidChangePasscode:(PAPasscodeViewController *)controller;
- (void)PAPasscodeViewControllerDidEnterAlternativePasscode:(PAPasscodeViewController *)controller;
- (void)PAPasscodeViewControllerDidEnterPasscode:(PAPasscodeViewController *)controller;
- (void)PAPasscodeViewControllerDidSetPasscode:(PAPasscodeViewController *)controller;
- (void)PAPasscodeViewController:(PAPasscodeViewController *)controller didFailToEnterPasscode:(NSInteger)attempts;
@end
@interface PAPasscodeViewController : UIViewController {
UIView *contentView;
NSInteger phase;
UILabel *promptLabel;
UILabel *messageLabel;
UIImageView *failedImageView;
UILabel *failedAttemptsLabel;
UITextField *passcodeTextField;
UIImageView *digitImageViews[4];
UIImageView *snapshotImageView;
}
@property (strong) UIView *backgroundView;
@property (readonly) PasscodeAction action;
@property (weak) id<PAPasscodeViewControllerDelegate> delegate;
@property (strong) NSString *alternativePasscode;
@property (strong) NSString *passcode;
@property (assign) BOOL simple;
@property (assign) NSInteger failedAttempts;
@property (strong) NSString *enterPrompt;
@property (strong) NSString *confirmPrompt;
@property (strong) NSString *changePrompt;
@property (strong) NSString *message;
- (id)initForAction:(PasscodeAction)action;
@end
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment