Skip to content

Commit

Permalink
Two main midifications: 1) Move delay to the top of class SearchableB…
Browse files Browse the repository at this point in the history
…aseNoteFragment; 2) If there is only one char in the search pattern, search it immediately without delay
  • Loading branch information
Isaac-Graham committed Apr 22, 2020
1 parent d2e8f97 commit cb42949
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public abstract class SearchableBaseNoteFragment extends BaseNoteFragment {
private int occurrenceCount = 0;
private SearchView searchView;
private String searchQuery = null;
private final int delay = 50; // If the search string does not change after $delay ms, then the search task starts.

@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -108,7 +109,6 @@ public void onGlobalLayout() {
}

searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private final int delay = 20; // If the search string does not change after $delay ms, then the search task starts.
private DelayQueryRunnable delayQueryTask;
private Handler handler = new Handler();

Expand Down Expand Up @@ -144,7 +144,8 @@ private void queryWithHandler(String newText) {
handler.removeCallbacksAndMessages(null);
}
delayQueryTask = new DelayQueryRunnable(newText);
handler.postDelayed(delayQueryTask, delay);
// If there is only one char in the search pattern, we should start the search immediately.
handler.postDelayed(delayQueryTask, newText.length() > 1 ? delay : 0);
}

class DelayQueryRunnable implements Runnable {
Expand Down

0 comments on commit cb42949

Please sign in to comment.