From 869b2cc5c7ef31724a15afc6278e9d977f7dabd6 Mon Sep 17 00:00:00 2001 From: Robbie Cooper Date: Tue, 27 Aug 2024 19:08:57 -0400 Subject: [PATCH 1/2] Fix debouncing not working on first search character Should partially address #1729 and #769. Signed-off-by: Robbie Cooper --- .../owncloud/notes/edit/SearchableBaseNoteFragment.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java index 12d0cf2d..6814e4c0 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java @@ -228,8 +228,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment { handler.removeCallbacksAndMessages(null); } delayQueryTask = new DelayQueryRunnable(newText); - // If there is only one char in the search pattern, we should start the search immediately. - handler.postDelayed(delayQueryTask, newText.length() > 1 ? delay : 0); + handler.postDelayed(delayQueryTask, delay); } class DelayQueryRunnable implements Runnable { From a7859e1faa58055206751534092cec830a5fcd8a Mon Sep 17 00:00:00 2001 From: Robbie Cooper Date: Tue, 27 Aug 2024 20:04:30 -0400 Subject: [PATCH 2/2] Use a longer debounce delay for short search strings This gives the user more time to type in their whole query before a search blocks the main thread. Searches for short strings often have many results that aren't really useful to the user. They also take much longer to process. This commit increases the debounce delay to 200ms for short strings three characters long or less. Longer strings still have the 50ms delay. Hopefully, this is a good balance between avoiding slowdowns for short strings and providing a snappy interactive experience for long strings. --- .../owncloud/notes/edit/SearchableBaseNoteFragment.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java b/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java index 6814e4c0..54d9f4e5 100644 --- a/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java +++ b/app/src/main/java/it/niedermann/owncloud/notes/edit/SearchableBaseNoteFragment.java @@ -48,6 +48,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment { private SearchView searchView; private String searchQuery = null; private static final int delay = 50; // If the search string does not change after $delay ms, then the search task starts. + private static final int shortStringDelay = 200; // A longer delay for short search strings. + private static final int shortStringSize = 3; // The maximum length of a short search string. private boolean directEditRemotelyAvailable = false; // avoid using this directly, instead use: isDirectEditEnabled() @ColorInt @@ -228,7 +230,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment { handler.removeCallbacksAndMessages(null); } delayQueryTask = new DelayQueryRunnable(newText); - handler.postDelayed(delayQueryTask, delay); + // If there are few chars in the search pattern, we should start the search later. + handler.postDelayed(delayQueryTask, newText.length() > shortStringSize ? delay : shortStringDelay); } class DelayQueryRunnable implements Runnable {