Fix search suggestions not working on resume

* add searchSuggestionString, isCorrectedSearch fields to state and load onResume
This commit is contained in:
Roy Yosef 2020-06-06 23:44:04 +03:00 committed by Stypox
parent 4194ac2226
commit 0711650ff8
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
1 changed files with 20 additions and 7 deletions

View File

@ -118,6 +118,12 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
@State
String lastSearchedString;
@State
String searchSuggestionString;
@State
boolean isCorrectedSearch;
@State
boolean wasSearchFocused = false;
@ -260,6 +266,10 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
}
}
if (!TextUtils.isEmpty(searchSuggestionString)) {
handleSearchSuggestion(searchSuggestionString, isCorrectedSearch);
}
if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
initSuggestionObserver();
}
@ -971,8 +981,10 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
NewPipe.getNameOfService(serviceId), searchString, 0);
}
handleSearchSuggestion(result);
handleSearchSuggestion(result.getSearchSuggestion(), result.isCorrectedSearch());
searchSuggestionString = result.getSearchSuggestion();
isCorrectedSearch = result.isCorrectedSearch();
lastSearchedString = searchString;
nextPageUrl = result.getNextPageUrl();
currentPageUrl = result.getUrl();
@ -990,18 +1002,19 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
super.handleResult(result);
}
private void handleSearchSuggestion(@NonNull final SearchInfo result) {
if (!TextUtils.isEmpty(result.getSearchSuggestion())) {
String helperText = getString(result.isCorrectedSearch()
private void handleSearchSuggestion(@NonNull final String searchSuggestion,
@NonNull final Boolean isCorrected) {
if (!TextUtils.isEmpty(searchSuggestion)) {
String helperText = getString(isCorrected
? R.string.search_showing_result_for
: R.string.did_you_mean);
correctSuggestionText.setText(String.format(helperText, result.getSearchSuggestion()));
correctSuggestionText.setText(String.format(helperText, searchSuggestion));
correctSuggestionPanel.setOnClickListener(v -> {
correctSuggestionPanel.setVisibility(View.GONE);
search(result.getSearchSuggestion(), contentFilter, sortFilter);
searchEditText.setText(result.getSearchSuggestion());
search(searchSuggestion, contentFilter, sortFilter);
searchEditText.setText(searchSuggestion);
});
correctSuggestionPanel.setVisibility(View.VISIBLE);