-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
Copy pathAuthorizationSequenceAwaitingAccountResetController.swift
94 lines (74 loc) · 3.65 KB
/
AuthorizationSequenceAwaitingAccountResetController.swift
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import Foundation
import UIKit
import Display
import AsyncDisplayKit
import TelegramPresentationData
import ProgressNavigationButtonNode
final class AuthorizationSequenceAwaitingAccountResetController: ViewController {
private var controllerNode: AuthorizationSequenceAwaitingAccountResetControllerNode {
return self.displayNode as! AuthorizationSequenceAwaitingAccountResetControllerNode
}
private let strings: PresentationStrings
private let theme: PresentationTheme
var logout: (() -> Void)?
var reset: (() -> Void)?
var protectedUntil: Int32?
var number: String?
var inProgress: Bool = false {
didSet {
if self.inProgress {
let item = UIBarButtonItem(customDisplayNode: ProgressNavigationButtonNode(color: self.theme.rootController.navigationBar.accentTextColor))
self.navigationItem.rightBarButtonItem = item
} else {
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.strings.Common_Next, style: .done, target: self, action: #selector(self.logoutPressed))
}
}
}
init(strings: PresentationStrings, theme: PresentationTheme, back: @escaping () -> Void) {
self.strings = strings
self.theme = theme
super.init(navigationBarPresentationData: NavigationBarPresentationData(theme: AuthorizationSequenceController.navigationBarTheme(theme), strings: NavigationBarStrings(presentationStrings: strings)))
self.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .portrait)
self.statusBar.statusBarStyle = theme.intro.statusBarStyle.style
self.attemptNavigation = { _ in
return false
}
self.navigationBar?.backPressed = {
back()
}
self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: " ", style: .plain, target: self, action: nil)
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.strings.Settings_Logout, style: .plain, target: self, action: #selector(self.logoutPressed))
}
required init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override public func loadDisplayNode() {
self.displayNode = AuthorizationSequenceAwaitingAccountResetControllerNode(strings: self.strings, theme: self.theme)
self.displayNodeDidLoad()
self.controllerNode.reset = { [weak self] in
self?.reset?()
}
if let protectedUntil = self.protectedUntil, let number = self.number {
self.controllerNode.updateData(protectedUntil: protectedUntil, number: number)
}
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
func updateData(protectedUntil: Int32, number: String) {
if self.protectedUntil != protectedUntil || self.number != number {
self.protectedUntil = protectedUntil
self.number = number
if self.isNodeLoaded {
self.controllerNode.updateData(protectedUntil: protectedUntil, number: number)
}
}
}
override func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
super.containerLayoutUpdated(layout, transition: transition)
self.controllerNode.containerLayoutUpdated(layout, navigationBarHeight: self.navigationLayout(layout: layout).navigationFrame.maxY, transition: transition)
}
@objc func logoutPressed() {
self.logout?()
}
}