RestoreOptionDataViewController.swift 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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 RestoreOptionDataViewControllerDelegate {
  22. func optionDataKeepLocal()
  23. func optionDataCancelled()
  24. }
  25. class RestoreOptionDataViewController: IDCreationPageViewController {
  26. @IBOutlet weak var mainContent: UIStackView!
  27. @IBOutlet weak var content: UIStackView!
  28. @IBOutlet weak var titleLabel: UILabel!
  29. @IBOutlet weak var descriptionLabel: UILabel!
  30. @IBOutlet weak var keepLocalButton: SetupButton!
  31. @IBOutlet weak var keepLocalLabel: UILabel!
  32. @IBOutlet weak var deleteLocalButton: SetupButton!
  33. @IBOutlet weak var deleteLocalLabel: UILabel!
  34. @IBOutlet weak var cancelButton: UIButton!
  35. @objc weak var delegate: RestoreOptionDataViewControllerDelegate?
  36. override func viewDidLoad() {
  37. super.viewDidLoad()
  38. self.hideKeyboardWhenTappedAround()
  39. self.titleLabel.text = BundleUtil.localizedString(forKey: "restore_option_title")
  40. self.descriptionLabel.text = BundleUtil.localizedString(forKey: "restore_option_data_description")
  41. self.keepLocalButton.setTitle(BundleUtil.localizedString(forKey: "restore_option_data_keep_data"), for: .normal)
  42. self.keepLocalLabel.text = BundleUtil.localizedString(forKey: "restore_option_data_keep_data_description")
  43. self.deleteLocalButton.setTitle(BundleUtil.localizedString(forKey: "restore_option_data_delete_data"), for: .normal)
  44. self.deleteLocalLabel.text = BundleUtil.localizedString(forKey: "restore_option_data_delete_data_description")
  45. self.cancelButton.setTitle(NSLocalizedString("cancel", comment: ""), for: .normal)
  46. //add swipe right for cancel action
  47. let gestureRecognizer = UISwipeGestureRecognizer(target: self, action:#selector(swipeAction))
  48. gestureRecognizer.numberOfTouchesRequired = 1
  49. self.view.addGestureRecognizer(gestureRecognizer)
  50. }
  51. }
  52. extension RestoreOptionDataViewController {
  53. @objc func swipeAction(sender: UITapGestureRecognizer) {
  54. if sender.state == .ended {
  55. self.delegate?.optionDataCancelled()
  56. }
  57. }
  58. @IBAction func touchDownButton(_ sender: UIButton, forEvent event: UIEvent) {
  59. if sender == self.keepLocalButton {
  60. self.delegate?.optionDataKeepLocal()
  61. } else if sender == self.deleteLocalButton {
  62. let alert = IntroQuestionViewHelper(parent: self, onAnswer: nil)
  63. alert.showAlert(BundleUtil.localizedString(forKey: "restore_option_data_delete_data_explain"), title: BundleUtil.localizedString(forKey: "safe_restore"))
  64. } else if sender == self.cancelButton {
  65. self.delegate?.optionDataCancelled()
  66. }
  67. }
  68. }