RestoreOptionBackupViewController.swift 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2018-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. import UIKit
  21. @objc protocol RestoreOptionBackupViewControllerDelegate {
  22. func restoreSafe()
  23. func restoreIdentityFromSafe()
  24. func restoreIdentity()
  25. func restoreCancelled()
  26. }
  27. class RestoreOptionBackupViewController: IDCreationPageViewController {
  28. @IBOutlet weak var mainContent: UIStackView!
  29. @IBOutlet weak var content: UIStackView!
  30. @IBOutlet weak var titleLabel: UILabel!
  31. @IBOutlet weak var descriptionLabel: UILabel!
  32. @IBOutlet weak var safeButton: SetupButton!
  33. @IBOutlet weak var safeLabel: UILabel!
  34. @IBOutlet weak var idButton: SetupButton!
  35. @IBOutlet weak var idLabel: UILabel!
  36. @IBOutlet weak var cancelButton: UIButton!
  37. @objc weak var delegate: RestoreOptionBackupViewControllerDelegate?
  38. @objc var hasDataOnDevice: Bool = false
  39. override func viewDidLoad() {
  40. super.viewDidLoad()
  41. self.hideKeyboardWhenTappedAround()
  42. self.titleLabel.text = self.hasDataOnDevice ? BundleUtil.localizedString(forKey: "restore_option_id_title") : BundleUtil.localizedString(forKey: "restore_option_title")
  43. self.descriptionLabel.text = BundleUtil.localizedString(forKey: "restore_option_description")
  44. self.safeButton.setTitle("Threema Safe", for: .normal)
  45. self.safeLabel.text = self.hasDataOnDevice ? BundleUtil.localizedString(forKey: "restore_option_safe_keep_data") : BundleUtil.localizedString(forKey: "restore_option_safe")
  46. self.idButton.setTitle(BundleUtil.localizedString(forKey: "id_backup"), for: .normal)
  47. self.idLabel.text = self.hasDataOnDevice ? BundleUtil.localizedString(forKey: "restore_option_id_keep_data") : BundleUtil.localizedString(forKey: "restore_option_id")
  48. let mdmSetup = MDMSetup(setup: true)
  49. self.idButton.deactivated = mdmSetup!.disableIdExport()
  50. self.cancelButton.setTitle(NSLocalizedString("cancel", comment: ""), for: .normal)
  51. //add swipe right for cancel action
  52. let gestureRecognizer = UISwipeGestureRecognizer(target: self, action:#selector(swipeAction))
  53. gestureRecognizer.numberOfTouchesRequired = 1
  54. self.view.addGestureRecognizer(gestureRecognizer)
  55. }
  56. }
  57. extension RestoreOptionBackupViewController {
  58. @objc func swipeAction(sender: UITapGestureRecognizer) {
  59. if sender.state == .ended {
  60. self.delegate?.restoreCancelled()
  61. }
  62. }
  63. @IBAction func touchDownButton(_ sender: UIButton, forEvent event: UIEvent) {
  64. if sender == self.safeButton {
  65. if self.hasDataOnDevice {
  66. self.delegate?.restoreIdentityFromSafe()
  67. } else {
  68. self.delegate?.restoreSafe()
  69. }
  70. } else if sender == self.idButton {
  71. self.delegate?.restoreIdentity()
  72. } else if sender == cancelButton {
  73. self.delegate?.restoreCancelled()
  74. }
  75. }
  76. }