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

2 years ago
//
// TargetVM.swift
// 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 {
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() {
guard let userInfo = UserDefaultsManagerFrieBoltt.getUserInfo() else { return }
2 years ago
//
var funcationList: [[UserTargetType]] = [[.step, .sleep], [.walk, .run, .cycling, .climb]]
//
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)
}
}
}
}
//
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)
}
let sectionTitle = i == 1 ? MultiLanguageKey_FB.sportTargetFB.localized : ""
2 years ago
tempRelay.append(SectionModel(model: sectionTitle, items: items))
}
relay.accept(tempRelay)
}
}