Bladeren bron

[feat]键盘插件,修复,如果第一次打开app,键盘id为null,取键盘列表默认第一个

hezihao 8 maanden geleden
bovenliggende
commit
8ba8df1170

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

@@ -227,8 +227,7 @@ class KeyboardViewModel : ViewModel() {
      * 获取当前键盘信息
      */
     fun getCurrentKeyboardInfo() {
-        mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
-            // 更新键盘名称
+        getCurrentKeyboardInfoWithDefault(onSuccess = {
             _currentKeyboardInfo.value = KeyboardSelectModel(
                 id = it.id,
                 type = it.type,
@@ -250,7 +249,7 @@ class KeyboardViewModel : ViewModel() {
         onFail: (String) -> Unit
     ) {
         // 先获取当前键盘信息,得到键盘Id
-        mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
+        getCurrentKeyboardInfoWithDefault(onSuccess = {
             val keyboardId = it.id
             // 查询该键盘下的人设列表
             mKeyboardRepository.getCharacterList(keyboardId, onSuccess, onFail)
@@ -347,4 +346,34 @@ class KeyboardViewModel : ViewModel() {
             onSuccess.invoke()
         }, onFail)
     }
+
+    /**
+     * 获取键盘信息,如果没有,则返回第一个键盘信息
+     */
+    fun getCurrentKeyboardInfoWithDefault(
+        onSuccess: (model: KeyboardSelectModel) -> Unit,
+        onFail: (String) -> Unit
+    ) {
+        mKeyboardRepository.getCurrentKeyboardInfo(onSuccess = {
+            if (it.id.isNullOrBlank()) {
+                mKeyboardRepository.getKeyboardList(onSuccess = {
+                    val defaultItem = it.keyboardInfos[0]
+                    onSuccess.invoke(defaultItem)
+                }, onFail)
+            } else {
+                // 更新键盘
+                val item = KeyboardSelectModel(
+                    id = it.id,
+                    type = it.type,
+                    name = it.name,
+                    gender = it.gender,
+                    birthday = it.birthday,
+                    intimacy = it.intimacy,
+                    imageUrl = it.imageUrl,
+                    isSelect = it.isSelect
+                )
+                onSuccess.invoke(item)
+            }
+        }, onFail)
+    }
 }

+ 1 - 1
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/util/bridge/model/resp/CurrentKeyboardIdResp.kt

@@ -9,7 +9,7 @@ data class CurrentKeyboardIdResp(
     /**
      * 键盘Id
      */
-    val id: String,
+    val id: String? = null,
     /**
      * 键盘类型,system:系统键盘、custom:定制键盘
      */