mirror of https://github.com/oxen-io/session-ios
Clean up session restoration view UI
parent
48804db770
commit
a433d13177
@ -0,0 +1,84 @@
|
|||||||
|
|
||||||
|
@objc(LKSessionRestorationView)
|
||||||
|
final class SessionRestorationView : UIView {
|
||||||
|
private let thread: TSThread
|
||||||
|
@objc public var onRestore: (() -> Void)?
|
||||||
|
@objc public var onDismiss: (() -> Void)?
|
||||||
|
|
||||||
|
// MARK: Lifecycle
|
||||||
|
@objc init(thread: TSThread) {
|
||||||
|
self.thread = thread;
|
||||||
|
super.init(frame: CGRect.zero)
|
||||||
|
initialize()
|
||||||
|
}
|
||||||
|
|
||||||
|
required init?(coder: NSCoder) { fatalError("Using SessionRestorationView.init(coder:) isn't allowed. Use SessionRestorationView.init(thread:) instead.") }
|
||||||
|
override init(frame: CGRect) { fatalError("Using SessionRestorationView.init(frame:) isn't allowed. Use SessionRestorationView.init(thread:) instead.") }
|
||||||
|
|
||||||
|
private func initialize() {
|
||||||
|
// Set up background
|
||||||
|
backgroundColor = Colors.modalBackground
|
||||||
|
layer.cornerRadius = Values.modalCornerRadius
|
||||||
|
layer.masksToBounds = false
|
||||||
|
layer.borderColor = Colors.modalBorder.cgColor
|
||||||
|
layer.borderWidth = Values.borderThickness
|
||||||
|
layer.shadowColor = UIColor.black.cgColor
|
||||||
|
layer.shadowRadius = 8
|
||||||
|
layer.shadowOpacity = 0.64
|
||||||
|
// Set up title label
|
||||||
|
let titleLabel = UILabel()
|
||||||
|
titleLabel.textColor = Colors.text
|
||||||
|
titleLabel.font = .boldSystemFont(ofSize: Values.mediumFontSize)
|
||||||
|
titleLabel.text = NSLocalizedString("Session Out of Sync", comment: "")
|
||||||
|
titleLabel.numberOfLines = 0
|
||||||
|
titleLabel.lineBreakMode = .byWordWrapping
|
||||||
|
titleLabel.textAlignment = .center
|
||||||
|
// Set up explanation label
|
||||||
|
let explanationLabel = UILabel()
|
||||||
|
explanationLabel.textColor = Colors.text
|
||||||
|
explanationLabel.font = .systemFont(ofSize: Values.smallFontSize)
|
||||||
|
explanationLabel.text = NSLocalizedString("Would you like to restore your session?", comment: "")
|
||||||
|
explanationLabel.numberOfLines = 0
|
||||||
|
explanationLabel.textAlignment = .center
|
||||||
|
explanationLabel.lineBreakMode = .byWordWrapping
|
||||||
|
// Set up restore button
|
||||||
|
let restoreButton = UIButton()
|
||||||
|
restoreButton.set(.height, to: Values.mediumButtonHeight)
|
||||||
|
restoreButton.layer.cornerRadius = Values.modalButtonCornerRadius
|
||||||
|
restoreButton.backgroundColor = Colors.accent
|
||||||
|
restoreButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize)
|
||||||
|
restoreButton.setTitleColor(Colors.text, for: UIControl.State.normal)
|
||||||
|
restoreButton.setTitle(NSLocalizedString("Restore", comment: ""), for: UIControl.State.normal)
|
||||||
|
restoreButton.addTarget(self, action: #selector(restore), for: UIControl.Event.touchUpInside)
|
||||||
|
// Set up dismiss button
|
||||||
|
let dismissButton = UIButton()
|
||||||
|
dismissButton.set(.height, to: Values.mediumButtonHeight)
|
||||||
|
dismissButton.layer.cornerRadius = Values.modalButtonCornerRadius
|
||||||
|
dismissButton.backgroundColor = Colors.buttonBackground
|
||||||
|
dismissButton.titleLabel!.font = .systemFont(ofSize: Values.smallFontSize)
|
||||||
|
dismissButton.setTitleColor(Colors.text, for: UIControl.State.normal)
|
||||||
|
dismissButton.setTitle(NSLocalizedString("Dismiss", comment: ""), for: UIControl.State.normal)
|
||||||
|
dismissButton.addTarget(self, action: #selector(dismiss), for: UIControl.Event.touchUpInside)
|
||||||
|
// Set up button stack view
|
||||||
|
let buttonStackView = UIStackView(arrangedSubviews: [ dismissButton, restoreButton ])
|
||||||
|
buttonStackView.axis = .horizontal
|
||||||
|
buttonStackView.spacing = Values.mediumSpacing
|
||||||
|
buttonStackView.distribution = .fillEqually
|
||||||
|
// Set up main stack view
|
||||||
|
let mainStackView = UIStackView(arrangedSubviews: [ titleLabel, explanationLabel, buttonStackView ])
|
||||||
|
mainStackView.axis = .vertical
|
||||||
|
mainStackView.spacing = Values.smallSpacing
|
||||||
|
addSubview(mainStackView)
|
||||||
|
mainStackView.pin(to: self, withInset: Values.mediumSpacing)
|
||||||
|
// Update explanation label if possible
|
||||||
|
if let contactID = thread.contactIdentifier() {
|
||||||
|
let displayName = DisplayNameUtilities.getPrivateChatDisplayName(for: contactID) ?? contactID
|
||||||
|
explanationLabel.text = String(format: NSLocalizedString("Would you like to restore your session with %@?", comment: ""), displayName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Interaction
|
||||||
|
@objc private func restore() { onRestore?() }
|
||||||
|
|
||||||
|
@objc private func dismiss() { onDismiss?() }
|
||||||
|
}
|
@ -1,83 +0,0 @@
|
|||||||
@objc(LKSessionRestoreBannerView)
|
|
||||||
final class SessionRestoreBannerView : UIView {
|
|
||||||
private let thread: TSThread
|
|
||||||
@objc public var onRestore: (() -> Void)?
|
|
||||||
@objc public var onDismiss: (() -> Void)?
|
|
||||||
|
|
||||||
private lazy var bannerView: UIView = {
|
|
||||||
let bannerView = UIView.container()
|
|
||||||
bannerView.backgroundColor = UIColor.lokiGray()
|
|
||||||
bannerView.layer.cornerRadius = 2.5;
|
|
||||||
|
|
||||||
// Use a shadow to "pop" the indicator above the other views.
|
|
||||||
bannerView.layer.shadowColor = UIColor.black.cgColor
|
|
||||||
bannerView.layer.shadowOffset = CGSize(width: 2, height: 3)
|
|
||||||
bannerView.layer.shadowRadius = 2
|
|
||||||
bannerView.layer.shadowOpacity = 0.35
|
|
||||||
return bannerView
|
|
||||||
}()
|
|
||||||
|
|
||||||
private lazy var label: UILabel = {
|
|
||||||
let result = UILabel()
|
|
||||||
result.textColor = UIColor.white
|
|
||||||
result.font = UIFont.ows_dynamicTypeSubheadlineClamped
|
|
||||||
result.numberOfLines = 0
|
|
||||||
result.textAlignment = .center
|
|
||||||
result.lineBreakMode = .byWordWrapping
|
|
||||||
return result
|
|
||||||
}()
|
|
||||||
|
|
||||||
private lazy var buttonStackView: UIStackView = {
|
|
||||||
let result = UIStackView()
|
|
||||||
result.axis = .horizontal
|
|
||||||
result.distribution = .fillEqually
|
|
||||||
return result
|
|
||||||
}()
|
|
||||||
|
|
||||||
private lazy var buttonFont = UIFont.ows_dynamicTypeBodyClamped.ows_mediumWeight()
|
|
||||||
private lazy var buttonHeight = buttonFont.pointSize * 48 / 17
|
|
||||||
|
|
||||||
// MARK: Lifecycle
|
|
||||||
@objc init(thread: TSThread) {
|
|
||||||
self.thread = thread;
|
|
||||||
super.init(frame: CGRect.zero)
|
|
||||||
initialize()
|
|
||||||
}
|
|
||||||
|
|
||||||
required init?(coder: NSCoder) { fatalError("Using SessionRestoreBannerView.init(coder:) isn't allowed. Use SessionRestoreBannerView.init(thread:) instead.") }
|
|
||||||
override init(frame: CGRect) { fatalError("Using SessionRestoreBannerView.init(frame:) isn't allowed. Use SessionRestoreBannerView.init(thread:) instead.") }
|
|
||||||
|
|
||||||
private func initialize() {
|
|
||||||
// Set up UI
|
|
||||||
let mainStackView = UIStackView()
|
|
||||||
mainStackView.axis = .vertical
|
|
||||||
mainStackView.distribution = .fill
|
|
||||||
mainStackView.addArrangedSubview(label)
|
|
||||||
mainStackView.addArrangedSubview(buttonStackView)
|
|
||||||
|
|
||||||
let restoreButton = OWSFlatButton.button(title: NSLocalizedString("Restore session", comment: ""), font: buttonFont, titleColor: .ows_materialBlue, backgroundColor: .white, target: self, selector:#selector(restore))
|
|
||||||
restoreButton.setBackgroundColors(upColor: .clear, downColor: .clear)
|
|
||||||
restoreButton.autoSetDimension(.height, toSize: buttonHeight)
|
|
||||||
buttonStackView.addArrangedSubview(restoreButton)
|
|
||||||
|
|
||||||
let dismissButton = OWSFlatButton.button(title: NSLocalizedString("DISMISS_BUTTON_TEXT", comment: ""), font: buttonFont, titleColor: .ows_white, backgroundColor: .white, target: self, selector:#selector(dismiss))
|
|
||||||
dismissButton.setBackgroundColors(upColor: .clear, downColor: .clear)
|
|
||||||
dismissButton.autoSetDimension(.height, toSize: buttonHeight)
|
|
||||||
buttonStackView.addArrangedSubview(dismissButton)
|
|
||||||
|
|
||||||
bannerView.addSubview(mainStackView)
|
|
||||||
mainStackView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 16, left: 16, bottom: 8, right: 16))
|
|
||||||
|
|
||||||
addSubview(bannerView)
|
|
||||||
bannerView.autoPinEdgesToSuperviewEdges(with: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
|
|
||||||
|
|
||||||
if let contactID = thread.contactIdentifier() {
|
|
||||||
let displayName = Environment.shared.contactsManager.profileName(forRecipientId: contactID) ?? contactID
|
|
||||||
label.text = String(format: NSLocalizedString("Would you like to start a new session with %@?", comment: ""), displayName)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@objc private func restore() { onRestore?() }
|
|
||||||
|
|
||||||
@objc private func dismiss() { onDismiss?() }
|
|
||||||
}
|
|
Loading…
Reference in New Issue