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.
126 lines
5.0 KiB
126 lines
5.0 KiB
![]()
2 years ago
|
//
|
||
![]()
2 years ago
|
// NotDisturbViewControllers.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 doubleTimePickerCell = ReusableCell<DoubleTimePickerCell>(identifier: "DoubleTimePickerCell", nib: nil)
|
||
|
}
|
||
|
|
||
|
fileprivate struct Metric {
|
||
|
static let descTextColor = kHexColor(0x96A3B3)
|
||
|
}
|
||
|
|
||
![]()
2 years ago
|
class NotDisturbViewControllers: TableViewController {
|
||
![]()
2 years ago
|
|
||
|
var noDisturbModel = NoDisturbModel()
|
||
|
|
||
|
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.tableViewCell)
|
||
|
tableView.snp.makeConstraints { (make) in
|
||
|
make.edges.equalToSuperview()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
override func bindViewModel() {
|
||
![]()
2 years ago
|
guard let viewModel = viewModel as? NotDisturbViewModels else { return }
|
||
![]()
2 years ago
|
noDisturbModel = viewModel.noDisturbModel
|
||
|
let dataSource = RxTableViewSectionedReloadDataSource<MultipleSectionModel>.init(configureCell: { [weak self] (ds, tv, indexPath, _) -> UITableViewCell in
|
||
|
switch ds[indexPath] {
|
||
|
case .SinglePicker( _, _):
|
||
|
return UITableViewCell()
|
||
|
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?.noDisturbModel.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.types = 999;
|
||
|
cell.selectionStyle = .none
|
||
![]()
1 year ago
|
cell.fbbegintimeLabel.text = leftTitle
|
||
|
cell.fbendtimeLabel.text = rightTitle
|
||
![]()
2 years ago
|
cell.pickerColsure = { (items) in
|
||
|
self?.noDisturbModel.StartTime = items.first ?? "00:00"
|
||
|
self?.noDisturbModel.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 = (noDisturbModel.StartTime as NSString).doubleValue
|
||
|
let endTime = (noDisturbModel.EndTime as NSString).doubleValue
|
||
|
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.notDisturbWithBleCmdType(model: noDisturbModel)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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 .notDisturb:
|
||
|
if isSuccess {
|
||
|
GlobalDeviceProfileModel.shareInstance.noDisturbModel = self.noDisturbModel
|
||
![]()
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 NotDisturbViewControllers: 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)
|
||
|
default: return kScaleHeight(184)
|
||
|
}
|
||
|
}
|
||
|
}
|