kotlin
class ImageViewModel : ViewModel() {
private val _imageLiveData = MutableLiveData<Resource<Bitmap>>()
val imageLiveData: LiveData<Resource<Bitmap>> get() = _imageLiveData
fun loadImage(url: String) {
viewModelScope.launch {
_imageLiveData.value = Resource.Loading()
try {
val bitmap = withContext(Dispatchers.IO) {
}
_imageLiveData.value = Resource.Success(bitmap)
} catch (e: Exception) {
_imageLiveData.value = Resource.Error(e.message)
}
}
}
}