Skip to content

Commit

Permalink
#19 Local Search asynchronously
Browse files Browse the repository at this point in the history
Searches are now performed asynchronously for performance reasons.
  • Loading branch information
stefan-niedermann committed Feb 8, 2016
1 parent 04f766d commit 2d76040
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,20 +203,25 @@ public boolean onQueryTextSubmit(String query) {

@Override
public boolean onQueryTextChange(String newText) {
search(newText);
search(newText.trim());
return true;
}
});
return true;
}

private void search(String query) {
if (query.length() > 0) {
setListView(db.searchNotes(query));
} else {
setListView(db.getNotes());
}
listView.scrollToPosition(0);
private void search(final String query) {
new Thread() {
@Override
public void run() {
if (query.length() > 0) {
setListView(db.searchNotes(query));
} else {
setListView(db.getNotes());
}
listView.scrollToPosition(0);
}
}.run();
}

@Override
Expand Down Expand Up @@ -351,6 +356,15 @@ public boolean onNoteLongClick(int position, View v) {
return selected;
}

@Override
public void onBackPressed() {
if (searchView.isIconified()) {
super.onBackPressed();
} else {
searchView.setIconified(true);
}
}

/**
* Handler for the MultiSelect Actions
*/
Expand Down

0 comments on commit 2d76040

Please sign in to comment.