Skip to content

Commit 045ee5a

Browse files
committed
fix: reset to INIT state if LiquidKeyboard is reset
1 parent 64242bf commit 045ee5a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
7676
setPadding(space)
7777
}
7878
theme = Theme.get(UiUtil.isDarkMode(context))
79+
adapterType = AdapterType.INIT
7980
}
8081

8182
// 及时更新layoutManager, 以防在旋转屏幕后打开液体键盘crash
@@ -155,7 +156,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
155156
}
156157
}
157158

158-
if (adapterType != AdapterType.SIMPLE) {
159+
if (shouldChangeAdapter(AdapterType.SIMPLE)) {
159160
adapterType = AdapterType.SIMPLE
160161
keyboardView.apply {
161162
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
@@ -255,7 +256,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
255256
)
256257
}
257258

258-
if (adapterType != AdapterType.DB) {
259+
if (shouldChangeAdapter(AdapterType.DB)) {
259260
adapterType = AdapterType.DB
260261
keyboardView.apply {
261262
layoutManager = getOneColumnStaggeredGrid()
@@ -289,7 +290,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
289290
}
290291

291292
private fun initCandidates() {
292-
if (adapterType != AdapterType.CANDIDATE) {
293+
if (shouldChangeAdapter(AdapterType.CANDIDATE)) {
293294
adapterType = AdapterType.CANDIDATE
294295
// 设置布局管理器
295296
keyboardView.apply {
@@ -344,7 +345,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
344345
}
345346
}
346347

347-
if (adapterType != AdapterType.VAR_LENGTH) {
348+
if (shouldChangeAdapter(AdapterType.VAR_LENGTH)) {
348349
adapterType = AdapterType.VAR_LENGTH
349350
// 设置布局管理器
350351
keyboardView.apply {
@@ -400,6 +401,10 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
400401
)
401402
}
402403

404+
private fun shouldChangeAdapter(type: AdapterType) =
405+
adapterType != type ||
406+
adapterType == AdapterType.INIT
407+
403408
private enum class AdapterType {
404409
INIT,
405410
SIMPLE,

0 commit comments

Comments
 (0)