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.
 
 
 

152 lines
6.2 KiB

//
// TemperarureCheckViewControllers.swift
// FireBoltt
//
// Created by lemo. on 2020/9/6.
// Copyright © 2020 Sheldon. 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 TemperarureCheckViewControllers: TableViewController {
var temperatureCheckModel = TemperatureCheckModel()
lazy var fbtipLabel: UILabel = {
let view = UILabel()
view.text = MultiLanguageKey_FB.temperatureCheckTipFB.localized
view.font = SystemLightFont(13)
view.textColor = .gray
view.numberOfLines = 0
view.textAlignment = .center
return view
}()
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()
}
view.addSubview(fbtipLabel)
fbtipLabel.snp.makeConstraints { (make) in
make.centerX.equalToSuperview()
make.left.equalTo(20)
make.right.equalTo(-20)
make.bottom.equalTo(-50)
}
}
override func bindViewModel() {
guard let viewModel = viewModel as? TemperarureCheckViewModels else { return }
temperatureCheckModel = viewModel.temperatureCheckModel
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?.temperatureCheckModel.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?.temperatureCheckModel.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?.temperatureCheckModel.StartTime = items.first ?? "00:00"
self?.temperatureCheckModel.EndTime = items.last ?? "00:00"
}
cell.selectedItems = selectedItems
return cell
}
})
viewModel.dataVariable
.bind(to: tableView.rx.items(dataSource: dataSource))
.disposed(by: rx.disposeBag)
}
@objc func clickSave() {
let startTime = (temperatureCheckModel.StartTime as NSString).integerValue
let endTime = (temperatureCheckModel.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.setTemperatureCheckWithBleCmdType(model: temperatureCheckModel)
}
}
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 .temperatureCheck:
if isSuccess {
GlobalDeviceProfileModel.shareInstance.temperatureModel = self.temperatureCheckModel
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 TemperarureCheckViewControllers: 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)
}
}
}