Skip to content

Latest commit

 

History

History
40 lines (32 loc) · 1.17 KB

README.md

File metadata and controls

40 lines (32 loc) · 1.17 KB

retrofit-livedata-adapter

This library mostly mirrors code from googlesamples/android-architecture-components, which can add LiveData support for Retrofit.

In a sense, this can be viewed as an official support.

Download

implementation 'me.linshen.retrofit2:adapter-livedata:1.0.0'

Usage

Retrofit.Builder()
            .baseUrl("https://github.com/gitapi/")
            .addConverterFactory(GsonConverterFactory.create())
            .addCallAdapterFactory(LiveDataCallAdapterFactory())
            .build()
            .create(GithubService::class.java)
            .getUser("shawnlinboy").observe(this,
                Observer { response ->
                    when (response) {
                        is ApiSuccessResponse -> {
                          //success response
                        }
                        else -> {
                            //failed response
                        }
                    }
                })