/
manage_lock_code_controller.rb
69 lines (57 loc) · 1.82 KB
/
manage_lock_code_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
class ManageLockCodeController < UIViewController
def initAndSetCode
if init
@text = "Enter a new code"
@action = -> (code) do
controller = ManageLockCodeController.alloc.initAndConfirmCode code
self.navigationController.pushViewController(controller, animated: true)
end
end
self
end
def initAndConfirmCode input_code
if init
@text = "Confirm your new code"
end
@action = -> (confirmation_code) do
stack = self.navigationController.viewControllers
if input_code == confirmation_code
LockCode.set(input_code)
outer_controller = stack.reverse.detect { |controller| controller.class != ManageLockCodeController }
self.navigationController.popToViewController(outer_controller, animated: false)
else
App.alert("Your codes do not match. Please try again.")
controller = stack[stack.size - 2]
self.navigationController.popToViewController(controller, animated: true)
end
end
self
end
def initAndChangeCode
if init
@text = "Enter your current code"
@action = -> (code) do
if LockCode.matches?(code)
self.navigationController.pushViewController(ManageLockCodeController.alloc.initAndSetCode, animated: true)
@lock_screen.reset_screen
else
@lock_screen.label.get.text = "Please try again"
@lock_screen.flash_background
@lock_screen.reset_screen
end
end
end
self
end
def viewDidAppear(animated)
@lock_screen.reset_screen
end
def viewDidLoad
super
rmq.stylesheet = ManageLockCodeStylesheet
@lock_screen = rmq.append(LockScreen, :lock_screen).get
@lock_screen.text = @text
@lock_screen.style_for_controller(self)
@lock_screen.action_on_last_button = @action
end
end