Occasionally getting the Response in JSON format can take a few minutes because the JSON can have multiple objects in it.
My goal is to show the progress of getting the Response.
For this purpose I simplify my example of getting the Response using Retrofit.
UserApi
@GET("users")
@Headers(
"Accept:$HEADERS_ACCEPT", "Content-Type:$HEADERS_CONTENT_TYPE",
"Authorization: $AUTHORISATION_TYPE $API_KEY"
)
fun getUsersList(@Query("page") pageNo: String, @Query("per_page") perPageNo: String): Call<List<User>>
Repository:
override suspend fun getUsersList(pageNo: String , perPageNo: String,
usersLiveData: MutableLiveData<List<User>?>) = withContext(ioDispatcher) {
val call = retrofitUserApiInstance.getUsersList(pageNo, perPageNo)
call.enqueue(object : Callback<List<User>> {
override fun onFailure(call: Call<List<User>>, t: Throwable) {
usersLiveData.postValue(null)
}
override fun onResponse(call: Call<List<User>>, response: Response<List<User>>) {
if (response.isSuccessful) {
usersLiveData.postValue(response.body())
} else {
usersLiveData.postValue(null)
}
}
})
}
>` to streamline this further. But none of what I'm saying deals with the task of getting progress while it's going. That doesn't lend itself well to a suspend function. Maybe a Flow, but I don't know how to build it. I don't know how to do a GET request with progress updates.