Skip to content

Instantly share code, notes, and snippets.

@illuzor
Created September 22, 2018 18:39
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/a2ede071849a21ad91942485207f0497 to your computer and use it in GitHub Desktop.
Save illuzor/a2ede071849a21ad91942485207f0497 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 ViewModelGallery : ViewModelBase() {
lateinit var data: List<String>
private set
fun load(category: String) {
state = State.PROGRESS
api.gallery(category).enqueue(object : Callback<List<String>> {
override fun onResponse(call: Call<List<String>>, response: Response<List<String>>) {
data = response.body()!!
state = State.LOADED
loadListener()
}
override fun onFailure(call: Call<List<String>>, t: Throwable?) {
state = State.ERROR
loadListener()
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment