Skip to content

Commit

Permalink
fix: reset to INIT state if LiquidKeyboard is reset
Browse files Browse the repository at this point in the history
  • Loading branch information
goofyz committed Jan 17, 2024
1 parent 64242bf commit 045ee5a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions app/src/main/java/com/osfans/trime/ime/symbol/LiquidKeyboard.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 045ee5a

Please sign in to comment.