You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

159 lines
6.2 KiB

2 years ago
//
// HealthFormView.swift
// HPlusFit
//
// Created by lemo. on 2019/9/24.
// Copyright © 2019 lemo. All rights reserved.
//
import UIKit
struct HealthFormModel {
let oneValue: String
let twoValue: String
let threeValue: String
let fourValue: String
}
class HealthFormView: UIView, NibLoadable {
@IBOutlet weak var tip1Label: UILabel!
@IBOutlet weak var tip2Label: UILabel!
@IBOutlet weak var tip3Label: UILabel!
@IBOutlet weak var tip4Label: UILabel!
@IBOutlet weak var totalSteps: UILabel!
@IBOutlet weak var totalDistance: UILabel!
@IBOutlet weak var totalTime: UILabel!
@IBOutlet weak var totalEnergy: UILabel!
@IBOutlet weak var unit1Label: UILabel!
@IBOutlet weak var unit2Label: UILabel!
@IBOutlet weak var unit3Label: UILabel!
@IBOutlet weak var unit4Label: UILabel!
@IBOutlet weak var hView: UIView!
@IBOutlet weak var sView: UIView!
private var type: HealthType = .step
lazy var views: UIView = {
let views = UIView()
views.backgroundColor = kHexColor(0xEAEAEA)
return views
}()
override func awakeFromNib() {
super.awakeFromNib()
addSubview(views)
//
totalSteps.font = UIFont(name: "DINAlternate-Bold", size: kScaleWidth(24))
totalDistance.font = UIFont(name: "DINAlternate-Bold", size: kScaleWidth(24))
totalTime.font = UIFont(name: "DINAlternate-Bold", size: kScaleWidth(24))
totalEnergy.font = UIFont(name: "DINAlternate-Bold", size: kScaleWidth(24))
//
for subView in self.subviews {
for constrain in subView.constraints {
constrain.constant = kScaleWidth(constrain.constant)
}
}
}
func configUI(type: HealthType) {
self.type = type
switch type {
case .step:
unit3Label.text = "(\(MultiLanguageKey_FB.minFB.localized))"
unit4Label.text = MultiLanguageKey_FB.kcalFB.localized
tip1Label.text = MultiLanguageKey_FB.maxStepFB.localized
tip2Label.text = MultiLanguageKey_FB.kmMileageFB.localized
tip3Label.text = MultiLanguageKey_FB.durationFB.localized
tip4Label.text = MultiLanguageKey_FB.consumeFB.localized
2 years ago
case .sleep:
unit1Label.text = MultiLanguageKey_FB.hourFB.localized
unit2Label.text = MultiLanguageKey_FB.hourFB.localized
unit3Label.text = MultiLanguageKey_FB.hourFB.localized
tip1Label.text = MultiLanguageKey_FB.deepSleepFB.localized
tip2Label.text = MultiLanguageKey_FB.shallowSleepFB.localized
tip3Label.text = MultiLanguageKey_FB.sleepDurationFB.localized
// tip4Label.text = MultiLanguageKey_FB.awakeNumberFB.localized
tip4Label.text = MultiLanguageKey_FB.awakeDurationFB.localized
2 years ago
case .heartRate:
unit1Label.text = MultiLanguageKey_FB.hrUnitFB.localized
unit2Label.text = MultiLanguageKey_FB.hrUnitFB.localized
unit3Label.text = MultiLanguageKey_FB.hrUnitFB.localized
tip1Label.text = MultiLanguageKey_FB.avgHrFB.localized
tip2Label.text = MultiLanguageKey_FB.maxHrFB.localized
tip3Label.text = MultiLanguageKey_FB.minHrFB.localized
2 years ago
tip4Label.text = ""
case .temperature:
unit1Label.text = MultiLanguageKey_FB.centigradeFB.localized
unit2Label.text = MultiLanguageKey_FB.centigradeFB.localized
unit3Label.text = MultiLanguageKey_FB.centigradeFB.localized
tip1Label.text = MultiLanguageKey_FB.avgTemperatureFB.localized
tip2Label.text = MultiLanguageKey_FB.maxTemperatureFB.localized
tip3Label.text = MultiLanguageKey_FB.minTemperatureFB.localized
2 years ago
tip4Label.text = ""
case .bloodPressure:
unit1Label.text = MultiLanguageKey_FB.bloodPressureUnitFB.localized
unit2Label.text = MultiLanguageKey_FB.bloodPressureUnitFB.localized
unit3Label.text = MultiLanguageKey_FB.bloodPressureUnitFB.localized
unit4Label.text = MultiLanguageKey_FB.bloodPressureUnitFB.localized
tip1Label.text = MultiLanguageKey_FB.avgSBPFB.localized
tip2Label.text = MultiLanguageKey_FB.avgDBPFB.localized
tip3Label.text = MultiLanguageKey_FB.maxSBPFB.localized
tip4Label.text = MultiLanguageKey_FB.maxDBPFB.localized
2 years ago
hView.isHidden = true
sView.isHidden = true
views.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(15)
make.size.equalTo(CGSize(width: 1, height: 80))
}
case .bloodOxygen:
unit1Label.text = MultiLanguageKey_FB.bloodOxygenUnitFB.localized
unit2Label.text = MultiLanguageKey_FB.bloodOxygenUnitFB.localized
unit3Label.text = MultiLanguageKey_FB.bloodOxygenUnitFB.localized
tip1Label.text = MultiLanguageKey_FB.avgBloodOxygenFB.localized
tip2Label.text = MultiLanguageKey_FB.maxBloodOxygenFB.localized
tip3Label.text = MultiLanguageKey_FB.minBloodOxygenFB.localized
2 years ago
tip4Label.text = ""
default:
break
}
}
fileprivate func bingUpdeFormView(model: HealthFormModel?) {
var defaultFout = "--"
switch type {
case .heartRate, .temperature, .bloodOxygen:
defaultFout = ""
default: break
}
guard let formModel = model else {
self.totalSteps.text = "--"
self.totalDistance.text = "--"
self.totalTime.text = type == .bloodPressure ? "" : "--"
self.totalEnergy.text = type == .bloodPressure ? "" : defaultFout
return
}
totalSteps.text = formModel.oneValue
totalDistance.text = formModel.twoValue
totalTime.text = formModel.threeValue
totalEnergy.text = formModel.fourValue
}
}
extension Reactive where Base: HealthFormView {
func formDataSource() -> Binder<HealthFormModel?> {
return Binder(self.base, binding: { (formView, model) in
formView.bingUpdeFormView(model: model)
})
}
}