// // 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() { 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 } } @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 } } }