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.4 KiB
152 lines
6.4 KiB
![]()
2 years ago
|
//
|
||
![]()
2 years ago
|
// DrinkRemindViewControllers.swift
|
||
![]()
1 year ago
|
// FireBoltt
|
||
![]()
2 years ago
|
//
|
||
|
// Created by lemo. on 2020/3/29.
|
||
|
// Copyright © 2020 Sheldon. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
// MARK:- 复用
|
||
|
private enum Resuable {
|
||
|
static let tableViewCell = ReusableCell<CommonTableViewCell>(nibName: "CommonTableViewCell")
|
||
|
static let singlePickerCell = ReusableCell<SinglePickerCell>(identifier: "SinglePickerCell", nib: nil)
|
||
|
static let doubleTimePickerCell = ReusableCell<DoubleTimePickerCell>(identifier: "DoubleTimePickerCell", nib: nil)
|
||
|
}
|
||
|
|
||
|
fileprivate struct Metric {
|
||
|
static let descTextColor = kHexColor(0x96A3B3)
|
||
|
}
|
||
|
|
||
![]()
2 years ago
|
class DrinkRemindViewControllers: TableViewController {
|
||
![]()
2 years ago
|
|
||
|
var drinkingModel = DrinkingModel()
|
||
|
|
||
|
override func viewDidLoad() {
|
||
|
super.viewDidLoad()
|
||
|
monitor()
|
||
|
}
|
||
|
|
||
|
override func makeUI() {
|
||
|
super.makeUI()
|
||
![]()
1 year ago
|
let rightItem = UIBarButtonItem.baseBarButtonItem(normalImg: "", highImg: nil, title: MultiLanguageKey_FB.saveFB.localized, target: self, action: #selector(clickSave))
|
||
![]()
2 years ago
|
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() {
|
||
![]()
2 years ago
|
guard let viewModel = viewModel as? DrinkRemindViewModels else { return }
|
||
![]()
2 years ago
|
drinkingModel = viewModel.drinkingModel
|
||
|
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
|
||
![]()
1 year ago
|
cell.fbtitleLabel.text = title
|
||
![]()
2 years ago
|
cell.singlePickerClosure = { item in
|
||
|
self?.drinkingModel.Interval = item
|
||
|
}
|
||
|
cell.functionType = .drinkRemind
|
||
|
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?.drinkingModel.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
|
||
![]()
1 year ago
|
cell.fbbegintimeLabel.text = leftTitle
|
||
|
cell.fbendtimeLabel.text = rightTitle
|
||
![]()
2 years ago
|
cell.pickerColsure = {(items) in
|
||
|
self?.drinkingModel.StartTime = items.first ?? "00:00"
|
||
|
self?.drinkingModel.EndTime = items.last ?? "00:00"
|
||
|
}
|
||
|
cell.selectedItems = selectedItems
|
||
|
return cell
|
||
|
}
|
||
|
})
|
||
|
viewModel.dataVariable
|
||
|
.bind(to: tableView.rx.items(dataSource: dataSource))
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
tableView.rx.itemSelected
|
||
|
.filter { $0.section == 3 }
|
||
|
.subscribe(onNext: { [weak self] _ in
|
||
|
guard let `self` = self else { return }
|
||
![]()
2 years ago
|
let repeatVM = RepeatViewModels(cycle: self.drinkingModel.Cycle)
|
||
![]()
2 years ago
|
repeatVM.updateCycle
|
||
|
.subscribe(onNext: { (cycleStr) in
|
||
![]()
2 years ago
|
guard let DrinkRemindViewModels = self.viewModel as? DrinkRemindViewModels else { return }
|
||
![]()
2 years ago
|
self.drinkingModel.Cycle = cycleStr
|
||
![]()
2 years ago
|
DrinkRemindViewModels.loadData(model: self.drinkingModel)
|
||
![]()
2 years ago
|
})
|
||
|
.disposed(by: repeatVM.rx.disposeBag)
|
||
|
self.navigator.show(segue: .repeatSet(viewModel: repeatVM), sender: self)
|
||
|
})
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
}
|
||
|
|
||
|
@objc func clickSave() {
|
||
|
let startTime = (drinkingModel.StartTime as NSString).integerValue
|
||
|
let endTime = (drinkingModel.EndTime as NSString).integerValue
|
||
|
if startTime >= endTime {
|
||
![]()
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.timeTipFB.localized)
|
||
![]()
2 years ago
|
return
|
||
|
}
|
||
|
SVProgressHUD.show()
|
||
![]()
2 years ago
|
if BluetoothService.shared.checkBleCmdEnable(isShow: true) {
|
||
![]()
2 years ago
|
BluetoothService.shared.setDrinkRemindWithBleCmdType(model: drinkingModel)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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
|
||
![]()
1 year ago
|
guard let `self` = self, let cmd = notification.object as? BleCMD_FireBoltt else { return }
|
||
![]()
2 years ago
|
let isSuccess = notification.name.rawValue == CmdSuccess
|
||
|
switch cmd {
|
||
|
case .setDrinkRemind:
|
||
|
if isSuccess {
|
||
|
GlobalDeviceProfileModel.shareInstance.drinkModel = self.drinkingModel
|
||
![]()
1 year ago
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.setSuccessFB.localized)
|
||
![]()
2 years ago
|
self.navigationController?.popViewController(animated: true)
|
||
|
return
|
||
|
}
|
||
![]()
1 year ago
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.setFailFB.localized)
|
||
![]()
2 years ago
|
default: break
|
||
|
}
|
||
|
})
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
![]()
2 years ago
|
extension DrinkRemindViewControllers: UITableViewDelegate {
|
||
![]()
2 years ago
|
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
||
|
switch indexPath.section {
|
||
|
case 0: return kScaleHeight(50)
|
||
|
case 1: return kScaleHeight(178)
|
||
|
case 2: return kScaleHeight(184)
|
||
|
default: return kScaleHeight(50)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|