// // StepCellViewModels.swift // Lookfit // // Created by lemo. on 2020/4/18. // Copyright © 2020 Sheldon. All rights reserved. // import UIKit class StepCellViewModels: ViewModel { let realStepModel = BehaviorRelay(value: RealtimeStepModel()) let step = BehaviorRelay(value: "0") let calories = BehaviorRelay(value: "0") let distance = BehaviorRelay(value: "0") let progress = BehaviorRelay(value: 0) let dateStr = BehaviorRelay(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) } }