Don't update search query unless it has changed meaningfully.
Changing the search query is quite an expensive operation, so this does some rudimentary checking to see if the two queries are meaningfully different. At present, it trims the strings and does a case insensitive comparison. The query is eventually exploded based on whitespace, so leading and trailing white space is not important. Also, sqlite `LIKE` clauses are case insensitive, so case is unimportant. Having said that, I'm not sure how someone will be able to change the queries case without first deleting and then adding characters (thus inducing meaningfull changse).
This commit is contained in:
parent
bd0e9e0a3c
commit
8060ac88c3
@ -58,7 +58,22 @@ public class AppListFragmentPagerAdapter extends FragmentPagerAdapter {
|
||||
return parent.getString(R.string.tab_updates_count, updateCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* Changing the search query is quite an expensive operation, so this does some rudimentary
|
||||
* checking to see if the two queries are meaningfully different. At present, it trims the
|
||||
* strings and does a case insensitive comparison.
|
||||
*/
|
||||
private boolean isSearchQuerySame(String newQuery) {
|
||||
String oldValueTrimmed = searchQuery == null ? "" : searchQuery.trim();
|
||||
String newValueTrimmed = newQuery == null ? "" : newQuery.trim();
|
||||
return oldValueTrimmed.equalsIgnoreCase(newValueTrimmed);
|
||||
}
|
||||
|
||||
public void updateSearchQuery(@Nullable String query) {
|
||||
if (isSearchQuerySame(query)) {
|
||||
return;
|
||||
}
|
||||
|
||||
searchQuery = query;
|
||||
for (AppListFragment fragment : registeredFragments) {
|
||||
if (fragment != null) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user