Improve search suggestion code

This commit is contained in:
wb9688 2020-06-28 15:15:51 +02:00 committed by Stypox
parent 0711650ff8
commit ccd82fb8b8
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 8 additions and 10 deletions

View File

@ -119,7 +119,7 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
String lastSearchedString;
@State
String searchSuggestionString;
String searchSuggestion;
@State
boolean isCorrectedSearch;
@ -266,9 +266,7 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
}
}
if (!TextUtils.isEmpty(searchSuggestionString)) {
handleSearchSuggestion(searchSuggestionString, isCorrectedSearch);
}
handleSearchSuggestion();
if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
initSuggestionObserver();
@ -981,10 +979,11 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
NewPipe.getNameOfService(serviceId), searchString, 0);
}
handleSearchSuggestion(result.getSearchSuggestion(), result.isCorrectedSearch());
searchSuggestionString = result.getSearchSuggestion();
searchSuggestion = result.getSearchSuggestion();
isCorrectedSearch = result.isCorrectedSearch();
handleSearchSuggestion();
lastSearchedString = searchString;
nextPageUrl = result.getNextPageUrl();
currentPageUrl = result.getUrl();
@ -1002,10 +1001,9 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
super.handleResult(result);
}
private void handleSearchSuggestion(@NonNull final String searchSuggestion,
@NonNull final Boolean isCorrected) {
private void handleSearchSuggestion() {
if (!TextUtils.isEmpty(searchSuggestion)) {
String helperText = getString(isCorrected
final String helperText = getString(isCorrectedSearch
? R.string.search_showing_result_for
: R.string.did_you_mean);