Skip to content
Merged
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
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.3
21 changes: 0 additions & 21 deletions PasscodeLock.podspec

This file was deleted.

4 changes: 4 additions & 0 deletions PasscodeLock/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ func bundleForResource(name: String, ofType type: String) -> NSBundle {

return NSBundle(forClass: PasscodeLock.self)
}

func defaultCustomColor() -> UIColor {
return UIColor(red: 0, green: 100/255, blue: 165/255, alpha: 1)
}
31 changes: 17 additions & 14 deletions PasscodeLock/PasscodeLock/ChangePasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,34 @@ import Foundation

struct ChangePasscodeState: PasscodeLockStateType {

let title: String
let description: String
let title : String
let description : String
let isCancellableAction = true
var isTouchIDAllowed = false

init(stringsToShow: StringsToBeDisplayed?) {

title = (stringsToShow?.passcodeLockChangeTitle ?? localizedStringFor("PasscodeLockChangeTitle", comment: "Change passcode title"))
description = (stringsToShow?.passcodeLockChangeDescription ?? localizedStringFor("PasscodeLockChangeDescription", comment: "Change passcode description"))
var isTouchIDAllowed = false
var tintColor : UIColor?
var font : UIFont?

init(stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {


let defaultColor = defaultCustomColor()
self.title = (stringsToShow?.passcodeLockChangeTitle ?? localizedStringFor("PasscodeLockChangeTitle", comment: "Change passcode title"))
self.description = (stringsToShow?.passcodeLockChangeDescription ?? localizedStringFor("PasscodeLockChangeDescription", comment: "Change passcode description"))
self.tintColor = (tintColor ?? defaultColor)
self.font = (font ?? UIFont.systemFontOfSize(16))
}

func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?) {
func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {

guard let currentPasscode = lock.repository.passcode else {
return
}

if passcode == currentPasscode {

let nextState = SetPasscodeState(stringsToShow: stringsToShow)

if (passcode == currentPasscode) {
let nextState = SetPasscodeState(stringsToShow: stringsToShow, tintColor: tintColor, font: font)
lock.changeStateTo(nextState)

} else {

lock.delegate?.passcodeLockDidFail(lock)
}
}
Expand Down
30 changes: 16 additions & 14 deletions PasscodeLock/PasscodeLock/ConfirmPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,36 @@ import Foundation

struct ConfirmPasscodeState: PasscodeLockStateType {

let title: String
let description: String
let title : String
let description : String
let isCancellableAction = true
var isTouchIDAllowed = false
var isTouchIDAllowed = false
var tintColor : UIColor?
var font : UIFont?

private var passcodeToConfirm: [String]

init(passcode: [String], stringsToShow: StringsToBeDisplayed?) {

passcodeToConfirm = passcode
title = (stringsToShow?.passcodeLockConfirmTitle ?? localizedStringFor("PasscodeLockConfirmTitle", comment: "Confirm passcode title"))
description = (stringsToShow?.passcodeLockConfirmDescription ?? localizedStringFor("PasscodeLockConfirmDescription", comment: "Confirm passcode description"))
init(passcode: [String], stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {

let defaultColor = defaultCustomColor()
self.passcodeToConfirm = passcode
self.title = (stringsToShow?.passcodeLockConfirmTitle ?? localizedStringFor("PasscodeLockConfirmTitle", comment: "Confirm passcode title"))
self.description = (stringsToShow?.passcodeLockConfirmDescription ?? localizedStringFor("PasscodeLockConfirmDescription", comment: "Confirm passcode description"))
self.tintColor = (tintColor ?? defaultColor)
self.font = (font ?? UIFont.systemFontOfSize(16))
}

func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?) {
func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {

if passcode == passcodeToConfirm {

if (passcode == passcodeToConfirm) {
lock.repository.savePasscode(passcode)
lock.delegate?.passcodeLockDidSucceed(lock)

} else {

let mismatchTitle = (stringsToShow?.passcodeLockMismatchTitle ?? localizedStringFor("PasscodeLockMismatchTitle", comment: "Passcode mismatch title"))
let mismatchDescription = (stringsToShow?.passcodeLockMismatchDescription ?? localizedStringFor("PasscodeLockMismatchDescription", comment: "Passcode mismatch description"))

let nextState = SetPasscodeState(title: mismatchTitle, description: mismatchDescription)

let nextState = SetPasscodeState(title: mismatchTitle, description: mismatchDescription, tintColor: tintColor, font: font)
lock.changeStateTo(nextState)
lock.delegate?.passcodeLockDidFail(lock)
}
Expand Down
38 changes: 17 additions & 21 deletions PasscodeLock/PasscodeLock/EnterPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,38 @@ public let PasscodeLockIncorrectPasscodeNotification = "passcode.lock.incorrect.

struct EnterPasscodeState: PasscodeLockStateType {

let title: String
let description: String
let isCancellableAction: Bool
var isTouchIDAllowed = true
let title : String
let description : String
let isCancellableAction : Bool
var isTouchIDAllowed = true
var tintColor : UIColor?
var font : UIFont?

private var inccorectPasscodeAttempts = 0
private var isNotificationSent = false

init(allowCancellation: Bool = false, stringsToShow: StringsToBeDisplayed?) {
init(allowCancellation: Bool = false, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {

isCancellableAction = allowCancellation
title = (stringsToShow?.passcodeLockEnterTitle ?? localizedStringFor("PasscodeLockEnterTitle", comment: "Enter passcode title"))
description = (stringsToShow?.passcodeLockEnterDescription ?? localizedStringFor("PasscodeLockEnterDescription", comment: "Enter passcode description"))
let defaultColor = defaultCustomColor()
self.isCancellableAction = allowCancellation
self.title = (stringsToShow?.passcodeLockEnterTitle ?? localizedStringFor("PasscodeLockEnterTitle", comment: "Enter passcode title"))
self.description = (stringsToShow?.passcodeLockEnterDescription ?? localizedStringFor("PasscodeLockEnterDescription", comment: "Enter passcode description"))
self.tintColor = (tintColor ?? defaultColor)
self.font = (font ?? UIFont.systemFontOfSize(16))
}

mutating func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?) {
mutating func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {

guard let currentPasscode = lock.repository.passcode else {
return
}

if passcode == currentPasscode {

if (passcode == currentPasscode) {
lock.delegate?.passcodeLockDidSucceed(lock)

} else {

inccorectPasscodeAttempts += 1

if inccorectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts {

if (inccorectPasscodeAttempts >= lock.configuration.maximumInccorectPasscodeAttempts) {
postNotification()
}

Expand All @@ -51,13 +52,8 @@ struct EnterPasscodeState: PasscodeLockStateType {
}

private mutating func postNotification() {

guard !isNotificationSent else { return }


let center = NSNotificationCenter.defaultCenter()

center.postNotificationName(PasscodeLockIncorrectPasscodeNotification, object: nil)

isNotificationSent = true
}
}
10 changes: 5 additions & 5 deletions PasscodeLock/PasscodeLock/PasscodeLock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ public class PasscodeLock: PasscodeLockType {
self.configuration = configuration
}

public func addSign(sign: String) {
public func addSign(sign: String, stringsToBeDisplayed: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {

passcode.append(sign)
delegate?.passcodeLock(self, addedSignAtIndex: passcode.count - 1)

if passcode.count >= configuration.passcodeLength {
lockState.acceptPasscode(passcode, fromLock: self, stringsToShow: nil)
passcode.removeAll(keepCapacity: true)
if (passcode.count >= configuration.passcodeLength) {

self.lockState.acceptPasscode(self.passcode, fromLock: self, stringsToShow: stringsToBeDisplayed, tintColor: tintColor, font: font)
self.passcode.removeAll(keepCapacity: true)
}
}

Expand Down
31 changes: 19 additions & 12 deletions PasscodeLock/PasscodeLock/SetPasscodeState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,34 @@ import Foundation

struct SetPasscodeState: PasscodeLockStateType {

let title: String
let description: String
let title : String
let description : String
let isCancellableAction = true
var isTouchIDAllowed = false
var isTouchIDAllowed = false
var tintColor : UIColor?
var font : UIFont?

init(title: String, description: String) {

init(title: String, description: String, tintColor: UIColor?, font: UIFont?) {

let defaultColor = defaultCustomColor()
self.title = title
self.description = description
self.tintColor = (tintColor ?? defaultColor)
self.font = (font ?? UIFont.systemFontOfSize(16))
}

init(stringsToShow: StringsToBeDisplayed?) {

title = (stringsToShow?.passcodeLockSetTitle ?? localizedStringFor("PasscodeLockSetTitle", comment: "Set passcode title"))
description = (stringsToShow?.passcodeLockSetDescription ?? localizedStringFor("PasscodeLockSetDescription", comment: "Set passcode description"))
init(stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {

let defaultColor = defaultCustomColor()
self.title = (stringsToShow?.passcodeLockSetTitle ?? localizedStringFor("PasscodeLockSetTitle", comment: "Set passcode title"))
self.description = (stringsToShow?.passcodeLockSetDescription ?? localizedStringFor("PasscodeLockSetDescription", comment: "Set passcode description"))
self.tintColor = (tintColor ?? defaultColor)
self.font = (font ?? UIFont.systemFontOfSize(16))
}

func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?) {
func acceptPasscode(passcode: [String], fromLock lock: PasscodeLockType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {

let nextState = ConfirmPasscodeState(passcode: passcode, stringsToShow: stringsToShow)

let nextState = ConfirmPasscodeState(passcode: passcode, stringsToShow: stringsToShow, tintColor: tintColor, font: font)
lock.changeStateTo(nextState)
}
}
8 changes: 4 additions & 4 deletions PasscodeLock/PasscodeLockPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,14 @@ public class PasscodeLockPresenter {
passcodeLockVC = viewController
}

public convenience init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType, stringsToShow: StringsToBeDisplayed?) {
public convenience init(mainWindow window: UIWindow?, configuration: PasscodeLockConfigurationType, stringsToShow: StringsToBeDisplayed?, tintColor: UIColor?, font: UIFont?) {

let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: configuration, stringsToShow: stringsToShow)
let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: configuration, stringsToShow: stringsToShow, tintColor: tintColor, font: font)

self.init(mainWindow: window, configuration: configuration, viewController: passcodeLockVC)
}

public func presentPasscodeLock(withImage image: UIImage? = nil, andStrings stringsToShow: StringsToBeDisplayed? = nil, dismissCompletionBlock: (() -> Void)? = nil) {
public func presentPasscodeLock(withImage image: UIImage? = nil, configuration config: PasscodeLockConfigurationType? = nil, andStrings stringsToShow: StringsToBeDisplayed? = nil, tintColor: UIColor?, font: UIFont?, dismissCompletionBlock: (() -> Void)? = nil) {

guard passcodeConfiguration.repository.hasPasscode else { return }
guard !isPasscodePresented else { return }
Expand All @@ -95,7 +95,7 @@ public class PasscodeLockPresenter {
mainWindow?.windowLevel = 1
mainWindow?.endEditing(true)

let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: passcodeConfiguration, stringsToShow: stringsToShow)
let passcodeLockVC = PasscodeLockViewController(state: .EnterPasscode, configuration: (config ?? passcodeConfiguration), stringsToShow: stringsToShow, tintColor: tintColor, font: font)
if (image != nil) {
passcodeLockVC.customImage = image
}
Expand Down
Loading