Skip to content
This repository has been archived by the owner on Apr 11, 2021. It is now read-only.

Change old pin functionality added #53

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions ABPadLockScreen/ABPadLockScreenAbstractViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,18 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

@import UIKit;

/**
Abstract Class that encapsulates common functionality between the lock and setup screen. It is not designed to be used directly
*/

#import "ABPadLockScreenDelegate.h"
@class ABPadLockScreenView;

@interface ABPadLockScreenAbstractViewController : UIViewController
{
ABPadLockScreenView* lockScreenView;
}

@property (strong, nonatomic, readonly) ABPadLockScreenView *lockScreenView;
@property (nonatomic, strong) NSString *currentPin;
@property (nonatomic, weak) id<ABPadLockScreenDelegate> delegate;
@property (nonatomic, readonly, getter = isComplexPin) BOOL complexPin;
@property (nonatomic, assign) BOOL tapSoundEnabled; //No by Default
@property (nonatomic, assign) BOOL errorVibrateEnabled; //No by Default
Expand Down
100 changes: 56 additions & 44 deletions ABPadLockScreen/ABPadLockScreenAbstractViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,22 @@
#import "ABPinSelectionView.h"
#import <AudioToolbox/AudioToolbox.h>

#define lockScreenView ((ABPadLockScreenView *) [self view])

@interface ABPadLockScreenAbstractViewController ()

- (void)setUpButtonMapping;
- (void)buttonSelected:(UIButton *)sender;
- (void)cancelButtonSelected:(UIButton *)sender;
- (void)deleteButtonSelected:(UIButton *)sender;
- (void)okButtonSelected:(UIButton *)sender;

@end

@implementation ABPadLockScreenAbstractViewController

- (ABPadLockScreenView *)lockScreenView {
return (ABPadLockScreenView *) [self view];
}

