From 71714b7e1ee15bf1ab1a67d2272b3877c32ba931 Mon Sep 17 00:00:00 2001 From: Yingwei Zheng Date: Mon, 18 Apr 2022 13:44:34 +0800 Subject: [PATCH] Fix the underlying problem as described in the issue #7647 --- .../fragments/list/search/SearchFragment.java | 15 ++------------- .../org/schabi/newpipe/util/KeyboardUtil.java | 14 +++++++++++++- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java index 04592d98052..01010839239 100644 --- a/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java +++ b/app/src/main/java/org/schabi/newpipe/fragments/list/search/SearchFragment.java @@ -141,8 +141,7 @@ public class SearchFragment extends BaseListFragment menuItemToFilterName = null; + @Nullable private Map menuItemToFilterName = null; private StreamingService service; private Page nextPage; private boolean showLocalSuggestions = true; @@ -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() { @@ -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)) )); diff --git a/app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java b/app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java index 71c0d394494..a709dc32ecf 100644 --- a/app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java +++ b/app/src/main/java/org/schabi/newpipe/util/KeyboardUtil.java @@ -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); + } } }