Browse Source

Merge remote-tracking branch 'origin/v1.0.0' into v1.0.0

云天逵 7 months ago
parent
commit
a4bab012e8

+ 16 - 2
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/mvvm/viewmodel/KeyboardViewModel.kt

@@ -420,8 +420,22 @@ class KeyboardViewModel : ViewModel() {
         mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
             if (it.id.isNullOrBlank()) {
                 mKeyboardRepository.getKeyboardList(onSuccess = {
-                    val defaultItem = it.keyboardInfos[0]
-                    onSuccess.invoke(defaultItem)
+                    val infos = it.keyboardInfos
+                    // 数据为空
+                    if (infos.isEmpty()) {
+                        onFail.invoke(-1, "暂无数据")
+                    } else {
+                        // 默认使用系统键盘
+                        val systemKeyboard = infos.filter {
+                            KeyboardType.isSystem(it.type ?: "")
+                        }.toList()
+                        if (systemKeyboard.isNotEmpty()) {
+                            onSuccess.invoke(systemKeyboard.first())
+                        } else {
+                            // 连系统键盘都没有,则取第一个
+                            onSuccess.invoke(infos[0])
+                        }
+                    }
                 }, onFail)
             } else {
                 // 更新键盘