|
|
@@ -3,8 +3,9 @@ package com.nova.brain.glass.ui
|
|
|
import android.view.View
|
|
|
import android.widget.TextView
|
|
|
import com.nova.brain.glass.R
|
|
|
-import com.nova.brain.glass.helper.BgChatDrawable
|
|
|
import com.nova.brain.glass.databinding.ActivityChatBinding
|
|
|
+import com.nova.brain.glass.helper.BgChatDrawable
|
|
|
+import com.nova.brain.glass.helper.IntentRecognizeHelper
|
|
|
import com.nova.brain.glass.helper.OfflineCmdListener
|
|
|
import com.nova.brain.glass.helper.OfflineCmdServiceHelper
|
|
|
import com.nova.brain.glass.model.ChatItem
|
|
|
@@ -25,7 +26,7 @@ class ChatActivity : BaseListFormLayoutNormalActivity<ChatItem, ChatVM, Activity
|
|
|
runOnUiThread {
|
|
|
when (cmd) {
|
|
|
"退出", "返回", "退回" -> finish()
|
|
|
- "继续" -> viewModel.demoPostSse()
|
|
|
+ "继续" -> recognizeAndChat()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -40,24 +41,38 @@ class ChatActivity : BaseListFormLayoutNormalActivity<ChatItem, ChatVM, Activity
|
|
|
}
|
|
|
|
|
|
viewModel.loading.observe(this) { loading ->
|
|
|
- binding.pb.visibility = if (loading) View.VISIBLE else View.GONE
|
|
|
+ binding.pb.isIndeterminate = loading
|
|
|
}
|
|
|
|
|
|
- viewModel.demoPostSse()
|
|
|
+ val question = intent.getStringExtra("question") ?: ""
|
|
|
+ if (question.isNotEmpty()) {
|
|
|
+ viewModel.demoPostSse(question)
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ private fun recognizeAndChat() {
|
|
|
+ IntentRecognizeHelper.recognize(
|
|
|
+ context = this,
|
|
|
+ scence = "decision",
|
|
|
+ onSuccess = { action ->
|
|
|
+ if (action.name == "goToDecisionCenter") {
|
|
|
+ viewModel.demoPostSse(action.params.question)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
override fun adapter() = object : CommonPagedAdapter<ChatItem>(R.layout.item_chat) {
|
|
|
override fun convert(holder: ViewHolder, item: ChatItem, position: Int) {
|
|
|
- holder.setVisibility(R.id.line, position!=0)
|
|
|
+ holder.setVisibility(R.id.line, position != 0)
|
|
|
val chatItems = viewModel.chatItems
|
|
|
val liveItem = if (position < chatItems.size) chatItems[position] else item
|
|
|
holder.setText(R.id.title, liveItem.title)
|
|
|
val tv = holder.getView<TextView>(R.id.content)
|
|
|
markwon.setMarkdown(tv, liveItem.content)
|
|
|
- holder.setClickListener(R.id.root, {
|
|
|
- viewModel.demoPostSse()
|
|
|
- })
|
|
|
+ holder.setClickListener(R.id.root) {
|
|
|
+ recognizeAndChat()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -74,4 +89,9 @@ class ChatActivity : BaseListFormLayoutNormalActivity<ChatItem, ChatVM, Activity
|
|
|
super.onPause()
|
|
|
OfflineCmdServiceHelper.removeOnLineListener(listener)
|
|
|
}
|
|
|
+
|
|
|
+ override fun onDestroy() {
|
|
|
+ super.onDestroy()
|
|
|
+ IntentRecognizeHelper.dispose()
|
|
|
+ }
|
|
|
}
|