Skip to content

Instantly share code, notes, and snippets.

@lisamariewatkins
Last active March 5, 2019 14:01
Show Gist options
  • Save lisamariewatkins/f87c2fdaf09a191095f9f5434d682791 to your computer and use it in GitHub Desktop.
Save lisamariewatkins/f87c2fdaf09a191095f9f5434d682791 to your computer and use it in GitHub Desktop.
AsyncTask and Retrofit
private class PetTask(val petList: ArrayList<Pet>, val petManager: PetManager): AsyncTask<Void, Void, Response<JsonResponse>>() {
override fun doInBackground(vararg params: Void?): Response<JsonResponse> {
return petManager.getPetList("78701").execute()
}
override fun onPostExecute(result: Response<JsonResponse>?) {
result?.body()?.petFinder?.pets?.pet?.let {
petList.addAll(it)
}
}
}
interface PetManager {
@GET("pet.find")
fun getPetList(@Query("location") location: String): Call<JsonResponse>
}
class PetManagerImpl: PetManager {
private val retrofitInstance = RetrofitFactory.retrofit().create(PetManager::class.java)
override fun getPetList(location: String): Call<JsonResponse> {
return retrofitInstance.getPetList(location)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment