session-ios/Session/View Controllers/KeyPairMigrationSheet.swift

72 lines
4.0 KiB
Swift
Raw Normal View History

2020-12-14 00:20:10 +01:00
final class KeyPairMigrationSheet : Sheet {
override func populateContentView() {
2020-12-14 04:30:34 +01:00
// Image view
2020-12-14 00:20:10 +01:00
let imageView = UIImageView(image: #imageLiteral(resourceName: "Sun"))
2020-12-14 04:30:34 +01:00
// Title label
2020-12-14 00:20:10 +01:00
let titleLabel = UILabel()
titleLabel.textColor = Colors.text
titleLabel.font = .boldSystemFont(ofSize: isIPhone5OrSmaller ? Values.largeFontSize : Values.veryLargeFontSize)
titleLabel.text = "Session IDs Just Got Better"
titleLabel.numberOfLines = 0
titleLabel.lineBreakMode = .byWordWrapping
2020-12-14 04:30:34 +01:00
// Top stack view
2020-12-14 00:20:10 +01:00
let topStackView = UIStackView(arrangedSubviews: [ imageView, titleLabel ])
topStackView.axis = .vertical
topStackView.spacing = Values.largeSpacing
topStackView.alignment = .center
2020-12-14 04:30:34 +01:00
// Explanation label
2020-12-14 00:20:10 +01:00
let explanationLabel = UILabel()
explanationLabel.textColor = Colors.text
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
explanationLabel.textAlignment = .center
explanationLabel.text = """
2020-12-14 04:30:34 +01:00
Weve upgraded Session IDs to make them even more private and secure. We recommend upgrading to a new Session ID now.
2020-12-14 00:20:10 +01:00
2020-12-14 04:30:34 +01:00
You will lose existing contacts and conversations, but youll gain even more privacy and security. You will need to upgrade your Session ID eventually, but you can choose to delay the upgrade if you need to save contacts or conversations.
2020-12-14 00:20:10 +01:00
"""
explanationLabel.numberOfLines = 0
explanationLabel.lineBreakMode = .byWordWrapping
2020-12-14 04:30:34 +01:00
// Upgrade now button
let upgradeNowButton = Button(style: .prominentOutline, size: .large)
upgradeNowButton.set(.width, to: 240)
upgradeNowButton.setTitle(NSLocalizedString("Upgrade Now", comment: ""), for: UIControl.State.normal)
upgradeNowButton.addTarget(self, action: #selector(upgradeNow), for: UIControl.Event.touchUpInside)
// Upgrade later button
let upgradeLaterButton = Button(style: .prominentOutline, size: .large)
upgradeLaterButton.set(.width, to: 240)
upgradeLaterButton.setTitle(NSLocalizedString("Upgrade Later", comment: ""), for: UIControl.State.normal)
upgradeLaterButton.addTarget(self, action: #selector(close), for: UIControl.Event.touchUpInside)
// Button stack view
let buttonStackView = UIStackView(arrangedSubviews: [ upgradeNowButton, upgradeLaterButton ])
buttonStackView.axis = .vertical
buttonStackView.spacing = Values.mediumSpacing
buttonStackView.alignment = .center
// Main stack view
let stackView = UIStackView(arrangedSubviews: [ topStackView, explanationLabel, buttonStackView ])
2020-12-14 00:20:10 +01:00
stackView.axis = .vertical
stackView.spacing = Values.veryLargeSpacing
stackView.alignment = .center
2020-12-14 04:30:34 +01:00
// Constraints
2020-12-14 00:20:10 +01:00
contentView.addSubview(stackView)
stackView.pin(.leading, to: .leading, of: contentView, withInset: Values.veryLargeSpacing)
stackView.pin(.top, to: .top, of: contentView, withInset: Values.largeSpacing)
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: Values.veryLargeSpacing)
contentView.pin(.bottom, to: .bottom, of: stackView, withInset: Values.veryLargeSpacing + overshoot)
}
2020-12-14 04:30:34 +01:00
@objc private func upgradeNow() {
guard let presentingVC = presentingViewController else { return }
let message = "Youre upgrading to a new Session ID. This will give you improved privacy and security, but it will clear ALL app data. Contacts and conversations will be lost. Proceed?"
let alert = UIAlertController(title: "Upgrade Session ID?", message: message, preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Yes", style: .destructive) { _ in
2020-12-14 04:43:17 +01:00
Storage.reset()
2020-12-14 04:30:34 +01:00
})
alert.addAction(UIAlertAction(title: "Cancel", style: .default, handler: nil))
presentingVC.dismiss(animated: true) { // Dismiss self first
presentingVC.present(alert, animated: true, completion: nil)
}
}
2020-12-14 00:20:10 +01:00
}