#pragma mark -
#pragma mark - init methods
- (instancetype)init
Expand All @@ -48,7 +51,7 @@ - (instancetype)init
_tapSoundEnabled = NO;
_errorVibrateEnabled = NO;
_currentPin = @"";
_complexPin = NO;
_complexPin = NO; //default to NO
}
return self;
}
Expand All @@ -68,7 +71,7 @@ - (id)initWithComplexPin:(BOOL)complexPin
- (void)viewDidLoad
{
[super viewDidLoad];

CGRect bounds = self.view.bounds;
if ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {
if (bounds.size.width > bounds.size.height) {
Expand All @@ -78,48 +81,49 @@ - (void)viewDidLoad
bounds.size.width = width;
}
}

self.view = [[ABPadLockScreenView alloc] initWithFrame:bounds complexPin:self.isComplexPin];

[self setUpButtonMapping];
[lockScreenView.deleteButton addTarget:self action:@selector(deleteButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
[lockScreenView.okButton addTarget:self action:@selector(okButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
[self.lockScreenView.cancelButton addTarget:self action:@selector(cancelButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
[self.lockScreenView.deleteButton addTarget:self action:@selector(deleteButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
[self.lockScreenView.okButton addTarget:self action:@selector(okButtonSelected:) forControlEvents:UIControlEventTouchUpInside];
}

- (NSUInteger)supportedInterfaceOrientations
{
UIUserInterfaceIdiom interfaceIdiom = [[UIDevice currentDevice] userInterfaceIdiom];
if (interfaceIdiom == UIUserInterfaceIdiomPad) return UIInterfaceOrientationMaskAll;
if (interfaceIdiom == UIUserInterfaceIdiomPhone) return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;

return UIInterfaceOrientationMaskAll;
}

- (UIStatusBarStyle)preferredStatusBarStyle
{
if(lockScreenView.backgroundView != nil)
if(self.lockScreenView.backgroundView != nil)
{
//Background view is shown - need light content status bar.
return UIStatusBarStyleLightContent;
}

//Check background color if light or dark.
UIColor* color = lockScreenView.backgroundColor;
UIColor* color = self.lockScreenView.backgroundColor;

if(color == nil)
{
color = lockScreenView.backgroundColor = [UIColor blackColor];
color = self.lockScreenView.backgroundColor = [UIColor blackColor];
}

const CGFloat *componentColors = CGColorGetComponents(color.CGColor);

//Determine brightness
CGFloat colorBrightness = (CGColorGetNumberOfComponents(color.CGColor) == 2 ?
//Black and white color
componentColors[0] :
//RGB color
((componentColors[0] * 299) + (componentColors[1] * 587) + (componentColors[2] * 114)) / 1000);

if (colorBrightness < 0.5)
{
return UIStatusBarStyleLightContent;
Expand All @@ -140,35 +144,35 @@ - (void)viewWillAppear:(BOOL)animated
- (void)setLockScreenTitle:(NSString *)title
{
self.title = title;
lockScreenView.enterPasscodeLabel.text = title;
self.lockScreenView.enterPasscodeLabel.text = title;
}

- (void)setSubtitleText:(NSString *)text
{
lockScreenView.detailLabel.text = text;
self.lockScreenView.detailLabel.text = text;
}

- (void)setCancelButtonText:(NSString *)text
{
[lockScreenView.cancelButton setTitle:text forState:UIControlStateNormal];
[lockScreenView.cancelButton sizeToFit];
[self.lockScreenView.cancelButton setTitle:text forState:UIControlStateNormal];
[self.lockScreenView.cancelButton sizeToFit];
}

- (void)setDeleteButtonText:(NSString *)text
{
[lockScreenView.deleteButton setTitle:text forState:UIControlStateNormal];
[lockScreenView.deleteButton sizeToFit];
[self.lockScreenView.deleteButton setTitle:text forState:UIControlStateNormal];
[self.lockScreenView.deleteButton sizeToFit];
}

- (void)setEnterPasscodeLabelText:(NSString *)text
{
lockScreenView.enterPasscodeLabel.text = text;
self.lockScreenView.enterPasscodeLabel.text = text;
}

- (void)setBackgroundView:(UIView *)backgroundView
{
[lockScreenView setBackgroundView:backgroundView];
[self.lockScreenView setBackgroundView:backgroundView];

if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1)
{
[self setNeedsStatusBarAppearanceUpdate];
Expand All @@ -179,15 +183,15 @@ - (void)setBackgroundView:(UIView *)backgroundView
#pragma mark - Helper Methods
- (void)setUpButtonMapping
{
for (UIButton *button in [lockScreenView buttonArray])
for (UIButton *button in [self.lockScreenView buttonArray])
{
[button addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside];
}
}

- (void)cancelButtonDisabled:(BOOL)disabled
{
lockScreenView.cancelButtonDisabled = disabled;
self.lockScreenView.cancelButtonDisabled = disabled;
}

- (void)processPin
Expand All @@ -203,31 +207,31 @@ - (void)newPinSelected:(NSInteger)pinNumber
{
return;
}

self.currentPin = [NSString stringWithFormat:@"%@%ld", self.currentPin, (long)pinNumber];

if(self.isComplexPin)
{
[lockScreenView updatePinTextfieldWithLength:self.currentPin.length];
[self.lockScreenView updatePinTextfieldWithLength:self.currentPin.length];
}
else
{
NSUInteger curSelected = [self.currentPin length] - 1;
[lockScreenView.digitsArray[curSelected] setSelected:YES animated:YES completion:nil];
[self.lockScreenView.digitsArray[curSelected] setSelected:YES animated:YES completion:nil];
}

if ([self.currentPin length] == 1)
{
[lockScreenView showDeleteButtonAnimated:YES completion:nil];
[self.lockScreenView showDeleteButtonAnimated:YES completion:nil];

if(self.complexPin)
{
[lockScreenView showOKButton:YES animated:YES completion:nil];
[self.lockScreenView showOKButton:YES animated:YES completion:nil];
}
}
else if (!self.isComplexPin && [self.currentPin length] == SIMPLE_PIN_LENGTH)
{
[lockScreenView.digitsArray.lastObject setSelected:YES animated:YES completion:nil];
[self.lockScreenView.digitsArray.lastObject setSelected:YES animated:YES completion:nil];
[self processPin];
}
}
Expand All @@ -238,23 +242,23 @@ - (void)deleteFromPin
{
return;
}

self.currentPin = [self.currentPin substringWithRange:NSMakeRange(0, [self.currentPin length] - 1)];

if(self.isComplexPin)
{
[lockScreenView updatePinTextfieldWithLength:self.currentPin.length];
[self.lockScreenView updatePinTextfieldWithLength:self.currentPin.length];
}
else
{
NSUInteger pinToDeselect = [self.currentPin length];
[lockScreenView.digitsArray[pinToDeselect] setSelected:NO animated:YES completion:nil];
[self.lockScreenView.digitsArray[pinToDeselect] setSelected:NO animated:YES completion:nil];
}

if ([self.currentPin length] == 0)
{
[lockScreenView showCancelButtonAnimated:YES completion:nil];
[lockScreenView showOKButton:NO animated:YES completion:nil];
[self.lockScreenView showCancelButtonAnimated:YES completion:nil];
[self.lockScreenView showOKButton:NO animated:YES completion:nil];
}
}

Expand All @@ -268,6 +272,14 @@ - (void)buttonSelected:(UIButton *)sender
[self newPinSelected:tag];
}

- (void)cancelButtonSelected:(UIButton *)sender
{
if ([self.delegate respondsToSelector:@selector(unlockWasCancelledForPadLockScreenViewController:)])
{
[self.delegate unlockWasCancelledForPadLockScreenViewController:self];
}
}

- (void)deleteButtonSelected:(UIButton *)sender
{
[self deleteFromPin];
Expand Down
35 changes: 35 additions & 0 deletions ABPadLockScreen/ABPadLockScreenChangeOldViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ABPadLockScreenChangeOldViewController.h
// ABPadLockScreenDemo
//
// Created by Lobanov Dmitry on 21.06.15.
// Copyright (c) 2015 Aron Bury. All rights reserved.
//

#import "ABPadLockScreenAbstractViewController.h"
#import "ABPadLockScreenChangeOldViewControllerDelegate.h"

@interface ABPadLockScreenChangeOldViewController : ABPadLockScreenAbstractViewController
@property (nonatomic, weak, readonly) id<ABPadLockScreenChangeOldViewControllerDelegate> lockScreenDelegate;
@property (nonatomic, strong, readonly) NSString *subtitleLabelText;
@property (nonatomic, strong) NSString *oldPinPromptText;
@property (nonatomic, strong) NSString *futurePinPromptText;
@property (nonatomic, strong) NSString *oldPinNotMatchedText;
@property (nonatomic, strong) NSString *pinNotMatchedText;
@property (nonatomic, strong) NSString *pinConfirmationText;

@property (nonatomic, assign, readonly) NSInteger totalAttempts;
@property (nonatomic, assign, readonly) NSInteger remainingAttempts;

- (void)setAllowedAttempts:(NSInteger)allowedAttempts;

- (void)setLockedOutText:(NSString *)title;
- (void)setPluralAttemptsLeftText:(NSString *)title;
- (void)setSingleAttemptLeftText:(NSString *)title;

- (instancetype)initWithDelegate:(id<ABPadLockScreenChangeOldViewControllerDelegate>)delegate;
- (instancetype)initWithDelegate:(id<ABPadLockScreenChangeOldViewControllerDelegate>)delegate complexPin:(BOOL)complexPin;
- (instancetype)initWithDelegate:(id<ABPadLockScreenChangeOldViewControllerDelegate>)delegate complexPin:(BOOL)complexPin subtitleLabelText:(NSString *)subtitleLabelText;
- (instancetype)initWithDelegate:(id<ABPadLockScreenChangeOldViewControllerDelegate>)delegate complexPin:(BOOL)complexPin subtitleLabelText:(NSString *)subtitleLabelText oldPin:(NSString *)oldPin;

@end
Loading