mirror of https://github.com/oxen-io/session-ios
Fix inconsistent modal usage
parent
f88a0f3c1f
commit
f3c80e9790
@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
@objc(LKModal)
|
||||||
|
internal class Modal : UIViewController {
|
||||||
|
|
||||||
|
// MARK: Components
|
||||||
|
lazy var contentView: UIView = {
|
||||||
|
let result = UIView()
|
||||||
|
result.backgroundColor = .lokiDarkGray()
|
||||||
|
result.layer.cornerRadius = 4
|
||||||
|
result.layer.masksToBounds = false
|
||||||
|
result.layer.shadowColor = UIColor.black.cgColor
|
||||||
|
result.layer.shadowRadius = 8
|
||||||
|
result.layer.shadowOpacity = 0.64
|
||||||
|
return result
|
||||||
|
}()
|
||||||
|
|
||||||
|
lazy var cancelButton: OWSFlatButton = {
|
||||||
|
let result = OWSFlatButton.button(title: NSLocalizedString("Cancel", comment: ""), font: .ows_dynamicTypeBodyClamped, titleColor: .white, backgroundColor: .clear, target: self, selector: #selector(cancel))
|
||||||
|
result.setBackgroundColors(upColor: .clear, downColor: .clear)
|
||||||
|
return result
|
||||||
|
}()
|
||||||
|
|
||||||
|
// MARK: Lifecycle
|
||||||
|
override func viewDidLoad() {
|
||||||
|
super.viewDidLoad()
|
||||||
|
setUpViewHierarchy()
|
||||||
|
}
|
||||||
|
|
||||||
|
private func setUpViewHierarchy() {
|
||||||
|
view.backgroundColor = .clear
|
||||||
|
view.addSubview(contentView)
|
||||||
|
contentView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 32).isActive = true
|
||||||
|
view.trailingAnchor.constraint(equalTo: contentView.trailingAnchor, constant: 32).isActive = true
|
||||||
|
contentView.center(.vertical, in: view)
|
||||||
|
populateContentView()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// To be overridden by subclasses.
|
||||||
|
func populateContentView() {
|
||||||
|
preconditionFailure("populateContentView() is abstract and must be overridden.")
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Interaction
|
||||||
|
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
|
||||||
|
let touch = touches.first!
|
||||||
|
let location = touch.location(in: view)
|
||||||
|
if contentView.frame.contains(location) {
|
||||||
|
super.touchesBegan(touches, with: event)
|
||||||
|
} else {
|
||||||
|
cancel()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@objc private func cancel() {
|
||||||
|
dismiss(animated: true, completion: nil)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
@objc(LKQRCodeModal)
|
||||||
|
final class QRCodeModal : Modal {
|
||||||
|
|
||||||
|
override func populateContentView() {
|
||||||
|
// Label
|
||||||
|
let label = UILabel()
|
||||||
|
label.font = UIFont.ows_dynamicTypeSubheadlineClamped
|
||||||
|
label.text = NSLocalizedString("This is your personal QR code. Other people can scan it to start a secure conversation with you.", comment: "")
|
||||||
|
label.numberOfLines = 0
|
||||||
|
label.textAlignment = .center
|
||||||
|
label.lineBreakMode = .byWordWrapping
|
||||||
|
label.textColor = UIColor.ows_white
|
||||||
|
// Image view
|
||||||
|
let imageView = UIImageView()
|
||||||
|
let hexEncodedPublicKey = OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
|
||||||
|
let data = hexEncodedPublicKey.data(using: .utf8)
|
||||||
|
let filter = CIFilter(name: "CIQRCodeGenerator")!
|
||||||
|
filter.setValue(data, forKey: "inputMessage")
|
||||||
|
let qrCodeAsCIImage = filter.outputImage!
|
||||||
|
let scaledQRCodeAsCIImage = qrCodeAsCIImage.transformed(by: CGAffineTransform(scaleX: 4.8, y: 4.8))
|
||||||
|
let qrCode = UIImage(ciImage: scaledQRCodeAsCIImage)
|
||||||
|
imageView.image = qrCode
|
||||||
|
// Cancel button
|
||||||
|
let buttonHeight = cancelButton.button.titleLabel!.font.pointSize * 48 / 17
|
||||||
|
cancelButton.set(.height, to: buttonHeight)
|
||||||
|
// Stack view
|
||||||
|
let stackView = UIStackView(arrangedSubviews: [ UIView.spacer(withHeight: 2), label, UIView.spacer(withHeight: 2), imageView, cancelButton ])
|
||||||
|
stackView.axis = .vertical
|
||||||
|
stackView.spacing = 16
|
||||||
|
stackView.alignment = .center
|
||||||
|
contentView.addSubview(stackView)
|
||||||
|
stackView.pin(.leading, to: .leading, of: contentView, withInset: 16)
|
||||||
|
stackView.pin(.top, to: .top, of: contentView, withInset: 16)
|
||||||
|
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: 16)
|
||||||
|
contentView.pin(.bottom, to: .bottom, of: stackView, withInset: 16)
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
import NVActivityIndicatorView
|
||||||
|
|
||||||
|
@objc(LKSeedModal)
|
||||||
|
final class SeedModal : Modal {
|
||||||
|
|
||||||
|
private let mnemonic: String = {
|
||||||
|
let identityManager = OWSIdentityManager.shared()
|
||||||
|
let databaseConnection = identityManager.value(forKey: "dbConnection") as! YapDatabaseConnection
|
||||||
|
var hexEncodedSeed: String! = databaseConnection.object(forKey: "LKLokiSeed", inCollection: OWSPrimaryStorageIdentityKeyStoreCollection) as! String?
|
||||||
|
if hexEncodedSeed == nil {
|
||||||
|
hexEncodedSeed = identityManager.identityKeyPair()!.hexEncodedPrivateKey // Legacy account
|
||||||
|
}
|
||||||
|
return Mnemonic.encode(hexEncodedString: hexEncodedSeed)
|
||||||
|
}()
|
||||||
|
|
||||||
|
// MARK: Lifecycle
|
||||||
|
override func populateContentView() {
|
||||||
|
// Label
|
||||||
|
let titleLabel = UILabel()
|
||||||
|
titleLabel.textColor = Theme.primaryColor
|
||||||
|
titleLabel.font = UIFont.ows_dynamicTypeHeadlineClamped
|
||||||
|
titleLabel.text = NSLocalizedString("Your Seed", comment: "")
|
||||||
|
titleLabel.numberOfLines = 0
|
||||||
|
titleLabel.lineBreakMode = .byWordWrapping
|
||||||
|
titleLabel.textAlignment = .center
|
||||||
|
// Mnemonic label
|
||||||
|
let mnemonicLabel = UILabel()
|
||||||
|
mnemonicLabel.font = UIFont.ows_dynamicTypeCaption1Clamped
|
||||||
|
mnemonicLabel.text = mnemonic
|
||||||
|
mnemonicLabel.numberOfLines = 0
|
||||||
|
mnemonicLabel.textAlignment = .center
|
||||||
|
mnemonicLabel.lineBreakMode = .byWordWrapping
|
||||||
|
mnemonicLabel.textColor = UIColor.ows_white
|
||||||
|
// Button stack view
|
||||||
|
let copyButton = OWSFlatButton.button(title: NSLocalizedString("Copy", comment: ""), font: .ows_dynamicTypeBodyClamped, titleColor: .white, backgroundColor: .clear, target: self, selector: #selector(copySeed))
|
||||||
|
copyButton.setBackgroundColors(upColor: .clear, downColor: .clear)
|
||||||
|
let buttonStackView = UIStackView(arrangedSubviews: [ copyButton, cancelButton ])
|
||||||
|
buttonStackView.axis = .horizontal
|
||||||
|
buttonStackView.distribution = .fillEqually
|
||||||
|
let buttonHeight = cancelButton.button.titleLabel!.font.pointSize * 48 / 17
|
||||||
|
copyButton.set(.height, to: buttonHeight)
|
||||||
|
cancelButton.set(.height, to: buttonHeight)
|
||||||
|
// Stack view
|
||||||
|
let stackView = UIStackView(arrangedSubviews: [ UIView.spacer(withHeight: 2), titleLabel, mnemonicLabel, buttonStackView ])
|
||||||
|
stackView.axis = .vertical
|
||||||
|
stackView.spacing = 16
|
||||||
|
contentView.addSubview(stackView)
|
||||||
|
stackView.pin(.leading, to: .leading, of: contentView, withInset: 16)
|
||||||
|
stackView.pin(.top, to: .top, of: contentView, withInset: 16)
|
||||||
|
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: 16)
|
||||||
|
contentView.pin(.bottom, to: .bottom, of: stackView, withInset: 16)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Interaction
|
||||||
|
@objc private func copySeed() {
|
||||||
|
UIPasteboard.general.string = mnemonic
|
||||||
|
dismiss(animated: true, completion: nil)
|
||||||
|
}
|
||||||
|
}
|
@ -1,40 +0,0 @@
|
|||||||
|
|
||||||
final class QRCodeViewController : OWSViewController {
|
|
||||||
|
|
||||||
public override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return .portrait}
|
|
||||||
public override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent}
|
|
||||||
|
|
||||||
override func viewDidLoad() {
|
|
||||||
super.viewDidLoad()
|
|
||||||
view.backgroundColor = UIColor.lokiDarkestGray()
|
|
||||||
let stackView = UIStackView(arrangedSubviews: [])
|
|
||||||
stackView.axis = .vertical
|
|
||||||
stackView.spacing = 32
|
|
||||||
stackView.alignment = .center
|
|
||||||
stackView.translatesAutoresizingMaskIntoConstraints = false
|
|
||||||
view.addSubview(stackView)
|
|
||||||
NSLayoutConstraint.activate([
|
|
||||||
stackView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 32),
|
|
||||||
stackView.topAnchor.constraint(equalTo: view.topAnchor, constant: 24),
|
|
||||||
view.trailingAnchor.constraint(equalTo: stackView.trailingAnchor, constant: 32)
|
|
||||||
])
|
|
||||||
let label = UILabel()
|
|
||||||
label.font = UIFont.ows_dynamicTypeSubheadlineClamped
|
|
||||||
label.text = NSLocalizedString("This is your personal QR code. Other people can scan it to start a secure conversation with you.", comment: "")
|
|
||||||
label.numberOfLines = 0
|
|
||||||
label.textAlignment = .center
|
|
||||||
label.lineBreakMode = .byWordWrapping
|
|
||||||
label.textColor = UIColor.ows_white
|
|
||||||
stackView.addArrangedSubview(label)
|
|
||||||
let imageView = UIImageView()
|
|
||||||
let hexEncodedPublicKey = OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
|
|
||||||
let data = hexEncodedPublicKey.data(using: .utf8)
|
|
||||||
let filter = CIFilter(name: "CIQRCodeGenerator")!
|
|
||||||
filter.setValue(data, forKey: "inputMessage")
|
|
||||||
let qrCodeAsCIImage = filter.outputImage!
|
|
||||||
let scaledQRCodeAsCIImage = qrCodeAsCIImage.transformed(by: CGAffineTransform(scaleX: 6.4, y: 6.4))
|
|
||||||
let qrCode = UIImage(ciImage: scaledQRCodeAsCIImage)
|
|
||||||
imageView.image = qrCode
|
|
||||||
stackView.addArrangedSubview(imageView)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue