I am using MVVM architectural component in my app.The task is to add retrofit with MVVM.
I am calling the webserver in every 10s to get the response data . To update this value i am using Mediator live data . This is code for it
public LiveData<LiveResponse.ResponseData> getLiveResponse(String userId, String tokenId, BodyRequest bodyRequest) {
final MutableLiveData<LiveResponse.ResponseData> liveResponseMutableLiveData = new MutableLiveData<>();
restApiService.getLiveResponse(userId, tokenId,bodyRequest).enqueue(new Callback<LiveResponse>() {
@Override
public void onResponse(@NotNull Call<LiveResponse> call, @NotNull Response<LiveResponse> response) {
try {
if (response.body()!=null){
if (response.body().isSuccess()){
Timber.i(" liveResponseMutableLiveData onResponse:");
liveResponseMutableLiveData.setValue(response.body().getResponseData());
}
}
}catch (Exception e){
e.printStackTrace();
}
}
@Override
public void onFailure(@NotNull Call<LiveResponse> call, @NotNull Throwable t) {
liveResponseMutableLiveData.setValue(null);
}
});
return liveResponseMutableLiveData;
}
I am facing the problem in getting the updated value even when the response has changed.
and how could i show the progress bar when this method is called and show the error if any in my view model .