|
|
@@ -6,18 +6,15 @@ import android.util.AttributeSet
|
|
|
import android.view.View
|
|
|
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.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.IAiKeyboardComponent
|
|
|
import com.atmob.keyboard_android.component.item.AiKeyboardKeyViewBinder
|
|
|
-import com.atmob.keyboard_android.component.root.IKeyboardRootComponent
|
|
|
import com.atmob.keyboard_android.constant.Constants
|
|
|
import com.atmob.keyboard_android.enums.HelpMode
|
|
|
import com.atmob.keyboard_android.enums.KeyboardGlobalType
|
|
|
-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
|
|
|
@@ -68,7 +65,7 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
/**
|
|
|
* Tab列表
|
|
|
*/
|
|
|
- private lateinit var mTabList: List<Tab>
|
|
|
+ private lateinit var mTabList: MutableList<String>
|
|
|
|
|
|
override fun onInflateViewId(): Int {
|
|
|
return R.layout.component_ai_keyboard
|
|
|
@@ -103,7 +100,8 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
* 配置Tab栏
|
|
|
*/
|
|
|
private fun setupTabBar() {
|
|
|
- mTabList = Tab.getAll()
|
|
|
+ // 初始化Tab列表
|
|
|
+ mTabList = mutableListOf()
|
|
|
|
|
|
// 配置指示器
|
|
|
vMagicIndicator.setNavigator(CommonNavigator(context).apply {
|
|
|
@@ -129,7 +127,7 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
}
|
|
|
}
|
|
|
// Tab文字
|
|
|
- titleView.setText(mTabList[index].tabName)
|
|
|
+ titleView.setText(mTabList[index])
|
|
|
// Tab未选中时的字体颜色
|
|
|
titleView.setTextColor(context.resources.getColor(R.color.text_color_secondary))
|
|
|
// Tab选中时的字体颜色
|
|
|
@@ -142,16 +140,10 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
// 点击Tab,切换页面
|
|
|
titleView.setOnClickListener(object : OnClickListener {
|
|
|
override fun onClick(v: View?) {
|
|
|
- // Tab没有改变,不处理
|
|
|
- val currentTab = KeyboardHolder.getKeyboardService()
|
|
|
- ?.getKeyboardViewModel()?.tab?.value
|
|
|
- if (Tab.getTabByIndex(index) == currentTab) {
|
|
|
- return
|
|
|
- }
|
|
|
// 更新Tab
|
|
|
val newTab = mTabList[index]
|
|
|
KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
|
|
|
- ?.updateTab(newTab)
|
|
|
+ ?.updateCurrentPrologueTab(newTab)
|
|
|
}
|
|
|
})
|
|
|
return titleView
|
|
|
@@ -275,6 +267,17 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
*/
|
|
|
private fun setupViewModel() {
|
|
|
KeyboardHolder.getKeyboardService()?.run {
|
|
|
+ // 监听开场白列表更新
|
|
|
+ getKeyboardViewModel().prologueList.observe(getLifecycleOwner()) { list ->
|
|
|
+ // 更新Tab列表
|
|
|
+ mTabList.clear()
|
|
|
+ mTabList.addAll(list.map {
|
|
|
+ it.title
|
|
|
+ }.toList())
|
|
|
+ // 刷新Tab栏
|
|
|
+ vMagicIndicator.navigator.notifyDataSetChanged()
|
|
|
+ LogUtil.d("开场白列表更新,刷新Tab栏...")
|
|
|
+ }
|
|
|
// 监听键盘类型切换
|
|
|
getKeyboardViewModel().keyboardGlobalType.observe(getLifecycleOwner()) { globalKeyboardType ->
|
|
|
if (KeyboardGlobalType.AI_KEYBOARD == globalKeyboardType) {
|
|
|
@@ -289,9 +292,9 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
updateKeyboardByHelpMode(newMode)
|
|
|
}
|
|
|
// 监听Tab切换,更新键盘列表
|
|
|
- getKeyboardViewModel().tab.observe(getLifecycleOwner()) { newTab ->
|
|
|
+ getKeyboardViewModel().currentPrologueTab.observe(getLifecycleOwner()) { newTab ->
|
|
|
// 切换Tab
|
|
|
- vMagicIndicator.onPageSelected(newTab.getIndex())
|
|
|
+ vMagicIndicator.onPageSelected(mTabList.indexOf(newTab))
|
|
|
// 关闭Ai内容生成面板
|
|
|
controlAiChatPageShowing(false)
|
|
|
// 根据Tab,重新加载数据
|
|
|
@@ -315,28 +318,63 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
*/
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
private fun setData() {
|
|
|
+ KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.getPrologueList(onFail = {
|
|
|
+ ToastUtils.showShort(it)
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 根据Tab类型,加载键盘列表
|
|
|
+ * 根据选择的帮助模式,加载按键列表
|
|
|
*/
|
|
|
@SuppressLint("NotifyDataSetChanged")
|
|
|
- private fun loadKeyListByTab(tab: Tab) {
|
|
|
- KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.getCharacterList(onSuccess = {
|
|
|
- val newList = (it.characterInfos ?: listOf()).map {
|
|
|
- AiKeyboardKeyModel(
|
|
|
- // 显示的文本 = 表情 + 名字
|
|
|
- text = "${it.emoji} ${it.name}",
|
|
|
- // 是否需要VIP
|
|
|
- isVip = it.isVip
|
|
|
- )
|
|
|
+ private fun loadKeyListByHelpMode(helpMode: HelpMode) {
|
|
|
+ // 开场白
|
|
|
+ if (HelpMode.OPEN_REMARKS == helpMode) {
|
|
|
+ val currentTab = KeyboardHolder.getKeyboardService()
|
|
|
+ ?.getKeyboardViewModel()?.currentPrologueTab?.value ?: ""
|
|
|
+ if (currentTab.isBlank()) {
|
|
|
+ return
|
|
|
}
|
|
|
- mKeyListItems.clear()
|
|
|
- mKeyListItems.addAll(newList)
|
|
|
- mKeyListAdapter.notifyDataSetChanged()
|
|
|
- }, onFail = {
|
|
|
- ToastUtils.showShort(it)
|
|
|
- })
|
|
|
+ loadKeyListByTab(currentTab)
|
|
|
+ } else {
|
|
|
+ // 其他类型
|
|
|
+ KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
|
|
|
+ ?.getCharacterList(onSuccess = {
|
|
|
+ val newList = (it.characterInfos ?: listOf()).map {
|
|
|
+ AiKeyboardKeyModel(
|
|
|
+ // 显示的文本 = 表情 + 名字
|
|
|
+ text = "${it.emoji} ${it.name}",
|
|
|
+ // 是否需要VIP
|
|
|
+ isVip = it.isVip
|
|
|
+ )
|
|
|
+ }
|
|
|
+ mKeyListItems.clear()
|
|
|
+ mKeyListItems.addAll(newList)
|
|
|
+ mKeyListAdapter.notifyDataSetChanged()
|
|
|
+ }, onFail = {
|
|
|
+ ToastUtils.showShort(it)
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据Tab,加载按键列表
|
|
|
+ */
|
|
|
+ @SuppressLint("NotifyDataSetChanged")
|
|
|
+ private fun loadKeyListByTab(tab: String) {
|
|
|
+ val list = KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()
|
|
|
+ ?.filterPrologueListByTab(tab) ?: listOf()
|
|
|
+ val newList = list.map {
|
|
|
+ AiKeyboardKeyModel(
|
|
|
+ // 显示的文本 = 名字
|
|
|
+ text = it.name,
|
|
|
+ // 是否需要VIP
|
|
|
+ isVip = false
|
|
|
+ )
|
|
|
+ }.toList()
|
|
|
+ mKeyListItems.clear()
|
|
|
+ mKeyListItems.addAll(newList)
|
|
|
+ mKeyListAdapter.notifyDataSetChanged()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -355,11 +393,8 @@ class AiKeyboardComponent @JvmOverloads constructor(
|
|
|
}
|
|
|
// 隐藏AI生成内容面板
|
|
|
controlAiChatPageShowing(false)
|
|
|
-
|
|
|
- // 重新加载人设列表
|
|
|
- KeyboardHolder.getKeyboardService()?.getKeyboardViewModel()?.tab?.value?.let {
|
|
|
- loadKeyListByTab(it)
|
|
|
- }
|
|
|
+ // 重新加载按键列表
|
|
|
+ loadKeyListByHelpMode(helpMode)
|
|
|
}
|
|
|
|
|
|
/**
|