Source: ```class MyPublishedAdvertisementsViewMod...
# android-architecture
o
Source:
Copy code
class MyPublishedAdvertisementsViewModel(private val advertisementRepository : AdvertisementRepository) : ViewModel(){

    var _myPublishedAdvertisements : MutableLiveData<NetworkCall<MyPublishedAdvertisementsResponse>> = MutableLiveData()
    val myPublishedAdvertisements : LiveData< NetworkCall<MyPublishedAdvertisementsResponse> > = _myPublishedAdvertisements

    // Called every time our UI is #onStarted
    fun getFreshData(){
        _myPublishedAdvertisements.value = liveData {
            emit(NetworkCall<MyPublishedAdvertisementsResponse>(NetworkStatus.LOADING, null, ""))
            val publishedAdvertisements = advertisementRepository.getMyPublishedAdvertisements()
            emit(publishedAdvertisements)
        }
    }

}
k
Does your NetworkCall extends LiveData?
o
No
It is a wrapper data class to be used for all my network responses, this is the code:
Copy code
data class NetworkCall<out T>(val status: NetworkStatus, val data: T?, val message: String?) {

    companion object {
        fun <T> success(data: T?): NetworkCall<T> {
            return NetworkCall(NetworkStatus.SUCCESS, data, null)
        }

        fun <T> error(msg: String, data: T?): NetworkCall<T> {
            return NetworkCall(NetworkStatus.ERROR, data, msg)
        }

        fun <T> loading(data: T?): NetworkCall<T> {
            return NetworkCall(NetworkStatus.LOADING, data, null)
        }
    }

}
k
But you’re putting liveData{} as a value of another live data
o
I am not sure what I am doing wrong 🤔
k
Seems like you are doing this, isn’t?
o
Ohhhh, ok I got what you’re saying But I still don’t understand how I use liveData{} to change the values of a MutableLiveData. Why for LiveData I can use liveData{}, and for MutableLiveData I can’t?
k
For my opinion you are trying to achieve something completely wrong. You should rethink this code. Also, there shouldn’t be any network requests from your view model class this is bad practice.
o
I will check thanks for the help anyway @Kirill Prybylsky