|
|
@ -44,12 +44,21 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lazy var buttonStackView: UIStackView = {
|
|
|
|
|
|
|
|
let result = UIStackView(arrangedSubviews: [ authorizeButton, cancelButton ])
|
|
|
|
|
|
|
|
result.axis = .horizontal
|
|
|
|
|
|
|
|
result.distribution = .fillEqually
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
private lazy var authorizeButton: OWSFlatButton = {
|
|
|
|
private lazy var authorizeButton: OWSFlatButton = {
|
|
|
|
let result = OWSFlatButton.button(title: NSLocalizedString("Authorize", comment: ""), font: .ows_dynamicTypeBodyClamped, titleColor: .white, backgroundColor: .clear, target: self, selector: #selector(authorizeDeviceLink))
|
|
|
|
let result = OWSFlatButton.button(title: NSLocalizedString("Authorize", comment: ""), font: .ows_dynamicTypeBodyClamped, titleColor: .white, backgroundColor: .clear, target: self, selector: #selector(authorizeDeviceLink))
|
|
|
|
result.setBackgroundColors(upColor: .clear, downColor: .clear)
|
|
|
|
result.setBackgroundColors(upColor: .clear, downColor: .clear)
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}()
|
|
|
|
}()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private lazy var bottomSpacer = UIView.spacer(withHeight: 8)
|
|
|
|
|
|
|
|
|
|
|
|
// MARK: Lifecycle
|
|
|
|
// MARK: Lifecycle
|
|
|
|
init(mode: Mode, delegate: DeviceLinkingModalDelegate?) {
|
|
|
|
init(mode: Mode, delegate: DeviceLinkingModalDelegate?) {
|
|
|
|
self.mode = mode
|
|
|
|
self.mode = mode
|
|
|
@ -78,13 +87,10 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override func populateContentView() {
|
|
|
|
override func populateContentView() {
|
|
|
|
let buttonStackView = UIStackView(arrangedSubviews: [ authorizeButton, cancelButton ])
|
|
|
|
let stackView = UIStackView(arrangedSubviews: [ topSpacer, spinner, UIView.spacer(withHeight: 8), titleLabel, subtitleLabel, mnemonicLabel, buttonStackView, bottomSpacer ])
|
|
|
|
let stackView = UIStackView(arrangedSubviews: [ topSpacer, spinner, UIView.spacer(withHeight: 8), titleLabel, subtitleLabel, mnemonicLabel, buttonStackView ])
|
|
|
|
|
|
|
|
contentView.addSubview(stackView)
|
|
|
|
contentView.addSubview(stackView)
|
|
|
|
stackView.spacing = 16
|
|
|
|
stackView.spacing = 16
|
|
|
|
stackView.axis = .vertical
|
|
|
|
stackView.axis = .vertical
|
|
|
|
buttonStackView.axis = .horizontal
|
|
|
|
|
|
|
|
buttonStackView.distribution = .fillEqually
|
|
|
|
|
|
|
|
spinner.set(.height, to: 64)
|
|
|
|
spinner.set(.height, to: 64)
|
|
|
|
spinner.startAnimating()
|
|
|
|
spinner.startAnimating()
|
|
|
|
titleLabel.text = {
|
|
|
|
titleLabel.text = {
|
|
|
@ -108,6 +114,7 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
|
|
|
|
authorizeButton.set(.height, to: buttonHeight)
|
|
|
|
authorizeButton.set(.height, to: buttonHeight)
|
|
|
|
cancelButton.set(.height, to: buttonHeight)
|
|
|
|
cancelButton.set(.height, to: buttonHeight)
|
|
|
|
authorizeButton.isHidden = true
|
|
|
|
authorizeButton.isHidden = true
|
|
|
|
|
|
|
|
bottomSpacer.isHidden = true
|
|
|
|
stackView.pin(.leading, to: .leading, of: contentView, withInset: 16)
|
|
|
|
stackView.pin(.leading, to: .leading, of: contentView, withInset: 16)
|
|
|
|
stackView.pin(.top, to: .top, of: contentView, withInset: 16)
|
|
|
|
stackView.pin(.top, to: .top, of: contentView, withInset: 16)
|
|
|
|
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: 16)
|
|
|
|
contentView.pin(.trailing, to: .trailing, of: stackView, withInset: 16)
|
|
|
@ -141,8 +148,18 @@ final class DeviceLinkingModal : Modal, DeviceLinkingSessionDelegate {
|
|
|
|
func handleDeviceLinkAuthorized(_ deviceLink: DeviceLink) {
|
|
|
|
func handleDeviceLinkAuthorized(_ deviceLink: DeviceLink) {
|
|
|
|
let session = DeviceLinkingSession.current!
|
|
|
|
let session = DeviceLinkingSession.current!
|
|
|
|
session.stopListeningForLinkingAuthorization()
|
|
|
|
session.stopListeningForLinkingAuthorization()
|
|
|
|
delegate?.handleDeviceLinkAuthorized(deviceLink)
|
|
|
|
topSpacer.isHidden = true
|
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
|
spinner.stopAnimating()
|
|
|
|
|
|
|
|
spinner.isHidden = true
|
|
|
|
|
|
|
|
titleLabel.text = NSLocalizedString("Device Link Authorized", comment: "")
|
|
|
|
|
|
|
|
subtitleLabel.text = NSLocalizedString("Your device has been linked successfully", comment: "")
|
|
|
|
|
|
|
|
mnemonicLabel.isHidden = true
|
|
|
|
|
|
|
|
buttonStackView.isHidden = true
|
|
|
|
|
|
|
|
bottomSpacer.isHidden = false
|
|
|
|
|
|
|
|
Timer.scheduledTimer(withTimeInterval: 2, repeats: false) { _ in
|
|
|
|
|
|
|
|
self.delegate?.handleDeviceLinkAuthorized(deviceLink)
|
|
|
|
|
|
|
|
self.dismiss(animated: true, completion: nil)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@objc override func cancel() {
|
|
|
|
@objc override func cancel() {
|
|
|
|