Skip to content

Commit

Permalink
Fix the underlying problem as described in the issue #7647
Browse files Browse the repository at this point in the history
  • Loading branch information
dtcxzyw committed Apr 18, 2022
1 parent 05ca6d5 commit 71714b7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ public class SearchFragment extends BaseListFragment<SearchInfo, ListExtractor.I
@State
boolean wasSearchFocused = false;

@Nullable
private Map<Integer, String> menuItemToFilterName = null;
@Nullable private Map<Integer, String> menuItemToFilterName = null;
private StreamingService service;
private Page nextPage;
private boolean showLocalSuggestions = true;
Expand Down Expand Up @@ -561,15 +560,6 @@ private void initSearchListeners() {
&& hasFocus && !isErrorPanelVisible()) {
showSuggestionsPanel();
}

// The state of keyboard will be maintained before onResume()
if (!isResumed() && hasFocus) {
if (TextUtils.isEmpty(searchString) || wasSearchFocused) {
showKeyboardSearch();
} else {
hideKeyboardSearch();
}
}
});

suggestionListAdapter.setListener(new SuggestionListAdapter.OnSuggestionItemSelected() {
Expand Down Expand Up @@ -856,8 +846,7 @@ private void search(final String theSearchString,
disposables.add(historyRecordManager.onSearched(serviceId, theSearchString)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
ignored -> {
},
ignored -> { },
throwable -> showSnackBarError(new ErrorInfo(throwable, UserAction.SEARCHED,
theSearchString, serviceId))
));
Expand Down
14 changes: 13 additions & 1 deletion app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,19 @@ public static void showKeyboard(final Activity activity, final EditText editText
if (editText.requestFocus()) {
final InputMethodManager imm = ContextCompat.getSystemService(activity,
InputMethodManager.class);
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
if (!imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED)) {
/*
* Sometimes the keyboard can't be shown because Android's ImeFocusController is in
* a incorrect state e.g. when animations are disabled or the unfocus event of the
* previous view arrives in the wrong moment (see #7647 for details).
* The invalid state can be fixed by to re-focusing the editText.
*/
editText.clearFocus();
editText.requestFocus();

// Try again
imm.showSoftInput(editText, InputMethodManager.SHOW_FORCED);
}
}
}

Expand Down

0 comments on commit 71714b7

Please sign in to comment.