Last active
March 5, 2019 14:01
-
-
Save lisamariewatkins/f87c2fdaf09a191095f9f5434d682791 to your computer and use it in GitHub Desktop.
AsyncTask and Retrofit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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