From 045ee5a8533e8668ef9eae2a781ead47737cde2d Mon Sep 17 00:00:00 2001 From: Goofyz Leung Date: Wed, 17 Jan 2024 14:38:21 +0800 Subject: [PATCH] fix: reset to INIT state if `LiquidKeyboard` is reset --- .../com/osfans/trime/ime/symbol/LiquidKeyboard.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt b/app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt index b70cb65df5..0304913dff 100644 --- a/app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt +++ b/app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt @@ -76,6 +76,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard setPadding(space) } theme = Theme.get(UiUtil.isDarkMode(context)) + adapterType = AdapterType.INIT } // 及时更新layoutManager, 以防在旋转屏幕后打开液体键盘crash @@ -155,7 +156,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard } } - if (adapterType != AdapterType.SIMPLE) { + if (shouldChangeAdapter(AdapterType.SIMPLE)) { adapterType = AdapterType.SIMPLE keyboardView.apply { layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) @@ -255,7 +256,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard ) } - if (adapterType != AdapterType.DB) { + if (shouldChangeAdapter(AdapterType.DB)) { adapterType = AdapterType.DB keyboardView.apply { layoutManager = getOneColumnStaggeredGrid() @@ -289,7 +290,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard } private fun initCandidates() { - if (adapterType != AdapterType.CANDIDATE) { + if (shouldChangeAdapter(AdapterType.CANDIDATE)) { adapterType = AdapterType.CANDIDATE // 设置布局管理器 keyboardView.apply { @@ -344,7 +345,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard } } - if (adapterType != AdapterType.VAR_LENGTH) { + if (shouldChangeAdapter(AdapterType.VAR_LENGTH)) { adapterType = AdapterType.VAR_LENGTH // 设置布局管理器 keyboardView.apply { @@ -400,6 +401,10 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard ) } + private fun shouldChangeAdapter(type: AdapterType) = + adapterType != type || + adapterType == AdapterType.INIT + private enum class AdapterType { INIT, SIMPLE,