Blame view

Twear/Setting/NotDisturbViewController.swift 4.26 KB
75d24c15   yangbin   123
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
  //
  //  NotDisturbViewController.swift
  //  Twear
  //
  //  Created by yangbin on 2021/12/24.
  //
  
  import UIKit
  import MBProgressHUD
  import HandyJSON
  
  class NotDisturbViewController: UIViewController {
  
      @IBOutlet weak var disturbSwitch: UISwitch!
      @IBOutlet weak var startTimeLabel: UILabel!
      @IBOutlet weak var endTimeLabel: UILabel!
      
      private let device = CurDevice
      lazy private var dis: RemindModel = CurDevice.disturb
      override func viewDidDisappear(_ animated: Bool) {
          super.viewDidDisappear(animated)
          MBProgressHUD.hide()
      }
      
      override func viewWillAppear(_ animated: Bool) {
          super.viewWillAppear(animated)
582f536d   yangbin   common:2022.1.28
27
28
  //        let navController = navigationController as? ZCNavigationController
  //        navController?.enableScreenEdgePanGestureRecognizer(false)
75d24c15   yangbin   123
29
30
31
32
33
34
35
36
37
38
39
      }
      override func viewWillDisappear(_ animated: Bool) {
          super.viewWillDisappear(animated)
          let navController = navigationController as? ZCNavigationController
          navController?.enableScreenEdgePanGestureRecognizer(true)
      }
      
      override func navigationShouldPop() -> Bool {
          if dis.isEqual(device.disturb) {
              return true
          } else {
66e7e76d   yangbin   NFC
40
              self.showAlert(title: LocString("温馨提示"), message: LocString("您的设置尚未保存,是否退出")) { action in
75d24c15   yangbin   123
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
                  self.navigationController?.popViewController(animated: true)
              }
              return false
              
          }
      }
      
      
      override func viewDidLoad() {
          super.viewDidLoad()
          title = LocString("勿扰模式")
  //        dis = device.disturb
          disturbSwitch.isOn = device.disturb.isOn
          
          startTimeLabel.text = "\(String(format:"%02d",device.disturb.startDate.hour)):\(String(format:"%02d",device.disturb.startDate.minute))"
          endTimeLabel.text = "\(String(format:"%02d",device.disturb.endDate.hour)):\(String(format:"%02d",device.disturb.endDate.minute))"
          
          let saveButton = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 28))
          saveButton.setTitle(LocString("保存"), for: .normal)
          saveButton.titleLabel?.font = RegularFont(14)
          saveButton.setTitleColor(UIColor.rgbColorFromHex(0x00993E), for: .normal)
          saveButton.addTarget(self, action: #selector(save), for: .touchUpInside)
          navigationItem.rightBarButtonItem =  UIBarButtonItem(customView: saveButton)
      }
      
582f536d   yangbin   common:2022.1.28
66
67
68
69
70
71
72
73
74
75
76
      func updateScreenEdgePanEnable() {
          let navController = navigationController as? ZCNavigationController
          
          if dis.isEqual(device.disturb) {
              navController?.enableScreenEdgePanGestureRecognizer(true)
          } else {
              navController?.enableScreenEdgePanGestureRecognizer(false)
          }
      }
      
      
75d24c15   yangbin   123
77
78
79
80
81
82
83
84
85
86
87
      @objc func save() {
          _ = MBProgressHUD.showMessage("")
          BluetoothManager.shared.setNotDisturb(remind: device.disturb) {[weak self] error in
              AdminHelper.shared.updateDevice((self?.device)!)
              self?.navigationController?.popViewController(animated: true)
              MBProgressHUD.hide()
          }
      }
      
      @IBAction func swtichValueChanged(_ sender: UISwitch) {
          device.disturb.isOn = sender.isOn
582f536d   yangbin   common:2022.1.28
88
          updateScreenEdgePanEnable()
75d24c15   yangbin   123
89
90
91
92
93
94
95
96
97
      }
      
      @IBAction func clickStartTime(_ sender: UIButton) {
          let pickerView = DatePickerView(title: LocString("开始时间"))
          pickerView.datePicker.date = device.disturb.startDate
          pickerView.show()
          pickerView.clickClosure = {[weak self] date in
              self?.startTimeLabel.text = "\(String(format:"%02d",date.hour)):\(String(format:"%02d",date.minute))"
              self?.device.disturb.startDate = date
582f536d   yangbin   common:2022.1.28
98
              self?.updateScreenEdgePanEnable()
75d24c15   yangbin   123
99
100
101
102
103
104
105
106
107
          }
      }
      @IBAction func clickEndTime(_ sender: UIButton) {
          let pickerView = DatePickerView(title: LocString("结束时间"))
          pickerView.datePicker.date = device.disturb.endDate
          pickerView.show()
          pickerView.clickClosure = {[weak self] date in
              self?.endTimeLabel.text = "\(String(format:"%02d",date.hour)):\(String(format:"%02d",date.minute))"
              self?.device.disturb.endDate = date
582f536d   yangbin   common:2022.1.28
108
              self?.updateScreenEdgePanEnable()
75d24c15   yangbin   123
109
110
111
112
113
114
115
116
117
118
          }
      }
  
      deinit {
          print("deinit\(NSStringFromClass(type(of: self)))!!!!!!!")
      }
  
  
  
  }