|
|
@@ -149,10 +149,7 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
|
|
|
// 点击Tab,切换页面
|
|
|
titleView.setOnClickListener(object : OnClickListener {
|
|
|
override fun onClick(v: View?) {
|
|
|
- // 更新Tab
|
|
|
- val newTab = mTabList[index]
|
|
|
- KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
|
|
|
- ?.updateCurrentPrologueTab(newTab)
|
|
|
+ handleTabClick(index)
|
|
|
}
|
|
|
})
|
|
|
return titleView
|
|
|
@@ -276,7 +273,7 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
|
|
|
vMagicIndicator.navigator.notifyDataSetChanged()
|
|
|
LogUtil.d("开场白列表更新,刷新Tab栏 => ${tabList.size}个Tab")
|
|
|
// 默认选中第一个Tab
|
|
|
- vMagicIndicator.onPageSelected(0)
|
|
|
+ handleTabClick(0)
|
|
|
}
|
|
|
// 监听Tab切换,更新键盘列表
|
|
|
getKeyboardViewModel().currentPrologueTab.observe(getLifecycleOwner()) { newTab ->
|
|
|
@@ -322,6 +319,22 @@ class AiKeyboardProloguePanelComponent @JvmOverloads constructor(
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 处理Tab切换
|
|
|
+ */
|
|
|
+ private fun handleTabClick(index: Int) {
|
|
|
+ // 如果没有更新,不需要切换
|
|
|
+ val newTab = mTabList[index]
|
|
|
+ val currentTab = KeyboardHolder.getKeyboardService()
|
|
|
+ ?.getKeyboardViewModel()?.currentPrologueTab?.value
|
|
|
+ if (currentTab == newTab) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 更新Tab
|
|
|
+ KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
|
|
|
+ ?.updateCurrentPrologueTab(newTab)
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 根据Tab,加载按键列表
|
|
|
*/
|
|
|
@SuppressLint("NotifyDataSetChanged")
|