123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- // _____ _
- // |_ _| |_ _ _ ___ ___ _ __ __ _
- // | | | ' \| '_/ -_) -_) ' \/ _` |_
- // |_| |_||_|_| \___\___|_|_|_\__,_(_)
- //
- // Threema iOS Client
- // Copyright (c) 2018-2020 Threema GmbH
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License, version 3,
- // as published by the Free Software Foundation.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
- import Foundation
- import UIKit
- class SafeSetupViewController: ThemedViewController {
- @IBOutlet weak var safeImageView: UIImageView!
- @IBOutlet weak var safeImageCircle: UIView!
- @IBOutlet weak var safeSwitchLabel: UILabel!
- @IBOutlet weak var safeSwitch: UISwitch!
- @IBOutlet weak var safeActivatedContainer: UIView!
- @IBOutlet weak var safeDeactivatedContainer: UIView!
- @IBOutlet weak var safeSeparatorView: UIView!
- var safeManager: SafeManager
- var mdmSetup: MDMSetup
-
- required init?(coder aDecoder: NSCoder) {
- let safeConfigManager = SafeConfigManager()
- let safeStore = SafeStore(safeConfigManager: safeConfigManager, serverApiConnector: ServerAPIConnector())
- self.safeManager = SafeManager(safeConfigManager: safeConfigManager, safeStore: safeStore, safeApiService: SafeApiService())
- self.mdmSetup = MDMSetup(setup: false)
- super.init(coder: aDecoder)
- }
-
- override func viewDidLoad() {
- super.viewDidLoad()
-
- self.title = "Threema Safe"
- self.safeImageCircle.layer.cornerRadius = self.safeImageCircle.frame.height / 2
- self.safeSwitch.isEnabled = !self.mdmSetup.isSafeBackupForce()
- }
-
- override func viewWillAppear(_ animated: Bool) {
- refreshView()
- setupColor()
- }
- //MARK: - Navigation
-
- override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
- guard identifier == "SafeSetupPassword",
- sender is UISwitch else {
-
- return true
- }
-
- if self.safeManager.isActivated {
-
- //confirm to delete backup
- UIAlertTemplate.showConfirm(owner: self, popOverSource: self.safeSwitch!, title: NSLocalizedString("safe_deactivate", comment: ""), message: NSLocalizedString("safe_deactivate_explain", comment: ""), titleOk: NSLocalizedString("deactivate", comment: ""), actionOk: { (action) in
-
- self.safeManager.deactivate()
- self.refreshView()
- }, titleCancel: NSLocalizedString("cancel", comment: ""), actionCancel: { (action) in self.safeSwitch.isOn = true })
- return false
- }
-
- return true
- }
-
- func refreshView() {
-
- guard self.safeManager.isActivated else {
-
- self.safeActivatedContainer.isHidden = true
- self.safeDeactivatedContainer.isHidden = false
-
- self.safeSwitch.isOn = false
- return
- }
-
- self.safeActivatedContainer.isHidden = false
- // refresh safe activated container view controller and start backup
- safeActivatedViewController()?.refreshView(updateCell: true)
- self.safeDeactivatedContainer.isHidden = true
- self.safeSwitch.isOn = true
- }
-
- @objc override func refresh() {
- super.refresh()
- for childViewController in self.children {
- if let viewController = childViewController as? SafeActivatedViewController {
- viewController.refresh()
- }
- if let viewController = childViewController as? SafeDeactivatedViewController {
- viewController.refresh()
- }
- }
- setupColor()
- }
-
- // MARK: Private functions
-
- private func safeActivatedViewController() -> SafeActivatedViewController? {
- for childViewController in self.children {
- if let viewController = childViewController as? SafeActivatedViewController {
- return viewController
- }
- }
- return nil
- }
-
- private func setupColor() {
- safeSeparatorView.backgroundColor = Colors.hairline()
- safeImageCircle.backgroundColor = UIColor(red: 235.0/255.0, green: 235.0/255.0, blue: 235.0/255.0, alpha: 1.0)
- safeImageView.bringSubviewToFront(self.view)
- }
- }
- extension SafeSetupViewController {
- @IBAction func doneSafeSetupPassword(_ segue: UIStoryboardSegue) {
- guard segue.source is SafeSetupPasswordViewController else {
- return
- }
-
- safeActivatedViewController()?.backupNow()
- self.refreshView()
- }
- }
|