diff --git a/app/src/main/java/helium314/keyboard/latin/LatinIME.java b/app/src/main/java/helium314/keyboard/latin/LatinIME.java index bafd0f3f0..be9cc0fce 100644 --- a/app/src/main/java/helium314/keyboard/latin/LatinIME.java +++ b/app/src/main/java/helium314/keyboard/latin/LatinIME.java @@ -1024,6 +1024,10 @@ void onStartInputViewInternal(final EditorInfo editorInfo, final boolean restart // Space state must be updated before calling updateShiftState switcher.requestUpdatingShiftState(getCurrentAutoCapsState(), getCurrentRecapitalizeState()); } + // This will remove old "stuck" inline suggestions + if (hasSuggestionStripView()) { + mSuggestionStripView.resetInlineSuggestions(); + } // This will set the punctuation suggestions if next word suggestion is off; // otherwise it will clear the suggestion strip. if (!mHandler.hasPendingResumeSuggestions()) { @@ -1315,6 +1319,11 @@ public InlineSuggestionsRequest onCreateInlineSuggestionsRequest(@NonNull Bundle @RequiresApi(api = Build.VERSION_CODES.R) public boolean onInlineSuggestionsResponse(InlineSuggestionsResponse response) { Log.d(TAG,"onInlineSuggestionsResponse called"); + // Ignore spammy requests if inline suggestions are already displayed or dismissed + if (!hasSuggestionStripView() || mSuggestionStripView.isInlineAutofillSuggestionsVisible() + || mSuggestionStripView.areInlineSuggestionsDismissed()) { + return false; + } final List inlineSuggestions = response.getInlineSuggestions(); if (inlineSuggestions.isEmpty()) { return false; @@ -1601,11 +1610,14 @@ private void setSuggestedWords(final SuggestedWords suggestedWords) { || currentSettingsValues.isApplicationSpecifiedCompletionsOn() // We should clear the contextual strip if there is no suggestion from dictionaries. || noSuggestionsFromDictionaries) { - mSuggestionStripView.setSuggestions(suggestedWords, - mRichImm.getCurrentSubtype().isRtlSubtype()); - // Auto hide the toolbar if dictionary suggestions are available - if (currentSettingsValues.mAutoHideToolbar && !noSuggestionsFromDictionaries) { - mSuggestionStripView.setToolbarVisibility(false); + if (mSuggestionStripView.isInlineAutofillSuggestionsVisible()){ + mSuggestionStripView.updateSuggestedWords(suggestedWords); + } else { + mSuggestionStripView.setSuggestions(suggestedWords, + mRichImm.getCurrentSubtype().isRtlSubtype()); + // Auto hide the toolbar if dictionary suggestions are available + if (currentSettingsValues.mAutoHideToolbar && !noSuggestionsFromDictionaries) + mSuggestionStripView.setToolbarVisibility(false); } } } diff --git a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java index 311781fef..e990376dc 100644 --- a/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java +++ b/app/src/main/java/helium314/keyboard/latin/suggestions/SuggestionStripView.java @@ -88,6 +88,7 @@ public interface Listener { private final Drawable mIncognitoIcon; private final Drawable mToolbarArrowIcon; private final Drawable mBinIcon; + private final Drawable mCloseIcon; private final ViewGroup mToolbar; private final View mToolbarContainer; private final ViewGroup mPinnedKeys; @@ -111,6 +112,7 @@ public interface Listener { private final SuggestionStripLayoutHelper mLayoutHelper; private final StripVisibilityGroup mStripVisibilityGroup; private boolean isInlineAutofillSuggestionsVisible = false; // Required to disable the more suggestions if inline autofill suggestions are visible + private boolean areInlineSuggestionsDismissed = false; private static class StripVisibilityGroup { private final View mSuggestionStripView; @@ -189,6 +191,7 @@ public SuggestionStripView(final Context context, final AttributeSet attrs, fina mIncognitoIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconIncognitoKey); mToolbarArrowIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconToolbarKey); mBinIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconBin); + mCloseIcon = keyboardAttr.getDrawable(R.styleable.Keyboard_iconClose); final LinearLayout.LayoutParams toolbarKeyLayoutParams = new LinearLayout.LayoutParams( getResources().getDimensionPixelSize(R.dimen.config_suggestions_strip_edge_key_width), @@ -248,7 +251,11 @@ private void updateKeys() { final View pinnedVoiceKey = mPinnedKeys.findViewWithTag(ToolbarKey.VOICE); if (pinnedVoiceKey != null) pinnedVoiceKey.setVisibility(currentSettingsValues.mShowsVoiceInputKey ? VISIBLE : GONE); - mToolbarExpandKey.setImageDrawable(currentSettingsValues.mIncognitoModeEnabled ? mIncognitoIcon : mToolbarArrowIcon); + if (isInlineAutofillSuggestionsVisible){ + mToolbarExpandKey.setImageDrawable(mCloseIcon); + } else { + mToolbarExpandKey.setImageDrawable(currentSettingsValues.mIncognitoModeEnabled ? mIncognitoIcon : mToolbarArrowIcon); + } mToolbarExpandKey.setScaleX((mToolbarContainer.getVisibility() != VISIBLE ? 1f : -1f) * mRtl); // hide pinned keys if device is locked, and avoid expanding toolbar @@ -258,7 +265,6 @@ private void updateKeys() { : km.isKeyguardLocked(); mToolbarExpandKey.setOnClickListener(hideToolbarKeys ? null : this); mPinnedKeys.setVisibility(hideToolbarKeys ? GONE : mSuggestionsStrip.getVisibility()); - isInlineAutofillSuggestionsVisible = false; } public void setRtl(final boolean isRtlLanguage) { @@ -272,6 +278,10 @@ public void setRtl(final boolean isRtlLanguage) { mStripVisibilityGroup.setLayoutDirection(layoutDirection); } + public void updateSuggestedWords(final SuggestedWords suggestedWords){ + mSuggestedWords = suggestedWords; + } + public void setSuggestions(final SuggestedWords suggestedWords, final boolean isRtlLanguage) { clear(); setRtl(isRtlLanguage); @@ -282,11 +292,24 @@ public void setSuggestions(final SuggestedWords suggestedWords, final boolean is } public void setInlineSuggestionsView(final View view) { - clear(); isInlineAutofillSuggestionsVisible = true; - mSuggestionsStrip.addView(view); - if (Settings.getInstance().getCurrent().mAutoHideToolbar) - setToolbarVisibility(false); + mSuggestionsStrip.addView(view, 0); + setToolbarVisibility(false); + updateKeys(); + } + + public void resetInlineSuggestions(){ + areInlineSuggestionsDismissed = false; + clear(); + updateKeys(); + } + + public boolean isInlineAutofillSuggestionsVisible(){ + return isInlineAutofillSuggestionsVisible; + } + + public boolean areInlineSuggestionsDismissed(){ + return areInlineSuggestionsDismissed; } @Override @@ -304,6 +327,7 @@ public void setMoreSuggestionsHeight(final int remainingHeight) { @SuppressLint("ClickableViewAccessibility") // why would "null" need to call View#performClick? private void clear() { mSuggestionsStrip.removeAllViews(); + isInlineAutofillSuggestionsVisible = false; if (DEBUG_SUGGESTIONS) removeAllDebugInfoViews(); if (mToolbarContainer.getVisibility() != VISIBLE) @@ -657,7 +681,12 @@ public void onClick(final View view) { } } if (view == mToolbarExpandKey) { - setToolbarVisibility(mToolbarContainer.getVisibility() != VISIBLE); + if (isInlineAutofillSuggestionsVisible) { + areInlineSuggestionsDismissed = true; + setSuggestions(mSuggestedWords, mRtl == -1); + } else { + setToolbarVisibility(mToolbarContainer.getVisibility() != VISIBLE); + } } diff --git a/app/src/main/res/layout/suggestions_strip.xml b/app/src/main/res/layout/suggestions_strip.xml index 6c0131240..2883109d2 100644 --- a/app/src/main/res/layout/suggestions_strip.xml +++ b/app/src/main/res/layout/suggestions_strip.xml @@ -56,6 +56,7 @@