diff --git a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/msgbox/MsgBoxConfig.kt b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/msgbox/MsgBoxConfig.kt index e92e474d28..241ad69f8c 100644 --- a/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/msgbox/MsgBoxConfig.kt +++ b/core/function-impl/mogo-core-function-datacenter/src/main/java/com/mogo/eagle/core/function/msgbox/MsgBoxConfig.kt @@ -37,6 +37,9 @@ class MsgBoxConfig { //录包信息缓存列表 @JvmField var recordBagList: ArrayList = ArrayList() + //播放小智语音消息时的未播放消息缓存列表 + @JvmField + var unPlayList: ArrayList = ArrayList() } } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/PassengerMsgBoxBubbleView.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/PassengerMsgBoxBubbleView.kt index 5cbc439866..5f0323fd51 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/PassengerMsgBoxBubbleView.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/PassengerMsgBoxBubbleView.kt @@ -11,6 +11,8 @@ import com.mogo.eagle.core.data.msgbox.MsgBoxBean import com.mogo.eagle.core.data.msgbox.MsgBoxCountDownBean import com.mogo.eagle.core.data.msgbox.MsgBoxType import com.mogo.eagle.core.data.msgbox.MsgCategory +import com.mogo.eagle.core.data.msgbox.VoiceMsg +import com.mogo.eagle.core.function.api.datacenter.msgbox.IMsgBoxEventListener import com.mogo.eagle.core.function.api.datacenter.msgbox.IMsgBoxListener import com.mogo.eagle.core.function.api.order.IOrderListener import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxEventListenerManager @@ -31,13 +33,17 @@ class PassengerMsgBoxBubbleView @JvmOverloads constructor( context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0 -) : ConstraintLayout(context, attrs, defStyleAttr), IMsgBoxListener, IOrderListener { +) : ConstraintLayout(context, attrs, defStyleAttr), IMsgBoxListener, IOrderListener, + IMsgBoxEventListener { private val TAG = "PassengerMsgBoxBubbleView" private val dataList :ArrayList = ArrayList() private var passengerMsgBoxBubbleAdapter: PassengerMsgBoxBubbleAdapter ?= null private var isShowData = true private var isShowSummary = false //是否展示汇总消息 + private var isCacheMsg = false //是否缓存消息 + private var voiceIsShowing = false //小智语音消息是否正在展示 + private var voiceMsgBean: MsgBoxCountDownBean ?= null //小智语音消息封装 init { LayoutInflater.from(context).inflate(R.layout.layout_passenger_msg_box_bubble, this, true) @@ -65,20 +71,95 @@ class PassengerMsgBoxBubbleView @JvmOverloads constructor( if(category == MsgCategory.NOTICE){ if(msgBoxList.type == MsgBoxType.NOTICE || msgBoxList.type == MsgBoxType.V2X || msgBoxList.type == MsgBoxType.OBU){ - if(msgBoxList.sourceType == DataSourceType.SUMMARY){ - //在一次订单中汇总消息只展示一次 - if(isShowSummary){ - operationalData(msgBoxList) - isShowSummary = false - } + if(isCacheMsg){ + //将消息缓存到未播放列表等待小智语音播放完成后取出播放 + MsgBoxConfig.unPlayList.add(msgBoxList) }else{ - operationalData(msgBoxList) + //实时播放消息 + notifyMsg(msgBoxList) } } } + if(category == MsgCategory.VOICE_INFO){ + if(msgBoxList.type == MsgBoxType.VOICE){ + executeVoiceInfo(msgBoxList) + } + } },UiThreadHandler.MODE.QUEUE) } + /** + * 小智语音消息执行 + */ + private fun executeVoiceInfo(msgBoxList: MsgBoxBean){ + val voiceMsg = msgBoxList.bean as VoiceMsg + if(voiceMsg.isWakeUp && !voiceMsg.isWakeUpEnd){ + //有其他消息时,将其他消息缓存进未播放列表 + voiceIsShowing = true + isCacheMsg = true + //开始展示消息 + if(voiceMsgBean == null){ + voiceMsgBean = MsgBoxCountDownBean(msgBoxList) + dataList.add(voiceMsgBean!!) + }else{ + dataList.remove(voiceMsgBean) + voiceMsgBean!!.msgBoxBean = msgBoxList + dataList.add(voiceMsgBean!!) + } + passengerMsgBoxBubbleAdapter?.setData(dataList) + } + if(!voiceMsg.isWakeUp && voiceMsg.isWakeUpEnd){ + //关闭消息展示 + dataList.remove(voiceMsgBean) + passengerMsgBoxBubbleAdapter?.setData(dataList) + //如果未播放列表中有未播放的消息则陆续展示消息,新来的消息继续放到未播放列表中, + //如果未播放消息列表为空,则立刻改变状态,即使播放新消息 + voiceIsShowing = false + handleCachedMsg() + } + + } + + /** + * 播放缓存消息 + */ + private fun handleCachedMsg(){ + if(MsgBoxConfig.unPlayList.isEmpty()){ + isCacheMsg = false + }else{ + //开始播放缓存未播放消息 + val iterator = MsgBoxConfig.unPlayList.iterator() + while(iterator.hasNext()){ + val msg = iterator.next() + if(passengerMsgBoxBubbleAdapter!!.getDataSize()<3){ + notifyMsg(msg) + iterator.remove() + } + } + if(MsgBoxConfig.unPlayList.isEmpty()){ + isCacheMsg = false + } + } + } + + /** + * 通知新消息展示 + */ + private fun notifyMsg(msgBoxList: MsgBoxBean){ + if(msgBoxList.sourceType == DataSourceType.SUMMARY){ + //在一次订单中汇总消息只展示一次 + if(isShowSummary){ + operationalData(msgBoxList) + isShowSummary = false + } + }else{ + operationalData(msgBoxList) + } + } + + /** + * 处理播放消息 + */ private fun operationalData(msgBoxList: MsgBoxBean){ MsgBoxConfig.noticeList.add(msgBoxList) if(isShowData){ @@ -93,16 +174,28 @@ class PassengerMsgBoxBubbleView @JvmOverloads constructor( super.onAttachedToWindow() CallerMsgBoxListenerManager.addListener(TAG,this) CallerOrderListenerManager.addListener(TAG,this) + CallerMsgBoxEventListenerManager.addListener(TAG,this) } override fun onDetachedFromWindow() { super.onDetachedFromWindow() CallerMsgBoxListenerManager.removeListener(TAG) CallerOrderListenerManager.removeListener(TAG) + CallerMsgBoxEventListenerManager.removeListener(TAG) } override fun onUpdateOrderStatus(inOrder: Boolean) { isShowSummary = inOrder } + /** + * 播放缓存消息 + */ + override fun onHandleCachedMsg() { + if(voiceIsShowing){ + return + } + handleCachedMsg() + } + } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/adapter/PassengerMsgBoxBubbleAdapter.kt b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/adapter/PassengerMsgBoxBubbleAdapter.kt index 7cf0289ddf..f2cd1a7db6 100644 --- a/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/adapter/PassengerMsgBoxBubbleAdapter.kt +++ b/core/function-impl/mogo-core-function-hmi/src/main/java/com/mogo/eagle/core/function/hmi/ui/msgbox/adapter/PassengerMsgBoxBubbleAdapter.kt @@ -1,7 +1,9 @@ package com.mogo.eagle.core.function.hmi.ui.msgbox.adapter import android.app.Activity +import android.content.res.Resources import android.os.CountDownTimer +import android.view.Gravity import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -17,6 +19,7 @@ import com.mogo.eagle.core.function.call.hmi.CallerHmiManager import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxEventListenerManager import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager import com.mogo.eagle.core.function.hmi.R +import com.mogo.eagle.core.function.hmi.ui.msgbox.PassengerMsgBoxBubbleView import com.mogo.eagle.core.utilcode.mogo.glide.transform.GlideRoundedCornersTransform import com.mogo.eagle.core.utilcode.util.TimeUtils import com.mogo.eagle.core.utilcode.util.TimeUtils.getHourMinFormat @@ -34,6 +37,7 @@ class PassengerMsgBoxBubbleAdapter(private val activity: Activity): RecyclerView private val notice: Int = 1 private val v2x: Int = 2 private val summary: Int = 3 + private val voice: Int = 4 fun setData(data: ArrayList){ this.data = data @@ -43,6 +47,17 @@ class PassengerMsgBoxBubbleAdapter(private val activity: Activity): RecyclerView notifyDataSetChanged() } + /** + * 获取列表数据个数 + */ + fun getDataSize(): Int{ + return if(data.isNullOrEmpty()){ + 0 + }else{ + data!!.size + } + } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return when (viewType) { notice -> { @@ -53,6 +68,11 @@ class PassengerMsgBoxBubbleAdapter(private val activity: Activity): RecyclerView val view = LayoutInflater.from(parent.context).inflate(R.layout.item_passenger_msg_box_summary,parent,false) BubbleSummaryHolder(view) } + //小智语音 + voice -> { + val view = LayoutInflater.from(parent.context).inflate(R.layout.item_passenger_msg_box_voice,parent,false) + BubbleVoiceHolder(view) + } else -> { val view = LayoutInflater.from(parent.context).inflate(R.layout.item_passenger_msg_box_v2x,parent,false) BubbleV2XHolder(view) @@ -108,23 +128,41 @@ class PassengerMsgBoxBubbleAdapter(private val activity: Activity): RecyclerView } } } + //小智语音消息 + is BubbleVoiceHolder -> { + data?.let { + val voiceMsg = it[position].msgBoxBean.bean as VoiceMsg + holder.tvPassengerVoiceContent.text = voiceMsg.msg + if(voiceMsg.isResp){ + //小智说的 + holder.tvPassengerVoiceContent.setTextColor(activity.resources.getColor(R.color.black)) + }else{ + //用户说的 + holder.tvPassengerVoiceContent.setTextColor(activity.resources.getColor(R.color.blue)) + } + } + } } val msgBoxBean: MsgBoxCountDownBean = data!![position] - msgBoxBean.countDownTimer =object: CountDownTimer(CallerMsgBoxManager.getDismissTime(),1000){ - override fun onTick(p0: Long) { + if(msgBoxBean.msgBoxBean.type != MsgBoxType.VOICE){ + msgBoxBean.countDownTimer =object: CountDownTimer(CallerMsgBoxManager.getDismissTime(),CallerMsgBoxManager.getDismissTime()){ + override fun onTick(p0: Long) { - } + } - override fun onFinish() { - data?.remove(msgBoxBean) - notifyDataSetChanged() + override fun onFinish() { + data?.remove(msgBoxBean) + notifyDataSetChanged() // notifyItemRemoved(index) // notifyItemRangeChanged(index,recordTypeEntity.size-index) - } + //通知消息盒子可以展示新的缓存消息 + CallerMsgBoxEventListenerManager.invokeHandleCachedMsg() + } + } + msgBoxBean.countDownTimer?.start() } - msgBoxBean.countDownTimer?.start() } override fun getItemCount() = data?.size ?: 0 @@ -134,7 +172,9 @@ class PassengerMsgBoxBubbleAdapter(private val activity: Activity): RecyclerView notice }else if(data!![position].msgBoxBean.type == MsgBoxType.V2X && data!![position].msgBoxBean.sourceType == DataSourceType.SUMMARY){ summary - } else{ + }else if(data!![position].msgBoxBean.type == MsgBoxType.VOICE){ + voice + }else{ v2x } } @@ -160,4 +200,9 @@ class PassengerMsgBoxBubbleAdapter(private val activity: Activity): RecyclerView var tvPassengerSummaryTime: TextView = itemView.findViewById(R.id.tvPassengerSummaryTime) } + //小智语音消息 + class BubbleVoiceHolder(itemView: View): RecyclerView.ViewHolder(itemView){ + var tvPassengerVoiceContent: TextView = itemView.findViewById(R.id.tvPassengerVoiceContent) + } + } \ No newline at end of file diff --git a/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_passenger_msg_box_voice.xml b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_passenger_msg_box_voice.xml new file mode 100644 index 0000000000..e5d2460761 --- /dev/null +++ b/core/function-impl/mogo-core-function-hmi/src/main/res/layout/item_passenger_msg_box_voice.xml @@ -0,0 +1,29 @@ + + + + + + \ No newline at end of file diff --git a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxCountDownBean.kt b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxCountDownBean.kt index a5fee017c9..af2c2becc2 100644 --- a/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxCountDownBean.kt +++ b/core/mogo-core-data/src/main/java/com/mogo/eagle/core/data/msgbox/MsgBoxCountDownBean.kt @@ -2,6 +2,6 @@ package com.mogo.eagle.core.data.msgbox import android.os.CountDownTimer -class MsgBoxCountDownBean(val msgBoxBean: MsgBoxBean){ +class MsgBoxCountDownBean(var msgBoxBean: MsgBoxBean){ var countDownTimer: CountDownTimer ?= null } \ No newline at end of file diff --git a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/msgbox/IMsgBoxEventListener.kt b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/msgbox/IMsgBoxEventListener.kt index e333b9afce..9a2c4061c3 100644 --- a/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/msgbox/IMsgBoxEventListener.kt +++ b/core/mogo-core-function-api/src/main/java/com/mogo/eagle/core/function/api/datacenter/msgbox/IMsgBoxEventListener.kt @@ -22,4 +22,7 @@ interface IMsgBoxEventListener { //气泡态上报消息事件点击监听 fun onBubbleReportClickEvent(msgBoxBean: MsgBoxBean){} + + //通知播放缓存的未播放消息 + fun onHandleCachedMsg(){} } \ No newline at end of file diff --git a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxEventListenerManager.kt b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxEventListenerManager.kt index 60ae707c49..6532d6ff8d 100644 --- a/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxEventListenerManager.kt +++ b/core/mogo-core-function-call/src/main/java/com/mogo/eagle/core/function/call/msgbox/CallerMsgBoxEventListenerManager.kt @@ -61,5 +61,15 @@ object CallerMsgBoxEventListenerManager: CallerBase() { } } + /** + * 通知播放缓存的未播放消息 + */ + fun invokeHandleCachedMsg(){ + M_LISTENERS.forEach { + val listener = it.value + listener.onHandleCachedMsg() + } + } + } \ No newline at end of file