Blame view

Twear/Mine/HealthReportVC.swift 5.71 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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  //
  //  HealthReportVC.swift
  //  Twear
  //
  //  Created by yangbin on 2022/1/1.
  //
  
  import UIKit
  import SwiftDate
  
  class HealthReportVC: UIViewController {
      @IBOutlet weak var collectionView: UICollectionView!
      
      @IBOutlet private weak var monthButton: UIButton!
      @IBOutlet private weak var dayButton: UIButton!
      @IBOutlet private weak var yearButton: UIButton!
      @IBOutlet private weak var weekButton: UIButton!
      
      private var dateType: DateType = .day
      
      var collectArray = CurDevice.allFunctions
      
      override func viewDidLoad() {
          super.viewDidLoad()
          
          title = LocString("健康报告")
          
          let shareButton = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 28))
          shareButton.setImage(UIImage(named: "share_btn"), for: .normal)
          shareButton.addTarget(self, action: #selector(share), for: .touchUpInside)
          navigationItem.rightBarButtonItem =  UIBarButtonItem(customView: shareButton)
          
          if let i = collectArray.firstIndex(of: "MotionRecord") {
              collectArray.remove(at: i)
          }
          if let i = collectArray.firstIndex(of: "WomenHealth") {
              collectArray.remove(at: i)
          }
          if let i = collectArray.firstIndex(of: "Train") {
              collectArray.remove(at: i)
          }
          testDate()
          collectArray.insert("Step", at: 0)
          
          configureCollectionView()
      
      }
      
   
      func testDate() {
  //        let testDate = DateInRegion(year: 2022, month: 1, day: 13, hour: 0, minute: 0, second: 0)
          if IsTest {
              if let i = collectArray.firstIndex(of: "BloodPressure") {
                  collectArray.remove(at: i)
              }
              if let i = collectArray.firstIndex(of: "BloodOxygen") {
                  collectArray.remove(at: i)
              }
  
          }
      }
      @objc func share() {
66e7e76d   yangbin   NFC
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
          SSEShareHelper.screenCaptureShare {[weak self] sImage, handler in
              if let sImage = sImage {
                  
                  sImage.getNativeImage { image in
                      if let image = image {
                          let shareView = ShareView(image)
                          shareView.show()
  //                        self?.share(index, image: image)
                      }
                  }
                 
              }
          } onStateChanged: { _, _, _, _ in
              
          }
         
75d24c15   yangbin   123
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
      }
      
      @IBAction func selectedDate(_ sender: UIButton) {
          monthButton.setTitleColor(.black, for: .normal)
          dayButton.setTitleColor(.black, for: .normal)
          yearButton.setTitleColor(.black, for: .normal)
          weekButton.setTitleColor(.black, for: .normal)
          sender.setTitleColor(TintColor, for: .normal)
          dateType = DateType(rawValue: sender.tag) ?? .day
          collectionView.reloadData()
      }
      
      
  
  
  
  }
  
  extension HealthReportVC: UICollectionViewDataSource,UICollectionViewDelegateFlowLayout {
      private func configureCollectionView(){
  
          let flowLayout = UICollectionViewFlowLayout()
          flowLayout.scrollDirection = .vertical
          flowLayout.minimumLineSpacing = 12
          flowLayout.minimumInteritemSpacing = 12
          flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 12.5, bottom: 15, right: 12.5)
          flowLayout.itemSize = CGSize(width: SCREEN_WIDTH-25, height: 335)
          collectionView.showsVerticalScrollIndicator = false
          collectionView.bounces = false
          collectionView.collectionViewLayout = flowLayout
          collectionView.register(UINib(nibName: "StepReportCell", bundle: .main), forCellWithReuseIdentifier: "StepReportCell")
          collectionView.register(UINib(nibName: "BOReportCell", bundle: .main), forCellWithReuseIdentifier: "BOReportCell")
          collectionView.register(UINib(nibName: "HRReportCell", bundle: .main), forCellWithReuseIdentifier: "HRReportCell")
          collectionView.register(UINib(nibName: "SleepReportCell", bundle: .main), forCellWithReuseIdentifier: "SleepReportCell")
          collectionView.register(UINib(nibName: "BPReportCell", bundle: .main), forCellWithReuseIdentifier: "BPReportCell")
      }
      
      
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
          return collectArray.count
      }
      
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
          switch collectArray[indexPath.row] {
          case "BloodPressure":
              let cell: BPReportCell = collectionView.dequeueReusableCell(withReuseIdentifier: "BPReportCell", for: indexPath) as! BPReportCell
              cell.dateType = dateType
              return cell
          case "BloodOxygen":
              let cell: BOReportCell = collectionView.dequeueReusableCell(withReuseIdentifier: "BOReportCell", for: indexPath) as! BOReportCell
              cell.dateType = dateType
              return cell
          case "HeartRate":
              let cell: HRReportCell = collectionView.dequeueReusableCell(withReuseIdentifier: "HRReportCell", for: indexPath) as! HRReportCell
              cell.dateType = dateType
              return cell
          case "Sleep":
              
              let cell: SleepReportCell = collectionView.dequeueReusableCell(withReuseIdentifier: "SleepReportCell", for: indexPath) as! SleepReportCell
              cell.dateType = dateType
              return cell
          case "Step":
              let cell: StepReportCell = collectionView.dequeueReusableCell(withReuseIdentifier: "StepReportCell", for: indexPath) as! StepReportCell
              cell.dateType = dateType
              return cell
          default:
              let cell: StepReportCell = collectionView.dequeueReusableCell(withReuseIdentifier: "StepReportCell", for: indexPath) as! StepReportCell
              return cell
          }
          
      }
  }