try delaying init of clipboard and emoji views

This commit is contained in:
Helium314 2023-12-31 18:27:25 +01:00
parent 00fe89ee93
commit 1df82d9b84
5 changed files with 18 additions and 8 deletions

View file

@ -7,13 +7,9 @@
package org.dslul.openboard.inputmethod.compat;
import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.widget.TabHost;
import org.dslul.openboard.inputmethod.latin.R;
import org.dslul.openboard.inputmethod.latin.utils.ResourceUtils;
/*
* Custom version of {@link TabHost} that triggers its {@link TabHost.OnTabChangeListener} when
* a tab is reselected. It is hacky but it avoids importing material widgets lib.

View file

@ -573,8 +573,9 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mEmojiTabStripView = mCurrentInputView.findViewById(R.id.emoji_tab_strip);
mClipboardStripView = mCurrentInputView.findViewById(R.id.clipboard_strip);
mSuggestionStripView = mCurrentInputView.findViewById(R.id.suggestion_strip_view);
mEmojiPalettesView.initialStart();
mClipboardHistoryView.initialStart();
// todo: try delaying, it's not needed at this point
// but when initializing right before showing, selected emoji category is not colored correctly
mEmojiPalettesView.initialize();
return mCurrentInputView;
}

View file

@ -40,6 +40,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
private val functionalKeyBackgroundId: Int
private val keyBackgroundId: Int
private val spacebarBackground: Drawable
private var initialized = false
private lateinit var clipboardRecyclerView: ClipboardHistoryRecyclerView
private lateinit var placeholderView: TextView
@ -79,7 +80,8 @@ class ClipboardHistoryView @JvmOverloads constructor(
}
@SuppressLint("ClickableViewAccessibility")
fun initialStart() { // needs to be delayed for access to ClipboardStrip, which is not a child of this view
private fun initialize() { // needs to be delayed for access to ClipboardStrip, which is not a child of this view
if (initialized) return
val colors = Settings.getInstance().current.mColors
clipboardAdapter = ClipboardAdapter(clipboardLayoutParams, this).apply {
itemBackgroundId = keyBackgroundId
@ -119,6 +121,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
colors.setBackground(it, ColorType.TOOL_BAR_KEY)
}
colors.setBackground(clipboardStrip, ColorType.BACKGROUND)
initialized = true
}
private fun setupAlphabetKey(key: TextView, label: String, params: KeyDrawParams) {
@ -166,6 +169,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
keyVisualAttr: KeyVisualAttributes?,
iconSet: KeyboardIconsSet
) {
initialize()
setupToolbarKeys()
historyManager.prepareClipboardHistory()
historyManager.setHistoryChangeListener(this)
@ -194,6 +198,7 @@ class ClipboardHistoryView @JvmOverloads constructor(
}
fun stopClipboardHistory() {
if (!initialized) return
clipboardRecyclerView.adapter = null
clipboardHistoryManager?.setHistoryChangeListener(null)
clipboardHistoryManager = null

View file

@ -134,7 +134,9 @@ final class EmojiCategory {
mCategoryNameToIdMap.put(sCategoryName[i], i);
mCategoryTabIconId[i] = emojiPaletteViewAttr.getResourceId(sCategoryTabIconAttr[i], 0);
}
}
public void initialize() {
int defaultCategoryId = EmojiCategory.ID_SMILEYS_EMOTION;
addShownCategoryId(EmojiCategory.ID_RECENTS);
addShownCategoryId(EmojiCategory.ID_SMILEYS_EMOTION);

View file

@ -63,6 +63,7 @@ import static org.dslul.openboard.inputmethod.latin.common.Constants.NOT_A_COORD
public final class EmojiPalettesView extends LinearLayout
implements OnTabChangeListener, View.OnClickListener, View.OnTouchListener,
OnKeyEventListener {
private boolean initialized = false;
private final int mFunctionalKeyBackgroundId;
private final Drawable mSpacebarBackground;
private final boolean mCategoryIndicatorEnabled;
@ -155,7 +156,9 @@ public final class EmojiPalettesView extends LinearLayout
host.addTab(tspec);
}
public void initialStart() { // needs to be delayed for access to EmojiTabStrip, which is not a child of this view
public void initialize() { // needs to be delayed for access to EmojiTabStrip, which is not a child of this view
if (initialized) return;
mEmojiCategory.initialize();
mTabHost = KeyboardSwitcher.getInstance().getEmojiTabStrip().findViewById(R.id.emoji_category_tabhost);
mTabHost.setup();
for (final EmojiCategory.CategoryProperties properties : mEmojiCategory.getShownCategories()) {
@ -250,6 +253,7 @@ public final class EmojiPalettesView extends LinearLayout
mColors.setBackground(mDeleteKey, ColorType.FUNCTIONAL_KEY_BACKGROUND);
mColors.setBackground(mSpacebar, ColorType.SPACE_BAR_BACKGROUND);
mEmojiCategoryPageIndicatorView.setColors(mColors.get(ColorType.EMOJI_CATEGORY_SELECTED), mColors.get(ColorType.EMOJI_CATEGORY_BACKGROUND));
initialized = true;
}
@Override
@ -361,6 +365,7 @@ public final class EmojiPalettesView extends LinearLayout
public void startEmojiPalettes(final String switchToAlphaLabel,
final KeyVisualAttributes keyVisualAttr,
final KeyboardIconsSet iconSet) {
initialize();
final int deleteIconResId = iconSet.getIconResourceId(KeyboardIconsSet.NAME_DELETE_KEY);
if (deleteIconResId != 0) {
mDeleteKey.setImageResource(deleteIconResId);
@ -377,6 +382,7 @@ public final class EmojiPalettesView extends LinearLayout
}
public void stopEmojiPalettes() {
if (!initialized) return;
mEmojiPalettesAdapter.releaseCurrentKey(true);
mEmojiPalettesAdapter.flushPendingRecentKeys();
mEmojiRecyclerView.setAdapter(null);