package com.eacenic.weighttrack import android.os.Build import android.util.Log import androidx.annotation.RequiresApi import androidx.lifecycle.ViewModel import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import java.time.LocalDateTime const val TAG = "WeightTrackViewModel" class WeightTrackViewModel: ViewModel() { @RequiresApi(Build.VERSION_CODES.O) private var _historyData = MutableStateFlow>(mutableListOf( WeightRecord(62.6f, LocalDateTime.now()), WeightRecord(63.6f, LocalDateTime.now()), WeightRecord(65.6f, LocalDateTime.now()) )) @RequiresApi(Build.VERSION_CODES.O) val historyData: StateFlow> = _historyData @RequiresApi(Build.VERSION_CODES.O) fun addWeightRecord(newRecord: WeightRecord) { val newRecords = _historyData.value.toMutableList() newRecords.add(newRecord) _historyData.value = newRecords Log.e(TAG, "$newRecord") Log.e(TAG, "${_historyData.value}") } }