mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-02-02 17:16:58 +00:00
Fixed auth code entry layout Added passcode lock confirmation Fixed auth code url handling Fixed instagram video gallery thumbnails
150 lines
5.8 KiB
Swift
150 lines
5.8 KiB
Swift
import Foundation
|
|
import Display
|
|
import AsyncDisplayKit
|
|
import TelegramCore
|
|
|
|
final class AuthorizationSequenceCodeEntryController: ViewController {
|
|
private var controllerNode: AuthorizationSequenceCodeEntryControllerNode {
|
|
return self.displayNode as! AuthorizationSequenceCodeEntryControllerNode
|
|
}
|
|
|
|
private let strings: PresentationStrings
|
|
private let theme: AuthorizationTheme
|
|
private let openUrl: (String) -> Void
|
|
|
|
var loginWithCode: ((String) -> Void)?
|
|
var reset: (() -> Void)?
|
|
var requestNextOption: (() -> Void)?
|
|
|
|
var data: (String, SentAuthorizationCodeType, AuthorizationCodeNextType?, Int32?)?
|
|
var termsOfService: (UnauthorizedAccountTermsOfService, Bool)?
|
|
|
|
private let hapticFeedback = HapticFeedback()
|
|
|
|
var inProgress: Bool = false {
|
|
didSet {
|
|
if self.inProgress {
|
|
let item = UIBarButtonItem(customDisplayNode: ProgressNavigationButtonNode(color: self.theme.accentColor))
|
|
self.navigationItem.rightBarButtonItem = item
|
|
} else {
|
|
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.strings.Common_Next, style: .done, target: self, action: #selector(self.nextPressed))
|
|
}
|
|
self.controllerNode.inProgress = self.inProgress
|
|
}
|
|
}
|
|
|
|
init(strings: PresentationStrings, theme: AuthorizationTheme, openUrl: @escaping (String) -> Void) {
|
|
self.strings = strings
|
|
self.theme = theme
|
|
self.openUrl = openUrl
|
|
|
|
super.init(navigationBarPresentationData: NavigationBarPresentationData(theme: AuthorizationSequenceController.navigationBarTheme(theme), strings: NavigationBarStrings(presentationStrings: strings)))
|
|
|
|
self.supportedOrientations = ViewControllerSupportedOrientations(regularSize: .all, compactSize: .portrait)
|
|
|
|
self.hasActiveInput = true
|
|
|
|
self.statusBar.statusBarStyle = theme.statusBarStyle
|
|
|
|
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: self.strings.Common_Next, style: .done, target: self, action: #selector(self.nextPressed))
|
|
|
|
self.attemptNavigation = { [weak self] f in
|
|
guard let strongSelf = self else {
|
|
return true
|
|
}
|
|
strongSelf.present(standardTextAlertController(theme: AlertControllerTheme(authTheme: theme), title: nil, text: strings.Login_CancelPhoneVerification, actions: [TextAlertAction(type: .genericAction, title: strings.Login_CancelPhoneVerificationContinue, action: {
|
|
}), TextAlertAction(type: .defaultAction, title: strings.Login_CancelPhoneVerificationStop, action: {
|
|
f()
|
|
})]), in: .window(.root))
|
|
return false
|
|
}
|
|
}
|
|
|
|
required init(coder aDecoder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override public func loadDisplayNode() {
|
|
self.displayNode = AuthorizationSequenceCodeEntryControllerNode(strings: self.strings, theme: self.theme)
|
|
self.displayNodeDidLoad()
|
|
|
|
self.controllerNode.loginWithCode = { [weak self] code in
|
|
self?.continueWithCode(code)
|
|
}
|
|
|
|
self.controllerNode.requestNextOption = { [weak self] in
|
|
self?.requestNextOption?()
|
|
}
|
|
|
|
self.controllerNode.requestAnotherOption = { [weak self] in
|
|
self?.requestNextOption?()
|
|
}
|
|
|
|
if let (number, codeType, nextType, timeout) = self.data {
|
|
self.controllerNode.updateData(number: number, codeType: codeType, nextType: nextType, timeout: timeout)
|
|
}
|
|
}
|
|
|
|
override func viewDidAppear(_ animated: Bool) {
|
|
super.viewDidAppear(animated)
|
|
|
|
self.controllerNode.activateInput()
|
|
}
|
|
|
|
func updateData(number: String, codeType: SentAuthorizationCodeType, nextType: AuthorizationCodeNextType?, timeout: Int32?, termsOfService: (UnauthorizedAccountTermsOfService, Bool)?) {
|
|
self.termsOfService = termsOfService
|
|
if self.data?.0 != number || self.data?.1 != codeType || self.data?.2 != nextType || self.data?.3 != timeout {
|
|
if case .otherSession = codeType {
|
|
self.title = number
|
|
} else {
|
|
self.title = nil
|
|
}
|
|
self.data = (number, codeType, nextType, timeout)
|
|
if self.isNodeLoaded {
|
|
self.controllerNode.updateData(number: number, codeType: codeType, nextType: nextType, timeout: timeout)
|
|
self.requestLayout(transition: .immediate)
|
|
}
|
|
}
|
|
}
|
|
|
|
override func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
|
super.containerLayoutUpdated(layout, transition: transition)
|
|
|
|
self.controllerNode.containerLayoutUpdated(layout, navigationBarHeight: self.navigationHeight, transition: transition)
|
|
}
|
|
|
|
@objc func nextPressed() {
|
|
guard let (_, type, _, _) = self.data else {
|
|
return
|
|
}
|
|
|
|
var minimalCodeLength = 1
|
|
|
|
switch type {
|
|
case let .otherSession(length):
|
|
minimalCodeLength = Int(length)
|
|
case let .sms(length):
|
|
minimalCodeLength = Int(length)
|
|
case let .call(length):
|
|
minimalCodeLength = Int(length)
|
|
case .flashCall:
|
|
break
|
|
}
|
|
|
|
if self.controllerNode.currentCode.count < minimalCodeLength {
|
|
hapticFeedback.error()
|
|
self.controllerNode.animateError()
|
|
} else {
|
|
self.continueWithCode(self.controllerNode.currentCode)
|
|
}
|
|
}
|
|
|
|
private func continueWithCode(_ code: String) {
|
|
self.loginWithCode?(code)
|
|
}
|
|
|
|
func applyConfirmationCode(_ code: Int) {
|
|
self.controllerNode.updateCode("\(code)")
|
|
}
|
|
}
|