Fix search suggestions not working on resume
* add searchSuggestionString, isCorrectedSearch fields to state and load onResume
This commit is contained in:
parent
4194ac2226
commit
0711650ff8
|
@ -118,6 +118,12 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
|
||||||
@State
|
@State
|
||||||
String lastSearchedString;
|
String lastSearchedString;
|
||||||
|
|
||||||
|
@State
|
||||||
|
String searchSuggestionString;
|
||||||
|
|
||||||
|
@State
|
||||||
|
boolean isCorrectedSearch;
|
||||||
|
|
||||||
@State
|
@State
|
||||||
boolean wasSearchFocused = false;
|
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()) {
|
if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
|
||||||
initSuggestionObserver();
|
initSuggestionObserver();
|
||||||
}
|
}
|
||||||
|
@ -971,8 +981,10 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
|
||||||
NewPipe.getNameOfService(serviceId), searchString, 0);
|
NewPipe.getNameOfService(serviceId), searchString, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleSearchSuggestion(result);
|
handleSearchSuggestion(result.getSearchSuggestion(), result.isCorrectedSearch());
|
||||||
|
|
||||||
|
searchSuggestionString = result.getSearchSuggestion();
|
||||||
|
isCorrectedSearch = result.isCorrectedSearch();
|
||||||
lastSearchedString = searchString;
|
lastSearchedString = searchString;
|
||||||
nextPageUrl = result.getNextPageUrl();
|
nextPageUrl = result.getNextPageUrl();
|
||||||
currentPageUrl = result.getUrl();
|
currentPageUrl = result.getUrl();
|
||||||
|
@ -990,18 +1002,19 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
|
||||||
super.handleResult(result);
|
super.handleResult(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleSearchSuggestion(@NonNull final SearchInfo result) {
|
private void handleSearchSuggestion(@NonNull final String searchSuggestion,
|
||||||
if (!TextUtils.isEmpty(result.getSearchSuggestion())) {
|
@NonNull final Boolean isCorrected) {
|
||||||
String helperText = getString(result.isCorrectedSearch()
|
if (!TextUtils.isEmpty(searchSuggestion)) {
|
||||||
|
String helperText = getString(isCorrected
|
||||||
? R.string.search_showing_result_for
|
? R.string.search_showing_result_for
|
||||||
: R.string.did_you_mean);
|
: R.string.did_you_mean);
|
||||||
|
|
||||||
correctSuggestionText.setText(String.format(helperText, result.getSearchSuggestion()));
|
correctSuggestionText.setText(String.format(helperText, searchSuggestion));
|
||||||
|
|
||||||
correctSuggestionPanel.setOnClickListener(v -> {
|
correctSuggestionPanel.setOnClickListener(v -> {
|
||||||
correctSuggestionPanel.setVisibility(View.GONE);
|
correctSuggestionPanel.setVisibility(View.GONE);
|
||||||
search(result.getSearchSuggestion(), contentFilter, sortFilter);
|
search(searchSuggestion, contentFilter, sortFilter);
|
||||||
searchEditText.setText(result.getSearchSuggestion());
|
searchEditText.setText(searchSuggestion);
|
||||||
});
|
});
|
||||||
|
|
||||||
correctSuggestionPanel.setVisibility(View.VISIBLE);
|
correctSuggestionPanel.setVisibility(View.VISIBLE);
|
||||||
|
|
Loading…
Reference in New Issue