mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Authorization code paste menu
This commit is contained in:
parent
47ffcd2e4d
commit
e1cb13110a
@ -8504,3 +8504,5 @@ Sorry for the inconvenience.";
|
|||||||
"Privacy.ProfilePhoto.PublicPhotoInfo" = "You can upload a public photo for those who are restricted from viewing your real profile photo.";
|
"Privacy.ProfilePhoto.PublicPhotoInfo" = "You can upload a public photo for those who are restricted from viewing your real profile photo.";
|
||||||
|
|
||||||
"WebApp.AddToAttachmentAllowMessages" = "Allow **%@** to send me messages";
|
"WebApp.AddToAttachmentAllowMessages" = "Allow **%@** to send me messages";
|
||||||
|
|
||||||
|
"Common.Paste" = "Paste";
|
||||||
|
@ -109,6 +109,10 @@ public final class AuthorizationSequenceCodeEntryController: ViewController {
|
|||||||
self?.navigationItem.rightBarButtonItem?.isEnabled = value
|
self?.navigationItem.rightBarButtonItem?.isEnabled = value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.controllerNode.present = { [weak self] c, a in
|
||||||
|
self?.present(c, in: .window(.root), with: a)
|
||||||
|
}
|
||||||
|
|
||||||
if let (number, email, codeType, nextType, timeout) = self.data {
|
if let (number, email, codeType, nextType, timeout) = self.data {
|
||||||
var appleSignInAllowed = false
|
var appleSignInAllowed = false
|
||||||
if case let .email(_, _, _, appleSignInAllowedValue, _) = codeType {
|
if case let .email(_, _, _, appleSignInAllowedValue, _) = codeType {
|
||||||
|
@ -14,6 +14,7 @@ import TelegramAnimatedStickerNode
|
|||||||
import SolidRoundedButtonNode
|
import SolidRoundedButtonNode
|
||||||
import InvisibleInkDustNode
|
import InvisibleInkDustNode
|
||||||
import AuthorizationUtils
|
import AuthorizationUtils
|
||||||
|
import TelegramStringFormatting
|
||||||
|
|
||||||
final class AuthorizationSequenceCodeEntryControllerNode: ASDisplayNode, UITextFieldDelegate {
|
final class AuthorizationSequenceCodeEntryControllerNode: ASDisplayNode, UITextFieldDelegate {
|
||||||
private let strings: PresentationStrings
|
private let strings: PresentationStrings
|
||||||
@ -64,6 +65,7 @@ final class AuthorizationSequenceCodeEntryControllerNode: ASDisplayNode, UITextF
|
|||||||
var loginWithCode: ((String) -> Void)?
|
var loginWithCode: ((String) -> Void)?
|
||||||
var signInWithApple: (() -> Void)?
|
var signInWithApple: (() -> Void)?
|
||||||
var openFragment: ((String) -> Void)?
|
var openFragment: ((String) -> Void)?
|
||||||
|
var present: (ViewController, Any?) -> Void = { _, _ in }
|
||||||
|
|
||||||
var requestNextOption: (() -> Void)?
|
var requestNextOption: (() -> Void)?
|
||||||
var requestAnotherOption: (() -> Void)?
|
var requestAnotherOption: (() -> Void)?
|
||||||
@ -170,6 +172,34 @@ final class AuthorizationSequenceCodeEntryControllerNode: ASDisplayNode, UITextF
|
|||||||
strongSelf.textChanged(text: strongSelf.codeInputView.text)
|
strongSelf.textChanged(text: strongSelf.codeInputView.text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.codeInputView.longPressed = { [weak self] in
|
||||||
|
guard let strongSelf = self else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if let code = UIPasteboard.general.string, let codeLength = strongSelf.requiredCodeLength, code.count == Int(codeLength) {
|
||||||
|
let code = normalizeArabicNumeralString(code, type: .western)
|
||||||
|
guard code.rangeOfCharacter(from: CharacterSet(charactersIn: "0123456789").inverted) == nil else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let controller = ContextMenuController(actions: [ContextMenuAction(content: .text(title: strongSelf.strings.Common_Paste, accessibilityLabel: strongSelf.strings.Common_Paste), action: { [weak self] in
|
||||||
|
self?.updateCode(code)
|
||||||
|
})])
|
||||||
|
|
||||||
|
strongSelf.present(
|
||||||
|
controller,
|
||||||
|
ContextMenuControllerPresentationArguments(sourceNodeAndRect: { [weak self] in
|
||||||
|
if let strongSelf = self {
|
||||||
|
return (strongSelf, strongSelf.codeInputView.frame.offsetBy(dx: 0.0, dy: -8.0), strongSelf, strongSelf.bounds)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
self.nextOptionButtonNode.addTarget(self, action: #selector(self.nextOptionNodePressed), forControlEvents: .touchUpInside)
|
self.nextOptionButtonNode.addTarget(self, action: #selector(self.nextOptionNodePressed), forControlEvents: .touchUpInside)
|
||||||
self.proceedNode.pressed = { [weak self] in
|
self.proceedNode.pressed = { [weak self] in
|
||||||
self?.proceedPressed()
|
self?.proceedPressed()
|
||||||
@ -193,23 +223,29 @@ final class AuthorizationSequenceCodeEntryControllerNode: ASDisplayNode, UITextF
|
|||||||
self.codeInputView.text = code
|
self.codeInputView.text = code
|
||||||
self.textChanged(text: code)
|
self.textChanged(text: code)
|
||||||
|
|
||||||
|
if let codeLength = self.requiredCodeLength, code.count == Int(codeLength) {
|
||||||
|
self.loginWithCode?(code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var requiredCodeLength: Int32? {
|
||||||
if let codeType = self.codeType {
|
if let codeType = self.codeType {
|
||||||
var codeLength: Int32?
|
|
||||||
switch codeType {
|
switch codeType {
|
||||||
case let .call(length):
|
case let .call(length):
|
||||||
codeLength = length
|
return length
|
||||||
case let .otherSession(length):
|
case let .otherSession(length):
|
||||||
codeLength = length
|
return length
|
||||||
case let .missedCall(_, length):
|
case let .missedCall(_, length):
|
||||||
codeLength = length
|
return length
|
||||||
case let .sms(length):
|
case let .sms(length):
|
||||||
codeLength = length
|
return length
|
||||||
default:
|
case let .fragment(_, length):
|
||||||
break
|
return length
|
||||||
}
|
default:
|
||||||
if let codeLength = codeLength, code.count == Int(codeLength) {
|
return nil
|
||||||
self.loginWithCode?(code)
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,6 +118,7 @@ public final class CodeInputView: ASDisplayNode, UITextFieldDelegate {
|
|||||||
private var itemViews: [ItemView] = []
|
private var itemViews: [ItemView] = []
|
||||||
|
|
||||||
public var updated: (() -> Void)?
|
public var updated: (() -> Void)?
|
||||||
|
public var longPressed: (() -> Void)?
|
||||||
|
|
||||||
private var theme: Theme?
|
private var theme: Theme?
|
||||||
private var count: Int?
|
private var count: Int?
|
||||||
@ -169,6 +170,18 @@ public final class CodeInputView: ASDisplayNode, UITextFieldDelegate {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override func didLoad() {
|
||||||
|
super.didLoad()
|
||||||
|
|
||||||
|
self.view.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(self.handleLongPress(_:))))
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc func handleLongPress(_ gestureRecognizer: UILongPressGestureRecognizer) {
|
||||||
|
if case .ended = gestureRecognizer.state {
|
||||||
|
self.longPressed?()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var isSucceed = false
|
private var isSucceed = false
|
||||||
private var isFailed = false
|
private var isFailed = false
|
||||||
private var isResetting = false
|
private var isResetting = false
|
||||||
|
Loading…
x
Reference in New Issue
Block a user