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.
 
 
 

134 lines
5.6 KiB

//
// HeartRateCheckViewController.swift
// FireBoltt
//
// Created by lemo on 2018/6/5.
// Copyright © 2020 ecell. All rights reserved.
//
import UIKit
// MARK:-
private enum Resuable {
static let doubleTimePickerCell = ReusableCell<DoubleTimePickerCell>(identifier: "DoubleTimePickerCell", nib: nil)
static let tableViewCell = ReusableCell<CommonTableViewCell>(nibName: "CommonTableViewCell")
static let singlePickerCell = ReusableCell<SinglePickerCell>(identifier: "SinglePickerCell", nib: nil)
}
fileprivate struct Metric {
static let descTextColor = kHexColor(0x96A3B3)
}
class HeartRateMonitorViewControllers: TableViewController {
var heartRateModel = HeartRateCheckModel()
override func viewDidLoad() {
super.viewDidLoad()
monitor()
}
override func makeUI() {
super.makeUI()
let rightItem = UIBarButtonItem.baseBarButtonItem(normalImg: "", highImg: nil, title: MultiLanguageKey_FB.saveFB.localized, target: self, action: #selector(clickSave))
navigationItem.rightBarButtonItem = rightItem
tableViewStyle = .grouped
tableView.rx.setDelegate(self).disposed(by: rx.disposeBag)
tableView.register(Resuable.doubleTimePickerCell)
tableView.register(Resuable.singlePickerCell)
tableView.register(Resuable.tableViewCell)
tableView.snp.makeConstraints { (make) in
make.edges.equalToSuperview()
}
}
override func bindViewModel() {
guard let viewModel = viewModel as? HeartRateCheckViewModels else { return }
heartRateModel = viewModel.heartRateCheckModel
let dataSource = RxTableViewSectionedReloadDataSource<MultipleSectionModel>.init(configureCell: { [weak self] (ds, tv, indexPath, _) -> UITableViewCell in
switch ds[indexPath] {
case .SinglePicker(let title, let selectedItem):
let cell: SinglePickerCell = tv.dequeue(Resuable.singlePickerCell, for: indexPath)
cell.selectionStyle = .none
cell.fbtitleLabel.text = title
cell.singlePickerClosure = { item in
self?.heartRateModel.Interval = item
}
cell.functionType = .heartRateMonitor
cell.selectedItem = selectedItem
return cell
case .TableViewCellModel(let cellModel):
let cell: CommonTableViewCell = tv.dequeue(Resuable.tableViewCell, for: indexPath)
cell.bindViewModel(model: cellModel)
cell.rightSwitch.rx.isOn
.skip(1)
.subscribe(onNext: { (isOn) in
self?.heartRateModel.IsOpen = isOn
})
.disposed(by: cell.cellDisposeBag)
return cell
case .DoubleTimePicker(let leftTitle, let rightTitle, let selectedItems):
let cell: DoubleTimePickerCell = tv.dequeue(Resuable.doubleTimePickerCell, for: indexPath)
cell.selectionStyle = .none
cell.fbbegintimeLabel.text = leftTitle
cell.fbendtimeLabel.text = rightTitle
cell.pickerColsure = { (items) in
self?.heartRateModel.StartTime = items.first ?? "00:00"
self?.heartRateModel.EndTime = items.last ?? "00:00"
}
cell.selectedItems = selectedItems
return cell
}
})
viewModel.fbdataVariable
.bind(to: tableView.rx.items(dataSource: dataSource))
.disposed(by: rx.disposeBag)
}
@objc func clickSave() {
let startTime = (heartRateModel.StartTime as NSString).integerValue
let endTime = (heartRateModel.EndTime as NSString).integerValue
if startTime >= endTime {
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.timeTipFB.localized)
return
}
SVProgressHUD.show()
if BluetoothService.shared.checkBleCmdEnable(isShow: true) {
BluetoothService.shared.setHeartRateCheckWithBleCmdType(model: heartRateModel)
}
}
func monitor() {
///
Observable.of(kNotificationCenter.rx.notification(Notification.Name(rawValue: CmdSuccess)),
kNotificationCenter.rx.notification(Notification.Name(rawValue: CmdTimeout)))
.merge()
.subscribe(onNext: { [weak self] notification in
guard let `self` = self, let cmd = notification.object as? BleCMD_FireBoltt else { return }
let isSuccess = notification.name.rawValue == CmdSuccess
switch cmd {
case .heartRateCheck:
if isSuccess {
GlobalDeviceProfileModel.shareInstance.heartRateModel = self.heartRateModel
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.setSuccessFB.localized)
self.navigationController?.popViewController(animated: true)
return
}
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.setFailFB.localized)
default: break
}
})
.disposed(by: rx.disposeBag)
}
}
extension HeartRateMonitorViewControllers: UITableViewDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.section {
case 0: return kScaleHeight(50)
case 1: return kScaleHeight(178)
default: return kScaleHeight(184)
}
}
}