Sfoglia il codice sorgente

[feat]键盘插件,Ai生成列表,教你说和开场白,分开2个组件,避免互相影响

hezihao 7 mesi fa
parent
commit
542f5a1a71

+ 1 - 1
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/IAiChatComponent.kt

@@ -5,5 +5,5 @@ import com.atmob.keyboard_android.component.base.IUIComponent
 /**
  * Ai生成组件接口
  */
-interface IAiChatComponent : IUIComponent{
+interface IAiChatComponent : IUIComponent {
 }

+ 9 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/ai/IPrologueAiChatComponent.kt

@@ -0,0 +1,9 @@
+package com.atmob.keyboard_android.component.child.ai
+
+import com.atmob.keyboard_android.component.child.IAiChatComponent
+
+/**
+ * 开场白-Ai生成内容页-接口
+ */
+interface IPrologueAiChatComponent : IAiChatComponent {
+}

+ 9 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/ai/ISuperSpeakAiChatComponent.kt

@@ -0,0 +1,9 @@
+package com.atmob.keyboard_android.component.child.ai
+
+import com.atmob.keyboard_android.component.child.IAiChatComponent
+
+/**
+ * 超会说(教你说)-Ai生成内容页-接口
+ */
+interface ISuperSpeakAiChatComponent : IAiChatComponent {
+}

+ 7 - 37
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/AiChatComponent.kt

@@ -15,8 +15,6 @@ import com.atmob.keyboard_android.component.item.AiGenerateLoadingViewBinder
 import com.atmob.keyboard_android.component.item.EmptyPlaceholderViewBinder
 import com.atmob.keyboard_android.constant.Constants
 import com.atmob.keyboard_android.ext.click
-import com.atmob.keyboard_android.ext.setGone
-import com.atmob.keyboard_android.ext.setVisible
 import com.atmob.keyboard_android.model.AiChatModel
 import com.atmob.keyboard_android.model.AiGenerateLoadingModel
 import com.atmob.keyboard_android.model.EmptyPlaceholderModel
@@ -28,13 +26,13 @@ import me.drakeet.multitype.Items
 import me.drakeet.multitype.MultiTypeAdapter
 
 /**
- * Ai对话组件
+ * Ai对话组件,基类,子类有教你说和开场白
  */
-class AiChatComponent @JvmOverloads constructor(
+abstract class AiChatComponent<T : IAiChatComponent> @JvmOverloads constructor(
     context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
-) : BaseUIComponent<IAiChatComponent>(context, attrs, defStyleAttr), IAiChatComponent {
+) : BaseUIComponent<T>(context, attrs, defStyleAttr) {
     private lateinit var vBackBtn: View
-    private lateinit var vReGenerateBtn: View
+    protected lateinit var vReGenerateBtn: View
     private lateinit var vChatList: RecyclerView
 
     private lateinit var mListItems: Items
@@ -99,10 +97,6 @@ class AiChatComponent @JvmOverloads constructor(
         setupViewModel()
     }
 
-    override fun getComponentInterfaceClazz(): Class<IAiChatComponent> {
-        return IAiChatComponent::class.java
-    }
-
     override fun getComponentAnimator(): Class<*> {
         return if (Constants.COMPONENT_ANIMATOR_ENABLE) {
             TransitionAnimator::class.java
@@ -112,39 +106,15 @@ class AiChatComponent @JvmOverloads constructor(
     }
 
     /**
-     * 配置ViewModel
+     * 配置ViewModel,子类重写
      */
-    private fun setupViewModel() {
-        // 监听Ai生成列表的更新
-        KeyboardHolder.getKeyboardService()?.run {
-            getKeyboardViewModel().aiChatListResult.observe(getLifecycleOwner()) {
-                if (it.isEmpty()) {
-                    vReGenerateBtn.setGone()
-                } else {
-                    vReGenerateBtn.setVisible()
-                }
-                loadAiList(it)
-            }
-        }
-    }
-
-    override fun onComponentShow() {
-        super.onComponentShow()
-        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
-            ?.updateAiChatPageShowing(true)
-    }
-
-    override fun onComponentHide() {
-        super.onComponentHide()
-        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
-            ?.updateAiChatPageShowing(false)
-    }
+    protected abstract fun setupViewModel()
 
     /**
      * 加载Ai内容列表
      */
     @SuppressLint("NotifyDataSetChanged")
-    private fun loadAiList(list: List<String>) {
+    protected fun loadAiList(list: List<String>) {
         mListItems.clear()
         mListItems.apply {
             // 空占位条目

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

@@ -11,6 +11,7 @@ import com.atmob.keyboard_android.component.base.FakeComponent
 import com.atmob.keyboard_android.component.base.RouteComponent
 import com.atmob.keyboard_android.component.child.IAiChatComponent
 import com.atmob.keyboard_android.component.child.IAiKeyboardCommonPanelComponent
+import com.atmob.keyboard_android.component.child.impl.ai.SuperSpeakAiChatComponent
 import com.atmob.keyboard_android.component.item.AddCharacterViewBinder
 import com.atmob.keyboard_android.component.item.AiKeyboardKeyViewBinder
 import com.atmob.keyboard_android.constant.Constants
@@ -51,7 +52,7 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
     private lateinit var vClearBtn: View
     private lateinit var vSendBtn: View
 
-    private lateinit var vCommonAiChatComponent: AiChatComponent
+    private lateinit var vSuperSpeakAiChatComponent: SuperSpeakAiChatComponent
 
     private lateinit var mKeyListItems: Items
     private lateinit var mKeyListAdapter: MultiTypeAdapter
@@ -74,7 +75,7 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
         vDeleteBtn = view.findViewById(R.id.delete_btn)
         vClearBtn = view.findViewById(R.id.clear_btn)
         vSendBtn = view.findViewById(R.id.send_btn)
-        vCommonAiChatComponent = view.findViewById(R.id.common_ai_chat_component)
+        vSuperSpeakAiChatComponent = view.findViewById(R.id.super_speak_ai_chat_component)
     }
 
     override fun bindView(view: View) {
@@ -201,8 +202,8 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
                 // 重新加载按键列表
                 loadKeyListByHelpMode(newMode)
             }
-            // 监听Ai内容生成页,是否显示
-            getKeyboardViewModel().aiChatPageShowing.observe(getLifecycleOwner()) { isShowing ->
+            // 监听教你说的Ai内容生成页,是否显示
+            getKeyboardViewModel().superSpeakAiChatPageShowing.observe(getLifecycleOwner()) { isShowing ->
                 // 显示Ai内容生成页,隐藏键盘列表
                 if (isShowing) {
                     vKeyList.setGone()
@@ -230,7 +231,7 @@ class AiKeyboardCommonPanelComponent @JvmOverloads constructor(
     @SuppressLint("NotifyDataSetChanged")
     private fun setData() {
         // 监听重新生成按钮点击
-        vCommonAiChatComponent.setOnActionClickListener(object :
+        vSuperSpeakAiChatComponent.setOnActionClickListener(object :
             AiChatComponent.OnActionClickListener {
             override fun onReGenerateClick() {
                 mCurrentClickItem?.let {

+ 4 - 3
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/AiKeyboardProloguePanelComponent.kt

@@ -11,6 +11,7 @@ import com.atmob.keyboard_android.component.base.FakeComponent
 import com.atmob.keyboard_android.component.base.RouteComponent
 import com.atmob.keyboard_android.component.child.IAiChatComponent
 import com.atmob.keyboard_android.component.child.IAiKeyboardProloguePanelComponent
+import com.atmob.keyboard_android.component.child.impl.ai.PrologueAiChatComponent
 import com.atmob.keyboard_android.component.item.AiKeyboardKeyViewBinder
 import com.atmob.keyboard_android.constant.Constants
 import com.atmob.keyboard_android.enums.HelpMode
@@ -56,7 +57,7 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
     private lateinit var vClearBtn: View
     private lateinit var vSendBtn: View
 
-    private lateinit var vPrologueAiChatComponent: AiChatComponent
+    private lateinit var vPrologueAiChatComponent: PrologueAiChatComponent
 
     private lateinit var mKeyListItems: Items
     private lateinit var mKeyListAdapter: MultiTypeAdapter
@@ -278,8 +279,8 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
                 // 根据Tab,重新加载数据
                 loadKeyListByTab(newTab)
             }
-            // 监听Ai内容生成页,是否显示
-            getKeyboardViewModel().aiChatPageShowing.observe(getLifecycleOwner()) { isShowing ->
+            // 监听开场白的Ai内容生成页,是否显示
+            getKeyboardViewModel().prologueAiChatPageShowing.observe(getLifecycleOwner()) { isShowing ->
                 // 显示Ai内容生成页,隐藏键盘列表
                 if (isShowing) {
                     vKeyList.setGone()

+ 47 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/ai/PrologueAiChatComponent.kt

@@ -0,0 +1,47 @@
+package com.atmob.keyboard_android.component.child.impl.ai
+
+import android.content.Context
+import android.util.AttributeSet
+import com.atmob.keyboard_android.component.child.ai.IPrologueAiChatComponent
+import com.atmob.keyboard_android.component.child.impl.AiChatComponent
+import com.atmob.keyboard_android.ext.setGone
+import com.atmob.keyboard_android.ext.setVisible
+import com.atmob.keyboard_android.util.KeyboardHolder
+
+/**
+ * 开场白-Ai生成内容页-实现类
+ */
+class PrologueAiChatComponent @JvmOverloads constructor(
+    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+) : AiChatComponent<IPrologueAiChatComponent>(context, attrs, defStyleAttr),
+    IPrologueAiChatComponent {
+    override fun getComponentInterfaceClazz(): Class<IPrologueAiChatComponent> {
+        return IPrologueAiChatComponent::class.java
+    }
+
+    override fun setupViewModel() {
+        // 监听Ai生成列表的更新
+        KeyboardHolder.getKeyboardService()?.run {
+            getKeyboardViewModel().prologueChatListResult.observe(getLifecycleOwner()) {
+                if (it.isEmpty()) {
+                    vReGenerateBtn.setGone()
+                } else {
+                    vReGenerateBtn.setVisible()
+                }
+                loadAiList(it)
+            }
+        }
+    }
+
+    override fun onComponentShow() {
+        super.onComponentShow()
+        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
+            ?.updatePrologueAiChatPageShowing(true)
+    }
+
+    override fun onComponentHide() {
+        super.onComponentHide()
+        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
+            ?.updatePrologueAiChatPageShowing(false)
+    }
+}

+ 47 - 0
plugins/keyboard_android/android/src/main/kotlin/com/atmob/keyboard_android/component/child/impl/ai/SuperSpeakAiChatComponent.kt

@@ -0,0 +1,47 @@
+package com.atmob.keyboard_android.component.child.impl.ai
+
+import android.content.Context
+import android.util.AttributeSet
+import com.atmob.keyboard_android.component.child.ai.ISuperSpeakAiChatComponent
+import com.atmob.keyboard_android.component.child.impl.AiChatComponent
+import com.atmob.keyboard_android.ext.setGone
+import com.atmob.keyboard_android.ext.setVisible
+import com.atmob.keyboard_android.util.KeyboardHolder
+
+/**
+ * 超会说(教你说)-Ai生成内容页-实现类
+ */
+class SuperSpeakAiChatComponent @JvmOverloads constructor(
+    context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
+) : AiChatComponent<ISuperSpeakAiChatComponent>(context, attrs, defStyleAttr),
+    ISuperSpeakAiChatComponent {
+    override fun getComponentInterfaceClazz(): Class<ISuperSpeakAiChatComponent> {
+        return ISuperSpeakAiChatComponent::class.java
+    }
+
+    override fun setupViewModel() {
+        // 监听Ai生成列表的更新
+        KeyboardHolder.getKeyboardService()?.run {
+            getKeyboardViewModel().superSpeakChatListResult.observe(getLifecycleOwner()) {
+                if (it.isEmpty()) {
+                    vReGenerateBtn.setGone()
+                } else {
+                    vReGenerateBtn.setVisible()
+                }
+                loadAiList(it)
+            }
+        }
+    }
+
+    override fun onComponentShow() {
+        super.onComponentShow()
+        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
+            ?.updateSuperSpeakAiChatPageShowing(true)
+    }
+
+    override fun onComponentHide() {
+        super.onComponentHide()
+        KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
+            ?.updateSuperSpeakAiChatPageShowing(false)
+    }
+}

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

@@ -50,10 +50,16 @@ class KeyboardViewModel : ViewModel() {
     val keyboardSelectPageShowing: LiveData<Boolean> = _keyboardSelectPageShowing
 
     /**
-     * Ai生成内容页,是否显示
+     * 超会说-Ai生成内容页,是否显示
      */
-    private val _aiChatPageShowing = MutableLiveData(false)
-    val aiChatPageShowing: LiveData<Boolean> = _aiChatPageShowing
+    private val _superSpeakAiChatPageShowing = MutableLiveData(false)
+    val superSpeakAiChatPageShowing: LiveData<Boolean> = _superSpeakAiChatPageShowing
+
+    /**
+     * 开场白-Ai生成内容页,是否显示
+     */
+    private val _prologueAiChatPageShowing = MutableLiveData(false)
+    val prologueAiChatPageShowing: LiveData<Boolean> = _prologueAiChatPageShowing
 
     /**
      * 帮助模式,帮聊、教你说、开场白等
@@ -93,10 +99,16 @@ class KeyboardViewModel : ViewModel() {
     val chatSuperReplyResult: LiveData<String> = _chatSuperReplyResult
 
     /**
-     * AI聊天-超会说或开场白(教你说)结果
+     * AI聊天-超会说(教你说)结果
+     */
+    private val _superSpeakChatListResult = MutableLiveData<List<String>>()
+    val superSpeakChatListResult: LiveData<List<String>> = _superSpeakChatListResult
+
+    /**
+     * AI聊天-开场白结果
      */
-    private val _aiChatListResult = MutableLiveData<List<String>>()
-    val aiChatListResult: LiveData<List<String>> = _aiChatListResult
+    private val _prologueChatListResult = MutableLiveData<List<String>>()
+    val prologueChatListResult: LiveData<List<String>> = _prologueChatListResult
 
     /**
      * 用户的剪切板数据
@@ -141,10 +153,17 @@ class KeyboardViewModel : ViewModel() {
     }
 
     /**
-     * 更新,Ai生成内容页,是否显示
+     * 更新,超会说-Ai生成内容页,是否显示
+     */
+    fun updateSuperSpeakAiChatPageShowing(isShowing: Boolean) {
+        _superSpeakAiChatPageShowing.value = isShowing
+    }
+
+    /**
+     * 更新,开场白-Ai生成内容页,是否显示
      */
-    fun updateAiChatPageShowing(isShowing: Boolean) {
-        _aiChatPageShowing.value = isShowing
+    fun updatePrologueAiChatPageShowing(isShowing: Boolean) {
+        _prologueAiChatPageShowing.value = isShowing
     }
 
     /**
@@ -315,7 +334,7 @@ class KeyboardViewModel : ViewModel() {
         onSuccess: () -> Unit,
         onFail: (String) -> Unit
     ) {
-        _aiChatListResult.value = listOf<String>()
+        _superSpeakChatListResult.value = listOf<String>()
         val req = SuperSpeakReq(
             // 键盘Id
             keyboardId = _currentKeyboardInfo.value?.id ?: "",
@@ -326,7 +345,7 @@ class KeyboardViewModel : ViewModel() {
         )
         mKeyboardRepository.chatSuperSpeak(req, onSuccess = {
             // 有多条数据,需要跳转列表页面中显示
-            _aiChatListResult.value = it.list
+            _superSpeakChatListResult.value = it.list
             onSuccess.invoke()
         }, onFail)
     }
@@ -339,10 +358,10 @@ class KeyboardViewModel : ViewModel() {
         onSuccess: () -> Unit,
         onFail: (String) -> Unit
     ) {
-        _aiChatListResult.value = listOf<String>()
+        _prologueChatListResult.value = listOf<String>()
         mKeyboardRepository.chatPrologue(name, onSuccess = {
             // 有多条数据,需要跳转列表页面中显示
-            _aiChatListResult.value = it.list
+            _prologueChatListResult.value = it.list
             onSuccess.invoke()
         }, onFail)
     }

+ 3 - 3
plugins/keyboard_android/android/src/main/res/layout/component_ai_keyboard_common_panel.xml

@@ -64,12 +64,12 @@
                         tools:layout_height="150dp" />
                 </com.atmob.keyboard_android.component.base.FakeComponent>
 
-                <com.atmob.keyboard_android.component.child.impl.AiChatComponent
-                    android:id="@+id/common_ai_chat_component"
+                <com.atmob.keyboard_android.component.child.impl.ai.SuperSpeakAiChatComponent
+                    android:id="@+id/super_speak_ai_chat_component"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:visibility="gone"
-                    app:uic_component_name="common.AiChatComponent"
+                    app:uic_component_name="superSpeak.AiChatComponent"
                     tools:visibility="visible" />
             </com.atmob.keyboard_android.component.base.RouteComponent>
 

+ 1 - 1
plugins/keyboard_android/android/src/main/res/layout/component_ai_keyboard_prologue_panel.xml

@@ -59,7 +59,7 @@
                         tools:layout_height="150dp" />
                 </com.atmob.keyboard_android.component.base.FakeComponent>
 
-                <com.atmob.keyboard_android.component.child.impl.AiChatComponent
+                <com.atmob.keyboard_android.component.child.impl.ai.PrologueAiChatComponent
                     android:id="@+id/prologue_ai_chat_component"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"