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.
78 lines
3.3 KiB
78 lines
3.3 KiB
![]()
2 years ago
|
//
|
||
|
// TargetVM.swift
|
||
![]()
1 year ago
|
// FireBoltt
|
||
![]()
2 years ago
|
//
|
||
|
// Created by lemo. on 2019/8/4.
|
||
|
// Copyright © 2019 lemo. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
|
||
|
enum UserTargetType {
|
||
|
case step, sleep, walk, run, cycling, climb
|
||
|
|
||
|
var title: String {
|
||
|
switch self {
|
||
![]()
1 year ago
|
case .step: return MultiLanguageKey_FB.stepTargetFB.localized
|
||
|
case .sleep: return MultiLanguageKey_FB.sleepTargetFB.localized
|
||
|
case .walk: return MultiLanguageKey_FB.walkTargetFB.localized
|
||
|
case .run: return MultiLanguageKey_FB.runTargetFB.localized
|
||
|
case .cycling: return MultiLanguageKey_FB.cyclingTargetFB.localized
|
||
|
case .climb: return MultiLanguageKey_FB.climbTargetFB.localized
|
||
![]()
2 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class TargetVM: ViewModel {
|
||
|
|
||
|
var relay = BehaviorRelay(value: [SectionModel<String,TableViewCellModel>]())
|
||
|
|
||
|
override init() {
|
||
|
super.init()
|
||
|
loadFuncationList()
|
||
|
// 设备适配更新
|
||
|
BluetoothService.shared.adapterInfoUpdate
|
||
|
.subscribe(onNext: { [weak self] (state) in
|
||
|
self?.loadFuncationList()
|
||
|
})
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
}
|
||
|
|
||
|
func loadFuncationList() {
|
||
![]()
1 year ago
|
guard let userInfo = UserDefaultsManagerFrieBoltt.getUserInfo() else { return }
|
||
![]()
2 years ago
|
// 功能列表
|
||
|
var funcationList: [[UserTargetType]] = [[.step, .sleep], [.walk, .run, .cycling, .climb]]
|
||
|
// 功能适配
|
||
![]()
1 year ago
|
if let adapterInfo = UserDefaultsManagerFrieBoltt.getDeviceInfo()?.adapterInfo {
|
||
![]()
2 years ago
|
let tempList = funcationList
|
||
|
for (i, types) in tempList.enumerated() {
|
||
|
for (j, type) in types.enumerated() {
|
||
|
if adapterInfo.targetSetTypes.contains(type) == false {
|
||
|
funcationList[i].remove(at: j)
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
// 数据
|
||
![]()
1 year ago
|
let step = MultiLanguageKey_FB.stepTipFB.localized
|
||
|
let hour = MultiLanguageKey_FB.hourFB.localized
|
||
|
// let min = MultiLanguageKey_FB.minFB.localized
|
||
![]()
2 years ago
|
// let descriptionList: [[String]] = [["\(userInfo.stepTarget)", "\(userInfo.sleepTarget / 60)" + hour + "\(userInfo.sleepTarget % 60)" + min], ["\(userInfo.walkTarget)" + step, "\(userInfo.runTarget)" + step, "\(userInfo.cyclingTarget)" + step, "\(userInfo.climbTarget)" + step]]
|
||
|
let descriptionList: [[String]] = [["\(userInfo.stepTarget)", "\(userInfo.sleepTarget)" + hour], ["\(userInfo.walkTarget)" + step, "\(userInfo.runTarget)" + step, "\(userInfo.cyclingTarget)" + step, "\(userInfo.climbTarget)" + step]]
|
||
|
|
||
|
var tempRelay: [SectionModel<String,TableViewCellModel>] = []
|
||
|
for i in 0..<funcationList.count {
|
||
|
var items: [TableViewCellModel] = []
|
||
|
funcationList[i].enumerated().forEach { (index, type) in
|
||
|
let isHiddenBottomLine = (index + 1) == funcationList[i].count
|
||
|
let description = descriptionList[i][index]
|
||
|
let cellModel = TableViewCellModel(title: type.title, isSwitch: false, description: description, isArrows: true, isOn: false, image: nil, isBottomLine: !isHiddenBottomLine, righeImg: nil, targetType: type)
|
||
|
items.append(cellModel)
|
||
|
}
|
||
![]()
1 year ago
|
let sectionTitle = i == 1 ? MultiLanguageKey_FB.sportTargetFB.localized : ""
|
||
![]()
2 years ago
|
tempRelay.append(SectionModel(model: sectionTitle, items: items))
|
||
|
}
|
||
|
relay.accept(tempRelay)
|
||
|
}
|
||
|
}
|