Skip to content

Commit

Permalink
2 min retention. Fix flickering and suggestions not clearing. Auto to…
Browse files Browse the repository at this point in the history
…ggle toolbar
  • Loading branch information
codokie committed Apr 9, 2024
1 parent 9b6bc78 commit ba3f49b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ClipboardHistoryManager(
onHistoryChangeListener?.onClipboardHistoryEntriesRemoved(pos, count)
}
if (latinIME.mSettings.current.mSuggestClipboardContent) {
latinIME.setNeutralSuggestionStrip() // get rid of any clipboard suggestion
latinIME.clearSuggestions() // get rid of any clipboard suggestion
}
}

Expand Down Expand Up @@ -143,13 +143,11 @@ class ClipboardHistoryManager(
}

fun retrieveRecentClipboardContent(updateEntry: Boolean): String {
val maxClipRetentionTime: Long =
latinIME.mSettings.current.mClipboardHistoryRetentionTime * 60000L
val clipContent = retrieveClipboardContent().toString()
val now = System.currentTimeMillis()
val isNewEntry = recentEntry != clipContent
val isRecent = (now - recentTimestamp) < maxClipRetentionTime
return if (isNewEntry || isRecent && !suggestionPicked || maxClipRetentionTime == 0L) {
val isRecent = (now - recentTimestamp) < TWO_MINUTES_MILLIS
return if (isNewEntry || isRecent && !suggestionPicked) {
if (updateEntry && isNewEntry) {
suggestionPicked = false
recentEntry = clipContent
Expand Down Expand Up @@ -185,5 +183,6 @@ class ClipboardHistoryManager(
companion object {
// store pinned clips in companion object so they survive a keyboard switch (which destroys the current instance)
private val historyEntries: MutableList<ClipboardHistoryEntry> = ArrayList()
private const val TWO_MINUTES_MILLIS = 2 * 60 * 1000L
}
}
23 changes: 19 additions & 4 deletions app/src/main/java/helium314/keyboard/latin/LatinIME.java
Original file line number Diff line number Diff line change
Expand Up @@ -1317,7 +1317,7 @@ public InlineSuggestionsRequest onCreateInlineSuggestionsRequest(@NonNull Bundle
public boolean onInlineSuggestionsResponse(InlineSuggestionsResponse response) {
Log.d(TAG,"onInlineSuggestionsResponse called");
final List<InlineSuggestion> inlineSuggestions = response.getInlineSuggestions();
if (inlineSuggestions.isEmpty()) {
if (inlineSuggestions.isEmpty() || mSuggestionStripView.isInlineAutofillSuggestionsVisible()) {
return false;
}

Expand Down Expand Up @@ -1581,7 +1581,7 @@ private void setSuggestedWords(final SuggestedWords suggestedWords) {
final SettingsValues currentSettingsValues = mSettings.getCurrent();
mInputLogic.setSuggestedWords(suggestedWords);
// TODO: Modify this when we support suggestions with hard keyboard
if (!hasSuggestionStripView()) {
if (!hasSuggestionStripView() || mSuggestionStripView.isInlineAutofillSuggestionsVisible()) {
return;
}
if (!onEvaluateInputViewShown()) {
Expand Down Expand Up @@ -1655,6 +1655,7 @@ public void onClipboardSuggestionPicked(){

// This will show a suggestion of the primary clipboard
// if there is one and the setting is enabled.
// If not, show the toolbar instead when there is no need to lookup suggestions yet.
// Otherwise, an empty suggestion strip (if prediction is enabled)
// or punctuation suggestions (if it's disabled) will be shown.
@Override
Expand All @@ -1663,22 +1664,36 @@ public void setNeutralSuggestionStrip() {
if (currentSettings.mSuggestClipboardContent) {
final String clipContent = mClipboardHistoryManager.retrieveRecentClipboardContent(true);
if (!clipContent.isEmpty()) {
EditorInfo editorInfo = getCurrentInputEditorInfo();
int inputType = (editorInfo != null) ? editorInfo.inputType : InputType.TYPE_NULL;
final EditorInfo editorInfo = getCurrentInputEditorInfo();
final int inputType = (editorInfo != null) ? editorInfo.inputType : InputType.TYPE_NULL;
// make sure content that is not a number is not suggested in a number input type
if (!InputTypeUtils.isNumberInputType(inputType) || StringUtilsKt.isValidNumber(clipContent)) {
setSuggestedWords(mInputLogic.getClipboardSuggestion(clipContent, inputType));
return;
}
}
}
// show the toolbar when we have just started composing,
// or when there is no need to lookup suggestions
// and there is no inline suggestion visible.
if (hasSuggestionStripView() && (mInputLogic.getComposingStart() <= 0
|| (!mSettings.getCurrent().needsToLookupSuggestions()
&& !mSuggestionStripView.isInlineAutofillSuggestionsVisible()))) {
clearSuggestions();
mSuggestionStripView.setToolbarVisibility(true);
return;
}
if (!currentSettings.mBigramPredictionEnabled) {
setSuggestedWords(currentSettings.mSpacingAndPunctuations.mSuggestPuncList);
return;
}
setSuggestedWords(SuggestedWords.getEmptyInstance());
}

public void clearSuggestions(){
mSuggestionStripView.clear();
}

@Override
public void removeSuggestion(final String word) {
mDictionaryFacilitator.removeWord(word);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public void setSuggestions(final SuggestedWords suggestedWords, final boolean is
mStartIndexOfMoreSuggestions = mLayoutHelper.layoutAndReturnStartIndexOfMoreSuggestions(
getContext(), mSuggestedWords, mSuggestionsStrip, this);
setInlineSuggestionsView(mCurrentInlineAutofillSuggestionsView);
setToolbarVisibility(false);
}

public void setInlineSuggestionsView(final View view) {
Expand All @@ -296,9 +297,14 @@ public void setInlineSuggestionsView(final View view) {
isInlineAutofillSuggestionsVisible = true;
mSuggestionsStrip.addView(view);
mCurrentInlineAutofillSuggestionsView = view;
setToolbarVisibility(false);
}
}

public boolean isInlineAutofillSuggestionsVisible(){
return isInlineAutofillSuggestionsVisible;
}

@Override
public void onVisibilityChanged(@NonNull final View view, final int visibility) {
super.onVisibilityChanged(view, visibility);
Expand All @@ -312,7 +318,7 @@ public void setMoreSuggestionsHeight(final int remainingHeight) {
}

@SuppressLint("ClickableViewAccessibility") // why would "null" need to call View#performClick?
private void clear() {
public void clear() {
mSuggestionsStrip.removeAllViews();
isInlineAutofillSuggestionsVisible = false;
if (DEBUG_SUGGESTIONS)
Expand Down Expand Up @@ -724,6 +730,7 @@ public void onClick(final View view) {
// make sure the latest clipboard entry
// is pasted since the content is hidden
onLongClickClipboardKey();
clear();
return;
}
}
Expand Down

0 comments on commit ba3f49b

Please sign in to comment.