kotlin-coroutine-glide-picasso
Simple android app using displaying images using glide and picasso and retrofit implementation using kotlin-coroutines
App Uses Pixabay API to fetch Images for more details please use -> Pixabay Please generate api from pixabay by signing up on Pixabay its free. Update the API_KEY in Constants.kt
without coroutine
@GET("api/?")
suspend fun getImages(
@Query("key") apiKey: String,
@Query("q") query: String,
@Query("image_type") imageType: String,
@Query("pretty") yesOrNo: Boolean
):ApiResponse
fun getImagesForGlideView() {
apiService.getImages(API_KEY,"food","photo",true).enqueue(object : Callback<ApiResponse> {
override fun onResponse(call: Call<ApiResponse>, response: Response<ApiResponse>) {
apiResponse.postValue(response.body())
}
override fun onFailure(call: Call<ApiResponse>, t: Throwable) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
})
}
with coroutine
@GET("api/?")
fun getImages(@Query("key") apiKey: String,
@Query("q") query: String,
@Query("image_type") imageType: String,
@Query("pretty") yesOrNo: Boolean): Call<ApiResponse>
fun getImagesForGlideView() {
CoroutineScope(IO).launch {
apiResponse.postValue(apiService.getImages(API_KEY,"food","photo",true))
}
}