Skip to content

retrofit simple LiveData CallAdapter and related LiveData wrapper for handling responses

Notifications You must be signed in to change notification settings

vahabghadiri/RetrofitLiveDataCallAdapter-Android

Repository files navigation

RetrofitLiveDataCallAdapter

retrofit simple LiveData CallAdapter and related LiveData wrapper for handling responses

sample usage :

retrofit init

Retrofit.Builder()
            .client(okHttpClient)
            .addConverterFactory(GsonConverterFactory.create(gson))
            .addCallAdapterFactory(LiveDataCallAdapterFactory())
            .baseUrl(BuildConfig.BASE_URL)
            .build()

service interface

interface CloudApiContract {
    @GET("/")
    fun getIP(): NetworkLiveData<String>
}

in view model

var ipLiveData = MutableLiveData<String>()
ipCloudRepository.getCurrentIP().observeForever {

            onSuccess {
                //body
                ipLiveData.value = it
            }
            onHttpException { code, message ->
                //code
                //message
            }
            onConnectionFailed { it.message.log() }

               //finished
        }

About

retrofit simple LiveData CallAdapter and related LiveData wrapper for handling responses

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages