@@ -76,6 +76,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
76
76
setPadding(space)
77
77
}
78
78
theme = Theme .get(UiUtil .isDarkMode(context))
79
+ adapterType = AdapterType .INIT
79
80
}
80
81
81
82
// 及时更新layoutManager, 以防在旋转屏幕后打开液体键盘crash
@@ -155,7 +156,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
155
156
}
156
157
}
157
158
158
- if (adapterType != AdapterType .SIMPLE ) {
159
+ if (shouldChangeAdapter( AdapterType .SIMPLE ) ) {
159
160
adapterType = AdapterType .SIMPLE
160
161
keyboardView.apply {
161
162
layoutManager = LinearLayoutManager (context, LinearLayoutManager .VERTICAL , false )
@@ -255,7 +256,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
255
256
)
256
257
}
257
258
258
- if (adapterType != AdapterType .DB ) {
259
+ if (shouldChangeAdapter( AdapterType .DB ) ) {
259
260
adapterType = AdapterType .DB
260
261
keyboardView.apply {
261
262
layoutManager = getOneColumnStaggeredGrid()
@@ -289,7 +290,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
289
290
}
290
291
291
292
private fun initCandidates () {
292
- if (adapterType != AdapterType .CANDIDATE ) {
293
+ if (shouldChangeAdapter( AdapterType .CANDIDATE ) ) {
293
294
adapterType = AdapterType .CANDIDATE
294
295
// 设置布局管理器
295
296
keyboardView.apply {
@@ -344,7 +345,7 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
344
345
}
345
346
}
346
347
347
- if (adapterType != AdapterType .VAR_LENGTH ) {
348
+ if (shouldChangeAdapter( AdapterType .VAR_LENGTH ) ) {
348
349
adapterType = AdapterType .VAR_LENGTH
349
350
// 设置布局管理器
350
351
keyboardView.apply {
@@ -400,6 +401,10 @@ class LiquidKeyboard(private val context: Context) : ClipboardHelper.OnClipboard
400
401
)
401
402
}
402
403
404
+ private fun shouldChangeAdapter (type : AdapterType ) =
405
+ adapterType != type ||
406
+ adapterType == AdapterType .INIT
407
+
403
408
private enum class AdapterType {
404
409
INIT ,
405
410
SIMPLE ,
0 commit comments