Skip to content

Instantly share code, notes, and snippets.

@Lavanyagaur22
Created June 11, 2019 20:06
Show Gist options
  • Save Lavanyagaur22/6d9f818cef7ea7056c40f07d2ad9ab20 to your computer and use it in GitHub Desktop.
Save Lavanyagaur22/6d9f818cef7ea7056c40f07d2ad9ab20 to your computer and use it in GitHub Desktop.
fun getTasks() {
noteslist.clear()
Log.e(TAG, "inside getTasks")
Log.e(TAG, " getActiveCallsCount : ${Utils.getApolloClient(this)?.activeCallsCount()}")
apolloStore = Utils.getApolloClient(this)?.apolloStore()!!
Log.e(TAG, " apolloStore : ${Utils.getApolloClient(this)?.apolloStore()}")
val client: ApolloCall<AllTasksQuery.Data> = Utils.getApolloClient(this)?.query(
AllTasksQuery.builder().build()
)?.responseFetcher(ApolloResponseFetchers.CACHE_FIRST) as ApolloCall<AllTasksQuery.Data>
Rx2Apollo.from(client).subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread())
?.subscribeWith(object : DisposableObserver<Response<AllTasksQuery.Data>>() {
override fun onComplete() {
}
override fun onNext(result: Response<AllTasksQuery.Data>) {
Log.e(TAG, " onNext : ${result.data()?.allTasks()?.size}")
result?.data()?.allTasks()?.forEach {
val title = it.title()
val desc = it.description()
val id = it.id()
val version: Int? = it.version()
val task = Task(title, desc, id.toInt(), version!!)
noteslist.add(task)
}
runOnUiThread {
Log.e(TAG, " Size ${noteslist.size}")
taskAdapter.notifyDataSetChanged()
}
}
override fun onError(e: Throwable) {
Log.e(TAG, " onError : ${e.message}")
}
}
)?.let {
disposables.add(
it
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment