session-ios/Signal/src/Loki/Settings/NukeDataModal.swift
2019-11-20 16:27:34 +11:00

54 lines
2.6 KiB
Swift

@objc(LKNukeDataModal)
final class NukeDataModal : Modal {
// MARK: Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
Analytics.shared.track("Nuke Data Modal Shown")
}
override func populateContentView() {
// Label
let titleLabel = UILabel()
titleLabel.textColor = Theme.primaryColor
titleLabel.font = UIFont.ows_dynamicTypeHeadlineClamped
titleLabel.text = NSLocalizedString("Clear All Data", comment: "")
titleLabel.numberOfLines = 0
titleLabel.lineBreakMode = .byWordWrapping
titleLabel.textAlignment = .center
// Explanation label
let explanationLabel = UILabel()
explanationLabel.font = UIFont.ows_dynamicTypeCaption1Clamped
explanationLabel.text = NSLocalizedString("Are you sure you want to clear all your data? This will delete your entire account, including all conversations and your personal key pair.", comment: "")
explanationLabel.numberOfLines = 0
explanationLabel.textAlignment = .center
explanationLabel.lineBreakMode = .byWordWrapping
explanationLabel.textColor = UIColor.ows_white
// Button stack view
let nukeButton = OWSFlatButton.button(title: NSLocalizedString("OK", comment: ""), font: .ows_dynamicTypeBodyClamped, titleColor: .white, backgroundColor: .clear, target: self, selector: #selector(nuke))
nukeButton.setBackgroundColors(upColor: .clear, downColor: .clear)
let buttonStackView = UIStackView(arrangedSubviews: [ nukeButton, cancelButton ])
buttonStackView.axis = .horizontal
buttonStackView.distribution = .fillEqually
let buttonHeight = cancelButton.button.titleLabel!.font.pointSize * 48 / 17
nukeButton.set(.height, to: buttonHeight)
cancelButton.set(.height, to: buttonHeight)
// Stack view
let stackView = UIStackView(arrangedSubviews: [ UIView.spacer(withHeight: 2), titleLabel, explanationLabel, 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 nuke() {
Analytics.shared.track("Data Nuked")
NotificationCenter.default.post(name: .dataNukeRequested, object: nil)
}
}