Skip to content

Commit

Permalink
fix(search-suggestions-not-working-on-resume)
Browse files Browse the repository at this point in the history
* add searchSuggestionString, isCorrectedSearch fields to state and load onResume
  • Loading branch information
Royosef authored and wb9688 committed Jun 14, 2020
1 parent f1cdf77 commit 5c8d1bf
Showing 1 changed file with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -260,6 +266,10 @@ public void onResume() {
}
}

if (!TextUtils.isEmpty(searchSuggestionString)) {
handleSearchSuggestion(searchSuggestionString, isCorrectedSearch);
}

if (suggestionDisposable == null || suggestionDisposable.isDisposed()) {
initSuggestionObserver();
}
Expand Down Expand Up @@ -971,8 +981,10 @@ public void handleResult(@NonNull final SearchInfo result) {
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();
Expand All @@ -990,18 +1002,19 @@ public void handleResult(@NonNull final SearchInfo result) {
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);
Expand Down

0 comments on commit 5c8d1bf

Please sign in to comment.