From 8c07b6c473a370a71cb25e6472d770b036bfa352 Mon Sep 17 00:00:00 2001 From: NekoInverter <7741672-NekoInverter@users.noreply.gitlab.com> Date: Fri, 18 Dec 2020 15:05:06 +0800 Subject: [PATCH] Fix SearchBar crashes --- .../java/com/hippo/ehviewer/widget/SearchBar.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java index 83555ca21..f88398e3b 100644 --- a/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java +++ b/app/src/main/java/com/hippo/ehviewer/widget/SearchBar.java @@ -157,20 +157,20 @@ public class SearchBar extends MaterialCardView implements View.OnClickListener, } private void updateSuggestions(boolean scrollToTop) { - mSuggestionList.clear(); + List suggestions = new ArrayList<>(); String text = mEditText.getText().toString(); if (mSuggestionProvider != null) { - List suggestions = mSuggestionProvider.providerSuggestions(text); - if (suggestions != null && !suggestions.isEmpty()) { - mSuggestionList.addAll(suggestions); + List providerSuggestions = mSuggestionProvider.providerSuggestions(text); + if (providerSuggestions != null && !providerSuggestions.isEmpty()) { + suggestions.addAll(providerSuggestions); } } String[] keywords = mSearchDatabase.getSuggestions(text, 128); for (String keyword : keywords) { - mSuggestionList.add(new KeywordSuggestion(keyword)); + suggestions.add(new KeywordSuggestion(keyword)); } EhTagDatabase ehTagDatabase = EhTagDatabase.getInstance(getContext()); @@ -181,12 +181,13 @@ public class SearchBar extends MaterialCardView implements View.OnClickListener, ArrayList> searchHints = ehTagDatabase.suggest(keyword); for (Pair searchHint : searchHints) { - mSuggestionList.add(new TagSuggestion(searchHint.first, searchHint.second)); + suggestions.add(new TagSuggestion(searchHint.first, searchHint.second)); } } } + mSuggestionList = suggestions; mSuggestionAdapter.notifyDataSetChanged(); if (scrollToTop) {