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

115 lines
5.4 KiB
Swift
Raw Normal View History

2019-12-06 04:42:43 +01:00
2020-11-16 00:34:47 +01:00
final class LandingVC : BaseVC {
2019-12-09 01:50:45 +01:00
private var fakeChatViewContentOffset: CGPoint!
2019-12-06 04:42:43 +01:00
2019-12-09 00:01:10 +01:00
// MARK: Components
private lazy var fakeChatView: FakeChatView = {
let result = FakeChatView()
result.set(.height, to: Values.fakeChatViewHeight)
return result
}()
2019-12-12 06:07:08 +01:00
private lazy var registerButton: Button = {
let result = Button(style: .prominentFilled, size: .large)
result.setTitle(NSLocalizedString("vc_landing_register_button_title", comment: ""), for: UIControl.State.normal)
2019-12-12 06:07:08 +01:00
result.titleLabel!.font = .boldSystemFont(ofSize: Values.mediumFontSize)
result.addTarget(self, action: #selector(register), for: UIControl.Event.touchUpInside)
return result
}()
private lazy var restoreButton: Button = {
let result = Button(style: .prominentOutline, size: .large)
result.setTitle(NSLocalizedString("vc_landing_restore_button_title", comment: ""), for: UIControl.State.normal)
2019-12-12 06:07:08 +01:00
result.titleLabel!.font = .boldSystemFont(ofSize: Values.mediumFontSize)
result.addTarget(self, action: #selector(restore), for: UIControl.Event.touchUpInside)
return result
}()
2019-12-06 04:42:43 +01:00
// MARK: Lifecycle
override func viewDidLoad() {
2020-02-20 04:37:17 +01:00
super.viewDidLoad()
setUpGradientBackground()
setUpNavBarStyle()
setUpNavBarSessionIcon()
2019-12-06 04:42:43 +01:00
// Set up title label
let titleLabel = UILabel()
titleLabel.textColor = Colors.text
2020-06-18 06:41:02 +02:00
titleLabel.font = .boldSystemFont(ofSize: isIPhone5OrSmaller ? Values.largeFontSize : Values.veryLargeFontSize)
titleLabel.text = NSLocalizedString("vc_landing_title_2", comment: "")
2019-12-06 04:42:43 +01:00
titleLabel.numberOfLines = 0
titleLabel.lineBreakMode = .byWordWrapping
// Set up title label container
let titleLabelContainer = UIView()
titleLabelContainer.addSubview(titleLabel)
titleLabel.pin(.leading, to: .leading, of: titleLabelContainer, withInset: Values.veryLargeSpacing)
titleLabel.pin(.top, to: .top, of: titleLabelContainer)
titleLabelContainer.pin(.trailing, to: .trailing, of: titleLabel, withInset: Values.veryLargeSpacing)
titleLabelContainer.pin(.bottom, to: .bottom, of: titleLabel)
2019-12-09 00:01:10 +01:00
// Set up spacers
let topSpacer = UIView.vStretchingSpacer()
let bottomSpacer = UIView.vStretchingSpacer()
2019-12-12 06:07:08 +01:00
// Set up link button container
let linkButtonContainer = UIView()
linkButtonContainer.set(.height, to: Values.onboardingButtonBottomOffset)
2019-12-06 04:42:43 +01:00
// Set up button stack view
let buttonStackView = UIStackView(arrangedSubviews: [ registerButton, restoreButton ])
buttonStackView.axis = .vertical
2020-06-18 06:41:02 +02:00
buttonStackView.spacing = isIPhone5OrSmaller ? Values.smallSpacing : Values.mediumSpacing
2019-12-06 04:42:43 +01:00
buttonStackView.alignment = .fill
2019-12-09 00:01:10 +01:00
// Set up button stack view container
let buttonStackViewContainer = UIView()
buttonStackViewContainer.addSubview(buttonStackView)
2020-07-29 03:33:43 +02:00
buttonStackView.pin(.leading, to: .leading, of: buttonStackViewContainer, withInset: isIPhone5OrSmaller ? CGFloat(52) : Values.massiveSpacing)
2019-12-09 00:01:10 +01:00
buttonStackView.pin(.top, to: .top, of: buttonStackViewContainer)
2020-07-29 03:33:43 +02:00
buttonStackViewContainer.pin(.trailing, to: .trailing, of: buttonStackView, withInset: isIPhone5OrSmaller ? CGFloat(52) : Values.massiveSpacing)
2019-12-09 00:01:10 +01:00
buttonStackViewContainer.pin(.bottom, to: .bottom, of: buttonStackView)
// Set up main stack view
2020-06-18 06:41:02 +02:00
let mainStackView = UIStackView(arrangedSubviews: [ topSpacer, titleLabelContainer, UIView.spacer(withHeight: isIPhone5OrSmaller ? Values.smallSpacing : Values.mediumSpacing), fakeChatView, bottomSpacer, buttonStackViewContainer, linkButtonContainer ])
2019-12-09 00:01:10 +01:00
mainStackView.axis = .vertical
mainStackView.alignment = .fill
view.addSubview(mainStackView)
mainStackView.pin(to: view)
topSpacer.heightAnchor.constraint(equalTo: bottomSpacer.heightAnchor, multiplier: 1).isActive = true
2020-12-16 06:22:46 +01:00
// Auto-migrate if needed
let userDefaults = UserDefaults.standard
if userDefaults[.isMigratingToV2KeyPair] {
if userDefaults[.displayName] != nil {
Storage.finishV2KeyPairMigration(navigationController: navigationController!)
}
}
2019-12-06 06:42:28 +01:00
}
2019-12-09 01:50:45 +01:00
override func viewDidDisappear(_ animated: Bool) {
super.viewDidAppear(animated)
2020-01-21 04:02:53 +01:00
if let fakeChatViewContentOffset = fakeChatViewContentOffset {
fakeChatView.contentOffset = fakeChatViewContentOffset
}
2019-12-09 01:50:45 +01:00
}
2019-12-06 06:42:28 +01:00
// MARK: Interaction
@objc private func register() {
2019-12-09 01:50:45 +01:00
fakeChatViewContentOffset = fakeChatView.contentOffset
DispatchQueue.main.async {
self.fakeChatView.contentOffset = self.fakeChatViewContentOffset
}
2019-12-09 02:33:40 +01:00
let registerVC = RegisterVC()
navigationController!.pushViewController(registerVC, animated: true)
}
@objc private func restore() {
fakeChatViewContentOffset = fakeChatView.contentOffset
DispatchQueue.main.async {
self.fakeChatView.contentOffset = self.fakeChatViewContentOffset
}
let restoreVC = RestoreVC()
navigationController!.pushViewController(restoreVC, animated: true)
2019-12-06 04:42:43 +01:00
}
2019-12-12 06:07:08 +01:00
// MARK: Convenience
private func setUserInteractionEnabled(_ isEnabled: Bool) {
2020-11-16 00:34:47 +01:00
[ registerButton, restoreButton ].forEach {
2019-12-12 06:07:08 +01:00
$0.isUserInteractionEnabled = isEnabled
}
}
2019-12-06 04:42:43 +01:00
}