|
|
|
//
|
|
|
|
// TargetVM.swift
|
|
|
|
// Lookfit
|
|
|
|
//
|
|
|
|
// 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.stepTargetFB.localized
|
|
|
|
case .sleep: return MultiLanguageKey.sleepTargetFB.localized
|
|
|
|
case .walk: return MultiLanguageKey.walkTargetFB.localized
|
|
|
|
case .run: return MultiLanguageKey.runTargetFB.localized
|
|
|
|
case .cycling: return MultiLanguageKey.cyclingTargetFB.localized
|
|
|
|
case .climb: return MultiLanguageKey.climbTargetFB.localized
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 = UserDefaultsManager.getUserInfo() else { return }
|
|
|
|
// 功能列表
|
|
|
|
var funcationList: [[UserTargetType]] = [[.step, .sleep], [.walk, .run, .cycling, .climb]]
|
|
|
|
// 功能适配
|
|
|
|
if let adapterInfo = UserDefaultsManager.getDeviceInfo()?.adapterInfo {
|
|
|
|
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.stepTipFB.localized
|
|
|
|
let hour = MultiLanguageKey.hourFB.localized
|
|
|
|
// let min = MultiLanguageKey.minFB.localized
|
|
|
|
// 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.sportTargetFB.localized : ""
|
|
|
|
tempRelay.append(SectionModel(model: sectionTitle, items: items))
|
|
|
|
}
|
|
|
|
relay.accept(tempRelay)
|
|
|
|
}
|
|
|
|
}
|