Updated handling queries so first query is always instant

This commit is contained in:
Viktor De Pasquale 2019-11-18 16:16:34 +01:00
parent 784a7a7f24
commit 0f1f43057e
3 changed files with 13 additions and 8 deletions

View File

@ -17,10 +17,7 @@ interface Queryable {
override val queryHandler = Handler(Looper.getMainLooper()) override val queryHandler = Handler(Looper.getMainLooper())
override val queryRunnable = Runnable { TODO() } override val queryRunnable = Runnable { TODO() }
override fun submitQuery() { override fun submitQuery() {}
queryHandler.removeCallbacks(queryRunnable)
queryHandler.postDelayed(queryRunnable, queryDelay)
}
} }
} }
} }

View File

@ -84,8 +84,12 @@ class HideViewModel(
// --- // ---
override fun submitQuery() { override fun submitQuery() {
queryHandler.removeCallbacks(queryRunnable) if (!queryHandler.hasCallbacks(queryRunnable)) {
queryHandler.postDelayed(queryRunnable, queryDelay) queryHandler.post(queryRunnable)
} else {
queryHandler.removeCallbacks(queryRunnable)
queryHandler.postDelayed(queryRunnable, queryDelay)
}
} }
private fun query( private fun query(

View File

@ -166,8 +166,12 @@ class ModuleViewModel(
// --- // ---
override fun submitQuery() { override fun submitQuery() {
queryHandler.removeCallbacks(queryRunnable) if (!queryHandler.hasCallbacks(queryRunnable)) {
queryHandler.postDelayed(queryRunnable, queryDelay) queryHandler.post(queryRunnable)
} else {
queryHandler.removeCallbacks(queryRunnable)
queryHandler.postDelayed(queryRunnable, queryDelay)
}
} }
private fun queryInternal(query: String, offset: Int): Single<List<RepoItem>> { private fun queryInternal(query: String, offset: Int): Single<List<RepoItem>> {