From 0f1f43057e53366dd649d8823ca113a86ce94a07 Mon Sep 17 00:00:00 2001 From: Viktor De Pasquale Date: Mon, 18 Nov 2019 16:16:34 +0100 Subject: [PATCH] Updated handling queries so first query is always instant --- .../com/topjohnwu/magisk/redesign/compat/Queryable.kt | 5 +---- .../com/topjohnwu/magisk/redesign/hide/HideViewModel.kt | 8 ++++++-- .../topjohnwu/magisk/redesign/module/ModuleViewModel.kt | 8 ++++++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/Queryable.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/Queryable.kt index 68c785b61..3d6f43661 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/compat/Queryable.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/compat/Queryable.kt @@ -17,10 +17,7 @@ interface Queryable { override val queryHandler = Handler(Looper.getMainLooper()) override val queryRunnable = Runnable { TODO() } - override fun submitQuery() { - queryHandler.removeCallbacks(queryRunnable) - queryHandler.postDelayed(queryRunnable, queryDelay) - } + override fun submitQuery() {} } } } \ No newline at end of file diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideViewModel.kt index 9e7b43d20..6cc893626 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/hide/HideViewModel.kt @@ -84,8 +84,12 @@ class HideViewModel( // --- override fun submitQuery() { - queryHandler.removeCallbacks(queryRunnable) - queryHandler.postDelayed(queryRunnable, queryDelay) + if (!queryHandler.hasCallbacks(queryRunnable)) { + queryHandler.post(queryRunnable) + } else { + queryHandler.removeCallbacks(queryRunnable) + queryHandler.postDelayed(queryRunnable, queryDelay) + } } private fun query( diff --git a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt index 320bf8357..585ffb8bf 100644 --- a/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/redesign/module/ModuleViewModel.kt @@ -166,8 +166,12 @@ class ModuleViewModel( // --- override fun submitQuery() { - queryHandler.removeCallbacks(queryRunnable) - queryHandler.postDelayed(queryRunnable, queryDelay) + if (!queryHandler.hasCallbacks(queryRunnable)) { + queryHandler.post(queryRunnable) + } else { + queryHandler.removeCallbacks(queryRunnable) + queryHandler.postDelayed(queryRunnable, queryDelay) + } } private fun queryInternal(query: String, offset: Int): Single> {