2019-12-04 06:54:46 +01:00
|
|
|
|
|
|
|
final class SettingsVC : UIViewController {
|
|
|
|
|
|
|
|
private lazy var userHexEncodedPublicKey: String = {
|
2019-12-05 04:31:45 +01:00
|
|
|
if let masterHexEncodedPublicKey = UserDefaults.standard.string(forKey: "masterDeviceHexEncodedPublicKey") {
|
2019-12-04 06:54:46 +01:00
|
|
|
return masterHexEncodedPublicKey
|
|
|
|
} else {
|
|
|
|
return OWSIdentityManager.shared().identityKeyPair()!.hexEncodedPublicKey
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
|
|
|
// MARK: Settings
|
|
|
|
override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent }
|
|
|
|
|
|
|
|
// MARK: Components
|
2019-12-05 00:10:09 +01:00
|
|
|
private lazy var profilePictureView: ProfilePictureView = {
|
|
|
|
let result = ProfilePictureView()
|
|
|
|
let size = Values.largeProfilePictureSize
|
|
|
|
result.size = size
|
|
|
|
result.set(.width, to: size)
|
|
|
|
result.set(.height, to: size)
|
|
|
|
return result
|
|
|
|
}()
|
|
|
|
|
|
|
|
private lazy var displayNameLabel: UILabel = {
|
|
|
|
let result = UILabel()
|
|
|
|
result.textColor = Colors.text
|
|
|
|
result.font = .boldSystemFont(ofSize: Values.largeFontSize)
|
|
|
|
result.lineBreakMode = .byTruncatingTail
|
|
|
|
return result
|
|
|
|
}()
|
|
|
|
|
2019-12-04 06:54:46 +01:00
|
|
|
private lazy var copyButton: Button = {
|
2019-12-05 00:10:09 +01:00
|
|
|
let result = Button(style: .prominent, size: .medium)
|
2019-12-04 06:54:46 +01:00
|
|
|
result.setTitle(NSLocalizedString("Copy", comment: ""), for: UIControl.State.normal)
|
|
|
|
result.addTarget(self, action: #selector(copyPublicKey), for: UIControl.Event.touchUpInside)
|
|
|
|
return result
|
|
|
|
}()
|
|
|
|
|
|
|
|
// MARK: Lifecycle
|
|
|
|
override func viewDidLoad() {
|
|
|
|
// Set gradient background
|
|
|
|
view.backgroundColor = .clear
|
|
|
|
let gradient = Gradients.defaultLokiBackground
|
|
|
|
view.setGradient(gradient)
|
|
|
|
// Set navigation bar background color
|
|
|
|
let navigationBar = navigationController!.navigationBar
|
|
|
|
navigationBar.setBackgroundImage(UIImage(), for: UIBarMetrics.default)
|
|
|
|
navigationBar.shadowImage = UIImage()
|
|
|
|
navigationBar.isTranslucent = false
|
|
|
|
navigationBar.barTintColor = Colors.navigationBarBackground
|
|
|
|
// Set up navigation bar buttons
|
|
|
|
let closeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "X"), style: .plain, target: self, action: #selector(close))
|
|
|
|
closeButton.tintColor = Colors.text
|
|
|
|
navigationItem.leftBarButtonItem = closeButton
|
2019-12-05 04:31:45 +01:00
|
|
|
let backButton = UIBarButtonItem(title: NSLocalizedString("Back", comment: ""), style: .plain, target: nil, action: nil)
|
|
|
|
backButton.tintColor = Colors.text
|
|
|
|
navigationItem.backBarButtonItem = backButton
|
2019-12-04 06:54:46 +01:00
|
|
|
let qrCodeButton = UIBarButtonItem(image: #imageLiteral(resourceName: "QRCodeFilled"), style: .plain, target: self, action: #selector(showQRCode))
|
|
|
|
qrCodeButton.tintColor = Colors.text
|
|
|
|
navigationItem.rightBarButtonItem = qrCodeButton
|
|
|
|
// Customize title
|
|
|
|
let titleLabel = UILabel()
|
|
|
|
titleLabel.text = NSLocalizedString("Settings", comment: "")
|
|
|
|
titleLabel.textColor = Colors.text
|
2019-12-05 04:31:45 +01:00
|
|
|
titleLabel.font = .boldSystemFont(ofSize: Values.veryLargeFontSize)
|
2019-12-04 06:54:46 +01:00
|
|
|
navigationItem.titleView = titleLabel
|
|
|
|
// Set up profile picture view
|
|
|
|
profilePictureView.hexEncodedPublicKey = userHexEncodedPublicKey
|
|
|
|
profilePictureView.update()
|
|
|
|
// Set up display name label
|
|
|
|
displayNameLabel.text = OWSProfileManager.shared().profileName(forRecipientId: userHexEncodedPublicKey)
|
|
|
|
// Set up header view
|
|
|
|
let headerStackView = UIStackView(arrangedSubviews: [ profilePictureView, displayNameLabel ])
|
|
|
|
headerStackView.axis = .vertical
|
|
|
|
headerStackView.spacing = Values.smallSpacing
|
|
|
|
headerStackView.alignment = .center
|
|
|
|
// Set up separator
|
|
|
|
let separator = Separator(title: NSLocalizedString("Your Public Key", comment: ""))
|
|
|
|
// Set up public key label
|
|
|
|
let publicKeyLabel = UILabel()
|
|
|
|
publicKeyLabel.textColor = Colors.text
|
|
|
|
publicKeyLabel.font = Fonts.spaceMono(ofSize: Values.largeFontSize)
|
|
|
|
publicKeyLabel.numberOfLines = 0
|
|
|
|
publicKeyLabel.textAlignment = .center
|
|
|
|
publicKeyLabel.lineBreakMode = .byCharWrapping
|
|
|
|
publicKeyLabel.text = userHexEncodedPublicKey
|
|
|
|
// Set up share button
|
2019-12-05 00:10:09 +01:00
|
|
|
let shareButton = Button(style: .regular, size: .medium)
|
2019-12-04 06:54:46 +01:00
|
|
|
shareButton.setTitle(NSLocalizedString("Share", comment: ""), for: UIControl.State.normal)
|
|
|
|
shareButton.addTarget(self, action: #selector(sharePublicKey), for: UIControl.Event.touchUpInside)
|
|
|
|
// Set up button container
|
|
|
|
let buttonContainer = UIStackView(arrangedSubviews: [ copyButton, shareButton ])
|
|
|
|
buttonContainer.axis = .horizontal
|
|
|
|
buttonContainer.spacing = Values.mediumSpacing
|
|
|
|
buttonContainer.distribution = .fillEqually
|
2019-12-05 00:10:09 +01:00
|
|
|
// Set up top stack view
|
|
|
|
let topStackView = UIStackView(arrangedSubviews: [ headerStackView, separator, publicKeyLabel, buttonContainer ])
|
|
|
|
topStackView.axis = .vertical
|
|
|
|
topStackView.spacing = Values.largeSpacing
|
|
|
|
topStackView.alignment = .fill
|
|
|
|
topStackView.layoutMargins = UIEdgeInsets(top: 0, left: Values.largeSpacing, bottom: 0, right: Values.largeSpacing)
|
|
|
|
topStackView.isLayoutMarginsRelativeArrangement = true
|
|
|
|
// Set up setting buttons stack view
|
|
|
|
let settingButtonsStackView = UIStackView(arrangedSubviews: getSettingButtons())
|
|
|
|
settingButtonsStackView.axis = .vertical
|
|
|
|
settingButtonsStackView.alignment = .fill
|
2019-12-04 06:54:46 +01:00
|
|
|
// Set up stack view
|
2019-12-05 00:10:09 +01:00
|
|
|
let stackView = UIStackView(arrangedSubviews: [ topStackView, settingButtonsStackView ])
|
2019-12-04 06:54:46 +01:00
|
|
|
stackView.axis = .vertical
|
|
|
|
stackView.spacing = Values.largeSpacing
|
|
|
|
stackView.alignment = .fill
|
2019-12-05 00:10:09 +01:00
|
|
|
stackView.layoutMargins = UIEdgeInsets(top: Values.mediumSpacing, left: 0, bottom: Values.mediumSpacing, right: 0)
|
2019-12-04 06:54:46 +01:00
|
|
|
stackView.isLayoutMarginsRelativeArrangement = true
|
2019-12-05 00:10:09 +01:00
|
|
|
stackView.set(.width, to: UIScreen.main.bounds.width)
|
|
|
|
// Set up scroll view
|
|
|
|
let scrollView = UIScrollView()
|
|
|
|
scrollView.showsVerticalScrollIndicator = false
|
|
|
|
scrollView.addSubview(stackView)
|
|
|
|
stackView.pin(to: scrollView)
|
|
|
|
view.addSubview(scrollView)
|
|
|
|
scrollView.pin(to: view)
|
|
|
|
}
|
|
|
|
|
|
|
|
private func getSettingButtons() -> [UIButton] {
|
|
|
|
func getSettingButton(withTitle title: String, color: UIColor, action selector: Selector) -> UIButton {
|
|
|
|
let button = UIButton()
|
|
|
|
button.setTitle(title, for: UIControl.State.normal)
|
|
|
|
button.setTitleColor(color, for: UIControl.State.normal)
|
|
|
|
button.titleLabel!.font = .boldSystemFont(ofSize: Values.mediumFontSize)
|
|
|
|
button.titleLabel!.textAlignment = .center
|
|
|
|
func getImage(withColor color: UIColor) -> UIImage {
|
|
|
|
let rect = CGRect(origin: CGPoint.zero, size: CGSize(width: 1, height: 1))
|
|
|
|
UIGraphicsBeginImageContext(rect.size)
|
|
|
|
let context = UIGraphicsGetCurrentContext()!
|
|
|
|
context.setFillColor(color.cgColor)
|
|
|
|
context.fill(rect)
|
|
|
|
let image = UIGraphicsGetImageFromCurrentImageContext()
|
|
|
|
UIGraphicsEndImageContext()
|
|
|
|
return image!
|
|
|
|
}
|
2019-12-05 01:42:31 +01:00
|
|
|
button.setBackgroundImage(getImage(withColor: Colors.buttonBackground), for: UIControl.State.normal)
|
2019-12-05 00:10:09 +01:00
|
|
|
button.setBackgroundImage(getImage(withColor: Colors.settingButtonSelected), for: UIControl.State.highlighted)
|
|
|
|
button.addTarget(self, action: selector, for: UIControl.Event.touchUpInside)
|
2019-12-05 04:31:45 +01:00
|
|
|
button.set(.height, to: Values.settingButtonHeight)
|
2019-12-05 00:10:09 +01:00
|
|
|
return button
|
|
|
|
}
|
2019-12-05 04:31:45 +01:00
|
|
|
var result = [
|
2019-12-05 00:10:09 +01:00
|
|
|
getSettingButton(withTitle: NSLocalizedString("Privacy", comment: ""), color: Colors.text, action: #selector(showPrivacySettings)),
|
2019-12-05 04:31:45 +01:00
|
|
|
getSettingButton(withTitle: NSLocalizedString("Notifications", comment: ""), color: Colors.text, action: #selector(showNotificationSettings))
|
2019-12-05 00:10:09 +01:00
|
|
|
]
|
2019-12-05 04:31:45 +01:00
|
|
|
let isMasterDevice = (UserDefaults.standard.string(forKey: "masterDeviceHexEncodedPublicKey") == nil)
|
|
|
|
if isMasterDevice {
|
|
|
|
result.append(getSettingButton(withTitle: NSLocalizedString("Linked Devices", comment: ""), color: Colors.text, action: #selector(showLinkedDevices)))
|
|
|
|
result.append(getSettingButton(withTitle: NSLocalizedString("Show Seed", comment: ""), color: Colors.text, action: #selector(showSeed)))
|
|
|
|
}
|
|
|
|
result.append(getSettingButton(withTitle: NSLocalizedString("Clear All Data", comment: ""), color: Colors.destructive, action: #selector(clearAllData)))
|
|
|
|
return result
|
2019-12-05 00:10:09 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
|
|
super.viewWillAppear(animated)
|
|
|
|
profilePictureView.update()
|
|
|
|
displayNameLabel.text = OWSProfileManager.shared().profileName(forRecipientId: userHexEncodedPublicKey)
|
2019-12-04 06:54:46 +01:00
|
|
|
}
|
|
|
|
|
2019-12-05 00:10:09 +01:00
|
|
|
// MARK: General
|
2019-12-04 06:54:46 +01:00
|
|
|
@objc private func enableCopyButton() {
|
|
|
|
copyButton.isUserInteractionEnabled = true
|
|
|
|
UIView.transition(with: copyButton, duration: 0.25, options: .transitionCrossDissolve, animations: {
|
|
|
|
self.copyButton.setTitle(NSLocalizedString("Copy", comment: ""), for: UIControl.State.normal)
|
|
|
|
}, completion: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: Interaction
|
|
|
|
@objc private func close() {
|
|
|
|
dismiss(animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc private func showQRCode() {
|
2019-12-05 00:10:09 +01:00
|
|
|
let qrCodeModal = QRCodeModal()
|
|
|
|
qrCodeModal.modalPresentationStyle = .overFullScreen
|
|
|
|
present(qrCodeModal, animated: true, completion: nil)
|
2019-12-04 06:54:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@objc private func copyPublicKey() {
|
|
|
|
UIPasteboard.general.string = userHexEncodedPublicKey
|
|
|
|
copyButton.isUserInteractionEnabled = false
|
|
|
|
UIView.transition(with: copyButton, duration: 0.25, options: .transitionCrossDissolve, animations: {
|
|
|
|
self.copyButton.setTitle(NSLocalizedString("Copied", comment: ""), for: UIControl.State.normal)
|
|
|
|
}, completion: nil)
|
|
|
|
Timer.scheduledTimer(timeInterval: 4, target: self, selector: #selector(enableCopyButton), userInfo: nil, repeats: false)
|
|
|
|
}
|
|
|
|
|
|
|
|
@objc private func sharePublicKey() {
|
|
|
|
let shareVC = UIActivityViewController(activityItems: [ userHexEncodedPublicKey ], applicationActivities: nil)
|
|
|
|
navigationController!.present(shareVC, animated: true, completion: nil)
|
|
|
|
}
|
|
|
|
|
2019-12-05 00:10:09 +01:00
|
|
|
@objc private func showPrivacySettings() {
|
|
|
|
let privacySettingsVC = PrivacySettingsTableViewController()
|
|
|
|
navigationController!.pushViewController(privacySettingsVC, animated: true)
|
2019-12-04 06:54:46 +01:00
|
|
|
}
|
|
|
|
|
2019-12-05 00:10:09 +01:00
|
|
|
@objc private func showNotificationSettings() {
|
|
|
|
let notificationSettingsVC = NotificationSettingsViewController()
|
|
|
|
navigationController!.pushViewController(notificationSettingsVC, animated: true)
|
2019-12-04 06:54:46 +01:00
|
|
|
}
|
|
|
|
|
2019-12-05 00:10:09 +01:00
|
|
|
@objc private func showLinkedDevices() {
|
|
|
|
let deviceLinksVC = DeviceLinksVC()
|
|
|
|
navigationController!.pushViewController(deviceLinksVC, animated: true)
|
2019-12-04 06:54:46 +01:00
|
|
|
}
|
|
|
|
|
2019-12-05 00:10:09 +01:00
|
|
|
@objc private func showSeed() {
|
|
|
|
let seedModal = SeedModal()
|
|
|
|
seedModal.modalPresentationStyle = .overFullScreen
|
2019-12-05 01:42:31 +01:00
|
|
|
seedModal.modalTransitionStyle = .crossDissolve
|
2019-12-05 00:10:09 +01:00
|
|
|
present(seedModal, animated: true, completion: nil)
|
2019-12-04 06:54:46 +01:00
|
|
|
}
|
|
|
|
|
2019-12-05 00:10:09 +01:00
|
|
|
@objc private func clearAllData() {
|
|
|
|
let nukeDataModal = NukeDataModal()
|
|
|
|
nukeDataModal.modalPresentationStyle = .overFullScreen
|
2019-12-05 01:42:31 +01:00
|
|
|
nukeDataModal.modalTransitionStyle = .crossDissolve
|
2019-12-05 00:10:09 +01:00
|
|
|
present(nukeDataModal, animated: true, completion: nil)
|
2019-12-04 06:54:46 +01:00
|
|
|
}
|
|
|
|
}
|