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.
 
 
 

35 lines
1.3 KiB

//
// StepCellViewModels.swift
// Lookfit
//
// Created by lemo. on 2020/4/18.
// Copyright © 2020 Sheldon. All rights reserved.
//
import UIKit
class StepCellViewModels: ViewModel {
let realStepModel = BehaviorRelay<RealtimeStepModel>(value: RealtimeStepModel())
let step = BehaviorRelay<String>(value: "0")
let calories = BehaviorRelay<String>(value: "0")
let distance = BehaviorRelay<String>(value: "0")
let progress = BehaviorRelay<CGFloat>(value: 0)
let dateStr = BehaviorRelay<String>(value: DateClass.timestampToStr(Int(Date().timeIntervalSince1970), formatStr: "yyyy/MM/dd"))
override init() {
super.init()
realStepModel
.subscribe(onNext: { [weak self] (realStepModel) in
guard let `self` = self else { return }
self.step.accept(String(realStepModel.stepNumber))
self.calories.accept(String(format: "%.1f", realStepModel.stepCalorie))
self.distance.accept(String(format: "%.1f", CGFloat(realStepModel.stepDistance) / 1000.0))
guard let userInfo = UserDefaultsManager.getUserInfo() else { return }
let progress = CGFloat(realStepModel.stepNumber) / CGFloat(userInfo.stepTarget)
self.progress.accept(progress)
})
.disposed(by: rx.disposeBag)
}
}