mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Add password removed screen
This commit is contained in:
@@ -15,7 +15,7 @@ import TelegramCore
|
||||
public enum TwoFactorAuthSplashMode {
|
||||
case intro
|
||||
case done
|
||||
case recoveryDone(recoveredAccountData: RecoveredAccountData, syncContacts: Bool)
|
||||
case recoveryDone(recoveredAccountData: RecoveredAccountData?, syncContacts: Bool, isPasswordSet: Bool)
|
||||
}
|
||||
|
||||
public final class TwoFactorAuthSplashScreen: ViewController {
|
||||
@@ -66,13 +66,15 @@ public final class TwoFactorAuthSplashScreen: ViewController {
|
||||
return
|
||||
}
|
||||
navigationController.filterController(strongSelf, animated: true)
|
||||
case let .recoveryDone(recoveredAccountData, syncContacts):
|
||||
case let .recoveryDone(recoveredAccountData, syncContacts, _):
|
||||
guard let navigationController = strongSelf.navigationController as? NavigationController else {
|
||||
return
|
||||
}
|
||||
switch strongSelf.engine {
|
||||
case let .unauthorized(engine):
|
||||
let _ = loginWithRecoveredAccountData(accountManager: strongSelf.sharedContext.accountManager, account: engine.account, recoveredAccountData: recoveredAccountData, syncContacts: syncContacts).start()
|
||||
if let recoveredAccountData = recoveredAccountData {
|
||||
let _ = loginWithRecoveredAccountData(accountManager: strongSelf.sharedContext.accountManager, account: engine.account, recoveredAccountData: recoveredAccountData, syncContacts: syncContacts).start()
|
||||
}
|
||||
case .authorized:
|
||||
navigationController.filterController(strongSelf, animated: true)
|
||||
}
|
||||
@@ -97,7 +99,8 @@ private final class TwoFactorAuthSplashScreenNode: ViewControllerTracingNode {
|
||||
private var animationOffset: CGPoint = CGPoint()
|
||||
private let animationNode: AnimatedStickerNode
|
||||
private let titleNode: ImmediateTextNode
|
||||
private let textNode: ImmediateTextNode
|
||||
private let textNodes: [ImmediateTextNode]
|
||||
private let textArrowNodes: [ASImageNode]
|
||||
let buttonNode: SolidRoundedButtonNode
|
||||
|
||||
var inProgress: Bool = false {
|
||||
@@ -114,7 +117,7 @@ private final class TwoFactorAuthSplashScreenNode: ViewControllerTracingNode {
|
||||
self.animationNode = AnimatedStickerNode()
|
||||
|
||||
let title: String
|
||||
let text: NSAttributedString
|
||||
let texts: [NSAttributedString]
|
||||
let buttonText: String
|
||||
|
||||
let textFont = Font.regular(16.0)
|
||||
@@ -123,7 +126,7 @@ private final class TwoFactorAuthSplashScreenNode: ViewControllerTracingNode {
|
||||
switch mode {
|
||||
case .intro:
|
||||
title = self.presentationData.strings.TwoFactorSetup_Intro_Title
|
||||
text = NSAttributedString(string: self.presentationData.strings.TwoFactorSetup_Intro_Text, font: textFont, textColor: textColor)
|
||||
texts = [NSAttributedString(string: self.presentationData.strings.TwoFactorSetup_Intro_Text, font: textFont, textColor: textColor)]
|
||||
buttonText = self.presentationData.strings.TwoFactorSetup_Intro_Action
|
||||
|
||||
if let path = getAppBundle().path(forResource: "TwoFactorSetupIntro", ofType: "tgs") {
|
||||
@@ -133,7 +136,7 @@ private final class TwoFactorAuthSplashScreenNode: ViewControllerTracingNode {
|
||||
}
|
||||
case .done:
|
||||
title = self.presentationData.strings.TwoFactorSetup_Done_Title
|
||||
text = NSAttributedString(string: self.presentationData.strings.TwoFactorSetup_Done_Text, font: textFont, textColor: textColor)
|
||||
texts = [NSAttributedString(string: self.presentationData.strings.TwoFactorSetup_Done_Text, font: textFont, textColor: textColor)]
|
||||
buttonText = self.presentationData.strings.TwoFactorSetup_Done_Action
|
||||
|
||||
if let path = getAppBundle().path(forResource: "TwoFactorSetupDone", ofType: "tgs") {
|
||||
@@ -141,13 +144,28 @@ private final class TwoFactorAuthSplashScreenNode: ViewControllerTracingNode {
|
||||
self.animationSize = CGSize(width: 124.0, height: 124.0)
|
||||
self.animationNode.visibility = true
|
||||
}
|
||||
case .recoveryDone:
|
||||
title = self.presentationData.strings.TwoFactorSetup_ResetDone_Title
|
||||
text = NSAttributedString(string: self.presentationData.strings.TwoFactorSetup_ResetDone_Text, font: textFont, textColor: textColor)
|
||||
case let .recoveryDone(_, _, isPasswordSet):
|
||||
title = isPasswordSet ? self.presentationData.strings.TwoFactorSetup_ResetDone_Title : self.presentationData.strings.TwoFactorSetup_ResetDone_TitleNoPassword
|
||||
|
||||
let rawText = isPasswordSet ? self.presentationData.strings.TwoFactorSetup_ResetDone_Text : self.presentationData.strings.TwoFactorSetup_ResetDone_TextNoPassword
|
||||
|
||||
var splitTexts: [String] = [""]
|
||||
var index = rawText.startIndex
|
||||
while index != rawText.endIndex {
|
||||
let c = rawText[index]
|
||||
if c == ">" {
|
||||
splitTexts.append("")
|
||||
} else {
|
||||
splitTexts[splitTexts.count - 1].append(c)
|
||||
}
|
||||
index = rawText.index(after: index)
|
||||
}
|
||||
|
||||
texts = splitTexts.map { NSAttributedString(string: $0, font: textFont, textColor: textColor) }
|
||||
buttonText = self.presentationData.strings.TwoFactorSetup_ResetDone_Action
|
||||
|
||||
if let path = getAppBundle().path(forResource: "TwoFactorSetupDone", ofType: "tgs") {
|
||||
self.animationNode.setup(source: AnimatedStickerNodeLocalFileSource(path: path), width: 248, height: 248, mode: .direct(cachePathPrefix: nil))
|
||||
if let path = getAppBundle().path(forResource: isPasswordSet ? "TwoFactorSetupDone" : "TwoFactorRemovePasswordDone", ofType: "tgs") {
|
||||
self.animationNode.setup(source: AnimatedStickerNodeLocalFileSource(path: path), width: 248, height: 248, playbackMode: isPasswordSet ? .loop : .once, mode: .direct(cachePathPrefix: nil))
|
||||
self.animationSize = CGSize(width: 124.0, height: 124.0)
|
||||
self.animationNode.visibility = true
|
||||
}
|
||||
@@ -159,12 +177,27 @@ private final class TwoFactorAuthSplashScreenNode: ViewControllerTracingNode {
|
||||
self.titleNode.maximumNumberOfLines = 0
|
||||
self.titleNode.textAlignment = .center
|
||||
|
||||
self.textNode = ImmediateTextNode()
|
||||
self.textNode.displaysAsynchronously = false
|
||||
self.textNode.attributedText = text
|
||||
self.textNode.maximumNumberOfLines = 0
|
||||
self.textNode.lineSpacing = 0.1
|
||||
self.textNode.textAlignment = .center
|
||||
self.textNodes = texts.map { text in
|
||||
let textNode = ImmediateTextNode()
|
||||
|
||||
textNode.displaysAsynchronously = false
|
||||
textNode.attributedText = text
|
||||
textNode.maximumNumberOfLines = 0
|
||||
textNode.lineSpacing = 0.1
|
||||
textNode.textAlignment = .center
|
||||
|
||||
return textNode
|
||||
}
|
||||
|
||||
let arrowImage = generateTintedImage(image: UIImage(bundleImageName: "Chat/Input/Search/DownButton"), color: presentationData.theme.list.itemPrimaryTextColor)
|
||||
self.textArrowNodes = (0 ..< self.textNodes.count - 1).map { _ in
|
||||
let iconNode = ASImageNode()
|
||||
|
||||
iconNode.image = arrowImage
|
||||
iconNode.alpha = 0.34
|
||||
|
||||
return iconNode
|
||||
}
|
||||
|
||||
self.buttonNode = SolidRoundedButtonNode(title: buttonText, theme: SolidRoundedButtonTheme(backgroundColor: self.presentationData.theme.list.itemCheckColors.fillColor, foregroundColor: self.presentationData.theme.list.itemCheckColors.foregroundColor), height: 50.0, cornerRadius: 10.0, gloss: false)
|
||||
self.buttonNode.isHidden = buttonText.isEmpty
|
||||
@@ -175,7 +208,8 @@ private final class TwoFactorAuthSplashScreenNode: ViewControllerTracingNode {
|
||||
|
||||
self.addSubnode(self.animationNode)
|
||||
self.addSubnode(self.titleNode)
|
||||
self.addSubnode(self.textNode)
|
||||
self.textNodes.forEach(self.addSubnode)
|
||||
self.textArrowNodes.forEach(self.addSubnode)
|
||||
self.addSubnode(self.buttonNode)
|
||||
|
||||
self.buttonNode.pressed = {
|
||||
@@ -204,9 +238,17 @@ private final class TwoFactorAuthSplashScreenNode: ViewControllerTracingNode {
|
||||
}
|
||||
|
||||
let titleSize = self.titleNode.updateLayout(CGSize(width: layout.size.width - sideInset * 2.0, height: layout.size.height))
|
||||
let textSize = self.textNode.updateLayout(CGSize(width: layout.size.width - sideInset * 2.0, height: layout.size.height))
|
||||
let textSizes = self.textNodes.map {
|
||||
$0.updateLayout(CGSize(width: layout.size.width - sideInset * 2.0, height: layout.size.height))
|
||||
}
|
||||
var combinedTextHeight: CGFloat = 0.0
|
||||
let textSpacing: CGFloat = 32.0
|
||||
for textSize in textSizes {
|
||||
combinedTextHeight += textSize.height
|
||||
}
|
||||
combinedTextHeight += CGFloat(max(0, textSizes.count - 1)) * textSpacing
|
||||
|
||||
let contentHeight = iconSize.height + iconSpacing + titleSize.height + titleSpacing + textSize.height
|
||||
let contentHeight = iconSize.height + iconSpacing + titleSize.height + titleSpacing + combinedTextHeight
|
||||
var contentVerticalOrigin = floor((layout.size.height - contentHeight - iconSize.height / 2.0) / 2.0)
|
||||
|
||||
let minimalBottomInset: CGFloat = 60.0
|
||||
@@ -227,7 +269,20 @@ private final class TwoFactorAuthSplashScreenNode: ViewControllerTracingNode {
|
||||
transition.updateFrameAdditive(node: self.animationNode, frame: iconFrame)
|
||||
let titleFrame = CGRect(origin: CGPoint(x: floor((layout.size.width - titleSize.width) / 2.0), y: iconFrame.maxY + iconSpacing), size: titleSize)
|
||||
transition.updateFrameAdditive(node: self.titleNode, frame: titleFrame)
|
||||
let textFrame = CGRect(origin: CGPoint(x: floor((layout.size.width - textSize.width) / 2.0), y: titleFrame.maxY + titleSpacing), size: textSize)
|
||||
transition.updateFrameAdditive(node: self.textNode, frame: textFrame)
|
||||
|
||||
var nextTextOrigin: CGFloat = titleFrame.maxY + titleSpacing
|
||||
for i in 0 ..< self.textNodes.count {
|
||||
let textFrame = CGRect(origin: CGPoint(x: floor((layout.size.width - textSizes[i].width) / 2.0), y: nextTextOrigin), size: textSizes[i])
|
||||
transition.updateFrameAdditive(node: self.textNodes[i], frame: textFrame)
|
||||
|
||||
if i != 0 {
|
||||
if let image = self.textArrowNodes[i - 1].image {
|
||||
let scaledImageSize = CGSize(width: floor(image.size.width * 0.7), height: floor(image.size.height * 0.7))
|
||||
self.textArrowNodes[i - 1].frame = CGRect(origin: CGPoint(x: floor((layout.size.width - scaledImageSize.width) / 2.0), y: nextTextOrigin - textSpacing + floor((textSpacing - scaledImageSize.height) / 2.0)), size: scaledImageSize)
|
||||
}
|
||||
}
|
||||
|
||||
nextTextOrigin = textFrame.maxY + textSpacing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user