Skip to content

Instantly share code, notes, and snippets.

@illuzor
Created September 20, 2018 20:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save illuzor/97138b226167a71ee1078025e2cfb18a to your computer and use it in GitHub Desktop.
Save illuzor/97138b226167a71ee1078025e2cfb18a to your computer and use it in GitHub Desktop.
package com.illuzor.lesson.wallpapers.model
import com.illuzor.lesson.wallpapers.api.api
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
class ViewModelCategories : ViewModelBase() {
lateinit var data: List<Category>
private set
fun load() {
state = State.PROGRESS
api.categories().enqueue(object : Callback<List<Category>> {
override fun onResponse(call: Call<List<Category>>, response: Response<List<Category>>) {
data = response.body()!!
state = State.LOADED
loadListener()
}
override fun onFailure(call: Call<List<Category>>, t: Throwable?) {
state = State.ERROR
loadListener()
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment