mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-12-18 00:22:17 +03:00
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.
This commit is contained in:
parent
869b2cc5c7
commit
a7859e1faa
1 changed files with 4 additions and 1 deletions
|
@ -48,6 +48,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
private SearchView searchView;
|
private SearchView searchView;
|
||||||
private String searchQuery = null;
|
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 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()
|
private boolean directEditRemotelyAvailable = false; // avoid using this directly, instead use: isDirectEditEnabled()
|
||||||
|
|
||||||
@ColorInt
|
@ColorInt
|
||||||
|
@ -228,7 +230,8 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
|
||||||
handler.removeCallbacksAndMessages(null);
|
handler.removeCallbacksAndMessages(null);
|
||||||
}
|
}
|
||||||
delayQueryTask = new DelayQueryRunnable(newText);
|
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 {
|
class DelayQueryRunnable implements Runnable {
|
||||||
|
|
Loading…
Reference in a new issue