Copy the following classes in your project to use LiveData<ApiResponse<T>>
instead of Call<T>
in Retrofit services.
Made this gist so everyone can just copy and paste them in project rather than finding through the Google Samples.
Original Credits: I didn't make these classes, they are from Google Sample
interface SomeService {
@GET("data")
fun getData(): Call<T>
}
interface SomeService {
@GET("data")
fun getData(): LiveData<ApiResponse<T>>
}
Set the LiveDataCallAdapterFactory
in the Retrofit Builder
Retrofit.Builder()
.baseUrl(BASE_URL)
// ....
.addCallAdapterFactory(new LiveDataCallAdapterFactory())
// ....
.build()