Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.3 kB
1
Indexable
Never
package com.app.healthupp.presentation.page.nutrition.more

import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.app.healthupp.domain.api.RetrofitService
import com.app.healthupp.domain.util.formatDateForUserEatenMeals
import com.app.healthupp.presentation.page.nutrition.NutritionPageViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import java.util.*
import javax.inject.Inject

@HiltViewModel
class NutritionSpecificInfoViewModel @Inject constructor(
    private val service: RetrofitService
): ViewModel() {

    private val _nutritionInfo = MutableLiveData("")
    val nutritionInfo: LiveData<String>
        get() = _nutritionInfo

    fun getNutritionInfo(id: Int) = viewModelScope.launch {
        kotlin.runCatching {
            service.getNutritionInfo(id)
        }.onSuccess { it ->
            it.data.let {
                println("co pokaze api: ${it.description}")
                _nutritionInfo.value = "test"
            }
        }.onFailure {
            Log.d(NutritionPageViewModel.TAG, "${it.message}, stackTrace = ${it.stackTraceToString()}")
        }
    }
}