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,9 +84,13 @@ class HideViewModel(
// --- // ---
override fun submitQuery() { override fun submitQuery() {
if (!queryHandler.hasCallbacks(queryRunnable)) {
queryHandler.post(queryRunnable)
} else {
queryHandler.removeCallbacks(queryRunnable) queryHandler.removeCallbacks(queryRunnable)
queryHandler.postDelayed(queryRunnable, queryDelay) queryHandler.postDelayed(queryRunnable, queryDelay)
} }
}
private fun query( private fun query(
query: String = this.query, query: String = this.query,

View File

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