|
|
@@ -7,16 +7,16 @@ import android.view.View
|
|
|
import androidx.recyclerview.widget.GridLayoutManager
|
|
|
import androidx.recyclerview.widget.RecyclerView
|
|
|
import com.atmob.keyboard_android.R
|
|
|
-import com.atmob.keyboard_android.component.ComponentMediator
|
|
|
import com.atmob.keyboard_android.component.base.BaseUIComponent
|
|
|
-import com.atmob.keyboard_android.component.child.IAiChatComponent
|
|
|
import com.atmob.keyboard_android.component.child.IAiKeyboardComponent
|
|
|
import com.atmob.keyboard_android.component.item.AiKeyboardKeyViewBinder
|
|
|
-import com.atmob.keyboard_android.enums.Mode
|
|
|
+import com.atmob.keyboard_android.enums.HelpMode
|
|
|
+import com.atmob.keyboard_android.enums.Tab
|
|
|
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.AiKeyboardKeyModel
|
|
|
+import com.atmob.keyboard_android.util.KeyboardHolder
|
|
|
import com.atmob.keyboard_android.util.recyclerview.GridDivider
|
|
|
import com.atmob.keyboard_android.widget.indicator.TabPagerTitleView
|
|
|
import com.blankj.utilcode.util.ConvertUtils
|
|
|
@@ -50,12 +50,7 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
/**
|
|
|
* Tab列表
|
|
|
*/
|
|
|
- private lateinit var mTabList: List<String>
|
|
|
-
|
|
|
- /**
|
|
|
- * 当前选中的Tab的索引
|
|
|
- */
|
|
|
- private var mCurrentTabIndex = 0
|
|
|
+ private lateinit var mTabList: List<Tab>
|
|
|
|
|
|
override fun onInflateViewId(): Int {
|
|
|
return R.layout.component_ai_keyboard
|
|
|
@@ -75,6 +70,7 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
setupTabBar()
|
|
|
setupKeyList()
|
|
|
setupActionBtn()
|
|
|
+ setupViewModel()
|
|
|
setData()
|
|
|
}
|
|
|
|
|
|
@@ -86,12 +82,7 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
* 配置Tab栏
|
|
|
*/
|
|
|
private fun setupTabBar() {
|
|
|
- mTabList = listOf(
|
|
|
- "发起聊天",
|
|
|
- "邀约话术",
|
|
|
- "如何告白",
|
|
|
- "关系升温"
|
|
|
- )
|
|
|
+ mTabList = Tab.getAll()
|
|
|
|
|
|
// 配置指示器
|
|
|
vMagicIndicator.setNavigator(CommonNavigator(context).apply {
|
|
|
@@ -117,7 +108,7 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
}
|
|
|
}
|
|
|
// Tab文字
|
|
|
- titleView.setText(mTabList[index])
|
|
|
+ titleView.setText(mTabList[index].tabName)
|
|
|
// Tab未选中时的字体颜色
|
|
|
titleView.setTextColor(context.resources.getColor(R.color.text_color_secondary))
|
|
|
// Tab选中时的字体颜色
|
|
|
@@ -130,15 +121,16 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
// 点击Tab,切换页面
|
|
|
titleView.setOnClickListener(object : OnClickListener {
|
|
|
override fun onClick(v: View?) {
|
|
|
- if (mCurrentTabIndex == index) {
|
|
|
+ // Tab没有改变,不处理
|
|
|
+ val currentTab = KeyboardHolder.getKeyboardService()
|
|
|
+ ?.getKeyboardViewModel()?.tab?.value
|
|
|
+ if (Tab.getTabByIndex(index) == currentTab) {
|
|
|
return
|
|
|
}
|
|
|
- // 根据Tab类型,刷新内容
|
|
|
- val tab = mTabList[index]
|
|
|
- refreshContent(tab)
|
|
|
- // 切换Tab
|
|
|
- mCurrentTabIndex = index
|
|
|
- vMagicIndicator.onPageSelected(index)
|
|
|
+ // 更新Tab
|
|
|
+ val newTab = mTabList[index]
|
|
|
+ KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
|
|
|
+ ?.updateTab(newTab)
|
|
|
}
|
|
|
})
|
|
|
return titleView
|
|
|
@@ -172,11 +164,8 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
mKeyListAdapter = MultiTypeAdapter(mKeyListItems).apply {
|
|
|
register(AiKeyboardKeyModel::class.java, AiKeyboardKeyViewBinder {
|
|
|
// 点击键盘按键,打开AI生成内容面板
|
|
|
- val aiChatComponent =
|
|
|
- ComponentMediator.findComponent(IAiChatComponent::class.java)
|
|
|
- aiChatComponent?.show()
|
|
|
- // 隐藏键盘列表
|
|
|
- vKeyList.setGone()
|
|
|
+ KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
|
|
|
+ ?.updateAiChatPageShowing(true)
|
|
|
})
|
|
|
}
|
|
|
layoutManager = GridLayoutManager(context, spanCount)
|
|
|
@@ -199,10 +188,48 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 配置ViewModel
|
|
|
+ */
|
|
|
+ private fun setupViewModel() {
|
|
|
+ KeyboardHolder.getKeyboardService()?.run {
|
|
|
+ // 监听模式更新,切换键盘
|
|
|
+ getKeyboardViewModel().helpMode.observe(getLifecycleOwner()) { newMode ->
|
|
|
+ updateKeyboardByHelpMode(newMode)
|
|
|
+ }
|
|
|
+ // 监听Tab切换,更新键盘列表
|
|
|
+ getKeyboardViewModel().tab.observe(getLifecycleOwner()) { newTab ->
|
|
|
+ // 切换Tab
|
|
|
+ vMagicIndicator.onPageSelected(newTab.getIndex())
|
|
|
+ // 关闭Ai内容生成面板
|
|
|
+ getKeyboardViewModel().updateAiChatPageShowing(false)
|
|
|
+ // 根据Tab,重新加载数据
|
|
|
+ loadKeyListByTab(newTab)
|
|
|
+ }
|
|
|
+ // 监听Ai内容生成页,是否显示
|
|
|
+ getKeyboardViewModel().aiChatPageShowing.observe(getLifecycleOwner()) { isShowing ->
|
|
|
+ // 显示Ai内容生成页,隐藏键盘列表
|
|
|
+ if (isShowing) {
|
|
|
+ vKeyList.setGone()
|
|
|
+ } else {
|
|
|
+ // Ai生成页关闭,则显示键盘列表
|
|
|
+ vKeyList.setVisible()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 填充数据
|
|
|
*/
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
private fun setData() {
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据Tab类型,加载键盘列表
|
|
|
+ */
|
|
|
+ @SuppressLint("NotifyDataSetChanged")
|
|
|
+ private fun loadKeyListByTab(tab: Tab) {
|
|
|
val newList = mutableListOf<AiKeyboardKeyModel>().apply {
|
|
|
add(AiKeyboardKeyModel("暧昧推拉"))
|
|
|
add(AiKeyboardKeyModel("欲拒还迎"))
|
|
|
@@ -221,17 +248,11 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 刷新内容
|
|
|
- *
|
|
|
- * @param tab 选择了哪个Tab
|
|
|
+ * 根据帮助模式,切换键盘内容
|
|
|
*/
|
|
|
- private fun refreshContent(tab: String) {
|
|
|
- setData()
|
|
|
- }
|
|
|
-
|
|
|
- override fun updateKeyboardMode(mode: Mode) {
|
|
|
+ private fun updateKeyboardByHelpMode(helpMode: HelpMode) {
|
|
|
// 根据不同的模式,切换不同的键盘
|
|
|
- if (Mode.OPEN_REMARKS == mode) {
|
|
|
+ if (HelpMode.OPEN_REMARKS == helpMode) {
|
|
|
// 开场白,显示Tab布局,隐藏粘贴栏
|
|
|
vTabBarLayout.setVisible()
|
|
|
vPasteBarLayout.setGone()
|
|
|
@@ -241,17 +262,7 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
vPasteBarLayout.setVisible()
|
|
|
}
|
|
|
// 隐藏AI生成内容面板
|
|
|
- val aiChatComponent =
|
|
|
- ComponentMediator.findComponent(IAiChatComponent::class.java)
|
|
|
- aiChatComponent?.hide()
|
|
|
- // 显示键盘列表
|
|
|
- vKeyList.setVisible()
|
|
|
- }
|
|
|
-
|
|
|
- override fun reset() {
|
|
|
- vKeyList.setVisible()
|
|
|
- val aiChatComponent =
|
|
|
- ComponentMediator.findComponent(IAiChatComponent::class.java)
|
|
|
- aiChatComponent?.hide()
|
|
|
+ KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
|
|
|
+ ?.updateAiChatPageShowing(false)
|
|
|
}
|
|
|
}
|