Selaa lähdekoodia

[feat]键盘插件,选择键盘后,刷新人设列表

hezihao 7 kuukautta sitten
vanhempi
commit
a456e81bd7

+ 31 - 28
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/AiKeyboardCommonPanelComponent.kt

@@ -200,7 +200,14 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
                 // 隐藏AI生成内容面板
                 controlAiChatPageShowing(false)
                 // 重新加载按键列表
-                loadKeyListByHelpMode(newMode)
+                if (HelpMode.OPEN_REMARKS != newMode) {
+                    // 非开场白类型
+                    loadKeyList()
+                }
+            }
+            // 监听键盘选择切换
+            getKeyboardViewModel().currentKeyboardInfo.observe(getLifecycleOwner()) { newKeyboard ->
+                loadKeyList()
             }
             // 监听教你说的Ai内容生成页,是否显示
             getKeyboardViewModel().superSpeakAiChatPageShowing.observe(getLifecycleOwner()) { isShowing ->
@@ -243,34 +250,30 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
     }
 
     /**
-     * 根据选择的帮助模式,加载按键列表
+     * 加载按键列表
      */
-    @SuppressLint("NotifyDataSetChanged")
-    private fun loadKeyListByHelpMode(helpMode: HelpMode) {
-        // 非开场白类型
-        if (HelpMode.OPEN_REMARKS != helpMode) {
-            KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
-                ?.getCharacterList(onSuccess = {
-                    val newList = (it.characterInfos ?: listOf()).map {
-                        AiKeyboardKeyModel(
-                            // 显示的文本 = 表情 + 名字
-                            text = "${it.emoji} ${it.name}",
-                            // 拓展字段,存储人设Id
-                            payload = it.id,
-                            // 是否需要VIP
-                            isVip = it.isVip
-                        )
-                    }
-                    mKeyListItems.clear()
-                    // 添加按键列表
-                    mKeyListItems.addAll(newList)
-                    // 添加人设按钮
-                    mKeyListItems.add(AddCharacterModel())
-                    mKeyListAdapter.notifyDataSetChanged()
-                }, onFail = {
-                    ToastUtils.showShort(it)
-                })
-        }
+    private fun loadKeyList() {
+        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
+            ?.getCharacterList(onSuccess = {
+                val newList = (it.characterInfos ?: listOf()).map {
+                    AiKeyboardKeyModel(
+                        // 显示的文本 = 表情 + 名字
+                        text = "${it.emoji} ${it.name}",
+                        // 拓展字段,存储人设Id
+                        payload = it.id,
+                        // 是否需要VIP
+                        isVip = it.isVip
+                    )
+                }
+                mKeyListItems.clear()
+                // 添加按键列表
+                mKeyListItems.addAll(newList)
+                // 添加人设按钮
+                mKeyListItems.add(AddCharacterModel())
+                mKeyListAdapter.notifyDataSetChanged()
+            }, onFail = {
+                ToastUtils.showShort(it)
+            })
     }
 
     /**