Merge branch 'dev_arch_opt_3.0' of gitlab.zhidaoauto.com:zhjt/AndroidApp/MoGoEagleEye into dev_arch_opt_3.0

This commit is contained in:
lixiaopeng
2023-02-15 12:30:40 +08:00
5 changed files with 319 additions and 0 deletions

View File

@@ -0,0 +1,79 @@
package com.mogo.eagle.core.function.hmi.ui.msgbox
import android.app.Activity
import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.recyclerview.widget.LinearLayoutManager
import com.mogo.eagle.core.data.msgbox.MsgBoxBean
import com.mogo.eagle.core.data.msgbox.MsgBoxType
import com.mogo.eagle.core.data.msgbox.MsgCategory
import com.mogo.eagle.core.function.api.msgbox.IMsgBoxListener
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxEventListenerManager
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxListenerManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.function.hmi.ui.msgbox.adapter.MBoxBubbleAdapter
import com.mogo.eagle.core.function.msgbox.MsgBoxConfig
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
import kotlinx.android.synthetic.main.layout_m_box_bubble.view.*
class MBoxBubbleView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : ConstraintLayout(context, attrs, defStyleAttr), IMsgBoxListener {
private val TAG = "PassengerMsgBoxBubbleView"
private val dataList :ArrayList<MsgBoxBean> = ArrayList()
private var mBoxBubbleAdapter: MBoxBubbleAdapter?= null
private var isShowData = true
init {
LayoutInflater.from(context).inflate(R.layout.layout_m_box_bubble, this, true)
initView()
}
private fun initView(){
val linearLayoutManager = LinearLayoutManager(context)
linearLayoutManager.orientation = LinearLayoutManager.VERTICAL
mBoxBubbleAdapter = MBoxBubbleAdapter(context as Activity)
rvMBoxBubbleList.adapter = mBoxBubbleAdapter
rvMBoxBubbleList.layoutManager = linearLayoutManager
}
/**
* 是否展示接收消息,消息盒子打开状态下不再展示气泡消息
* @param show true 展示false 不展示
*/
fun isShowData(show: Boolean){
isShowData = show
}
override fun onDataChanged(category: MsgCategory, msgBoxList: MsgBoxBean) {
UiThreadHandler.post {
if(category == MsgCategory.NOTICE){
if(msgBoxList.type == MsgBoxType.NOTICE || msgBoxList.type == MsgBoxType.V2X
|| msgBoxList.type == MsgBoxType.OBU){
MsgBoxConfig.noticeList.add(msgBoxList)
if(isShowData){
CallerMsgBoxEventListenerManager.invokeUpdateTipListener(true)
dataList.add(msgBoxList)
mBoxBubbleAdapter?.setData(dataList)
}
}
}
}
}
override fun onAttachedToWindow() {
super.onAttachedToWindow()
CallerMsgBoxListenerManager.addListener(TAG,this)
}
override fun onDetachedFromWindow() {
super.onDetachedFromWindow()
CallerMsgBoxListenerManager.removeListener(TAG)
}
}

View File

@@ -0,0 +1,119 @@
package com.mogo.eagle.core.function.hmi.ui.msgbox.adapter
import android.app.Activity
import android.os.CountDownTimer
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.mogo.eagle.core.data.enums.EventTypeEnumNew
import com.mogo.eagle.core.data.msgbox.*
import com.mogo.eagle.core.function.call.msgbox.CallerMsgBoxManager
import com.mogo.eagle.core.function.hmi.R
import com.mogo.eagle.core.utilcode.util.TimeUtils
import com.mogo.eagle.core.utilcode.util.TimeUtils.getHourMinFormat
class MBoxBubbleAdapter(private val activity: Activity): RecyclerView.Adapter<RecyclerView.ViewHolder>(){
private var data: ArrayList<MsgBoxBean> ?= null
private val notice: Int = 1
private val v2x: Int = 2
var countDownTimer: CountDownTimer?=null
fun setData(data: ArrayList<MsgBoxBean>){
this.data = data
if(data.size>3){
data.removeAt(0)
}
notifyDataSetChanged()
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return when (viewType) {
notice -> {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_m_box_notice,parent,false)
BubbleNoticeHolder(view)
}
else -> {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_m_box_v2x,parent,false)
BubbleV2XHolder(view)
}
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is BubbleNoticeHolder -> {
data?.let {
val noticeFrCloudMsg = it[position].bean as NoticeFrCloudMsg
if(noticeFrCloudMsg.type == 0){
val noticeNormalData = noticeFrCloudMsg.noticeNormalData
holder.tvMNoticeTime.text = TimeUtils.millis2String(it[position].timestamp,getHourMinFormat())
holder.tvMNoticeContent.text = noticeNormalData?.content
}else {
val noticeTrafficStylePushData = noticeFrCloudMsg.trafficPushData
holder.tvMNoticeTime.text = TimeUtils.millis2String(it[position].timestamp,getHourMinFormat())
holder.tvMNoticeContent.text = noticeTrafficStylePushData?.content
}
}
}
is BubbleV2XHolder -> {
data?.let {
val msgBoxBean = it[position]
val v2XMsg = msgBoxBean.bean as V2XMsg
holder.tvMV2XTime.text = TimeUtils.millis2String(it[position].timestamp,getHourMinFormat())
holder.tvMV2XContent.text = v2XMsg.content
holder.ivMV2XImage.setImageDrawable(activity.resources.getDrawable(
EventTypeEnumNew.getUpdateIconRes(v2XMsg.type)))
}
}
}
val msgBoxBean: MsgBoxBean = data!![position]
countDownTimer =object: CountDownTimer(CallerMsgBoxManager.getDismissTime(),1000){
override fun onTick(p0: Long) {
}
override fun onFinish() {
data?.remove(msgBoxBean)
notifyDataSetChanged()
// notifyItemRemoved(index)
// notifyItemRangeChanged(index,recordTypeEntity.size-index)
}
}
countDownTimer?.start()
}
override fun getItemCount() = data?.size ?: 0
override fun getItemViewType(position: Int): Int {
return if(data!![position].type == MsgBoxType.NOTICE){
notice
}else{
v2x
}
}
//Notice
class BubbleNoticeHolder(itemView: View): RecyclerView.ViewHolder(itemView){
var ivMNoticeImage: ImageView = itemView.findViewById(R.id.ivMNoticeImage)
var tvMNoticeTitle: TextView = itemView.findViewById(R.id.tvMNoticeTitle)
var tvMNoticeContent: TextView = itemView.findViewById(R.id.tvMNoticeContent)
var tvMNoticeTime: TextView = itemView.findViewById(R.id.tvMNoticeTime)
}
//OBU、V2X
class BubbleV2XHolder(itemView: View): RecyclerView.ViewHolder(itemView){
var ivMV2XImage: ImageView = itemView.findViewById(R.id.ivMV2XImage)
var tvMV2XTime: TextView = itemView.findViewById(R.id.tvMV2XTime)
var tvMV2XContent: TextView = itemView.findViewById(R.id.tvMV2XContent)
}
}

View File

@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mogo.eagle.core.widget.RoundConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/dp_291"
android:layout_height="@dimen/dp_80"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#CCFFFFFF"
app:roundLayoutRadius="@dimen/dp_16"
android:layout_marginTop="@dimen/dp_12"
android:layout_marginBottom="@dimen/dp_12"
>
<ImageView
android:id="@+id/ivMNoticeImage"
android:layout_width="@dimen/dp_80"
android:layout_height="@dimen/dp_80"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:src="@drawable/icon_passenger_operation"
/>
<TextView
android:id="@+id/tvMNoticeTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="官方公告"
android:textColor="#FF203555"
android:textSize="@dimen/dp_18"
android:layout_marginStart="@dimen/dp_10"
app:layout_constraintLeft_toRightOf="@id/ivMNoticeImage"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@id/tvMNoticeContent"
/>
<TextView
android:id="@+id/tvMNoticeTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#B31A273F"
android:textSize="@dimen/dp_18"
app:layout_constraintTop_toTopOf="@id/tvMNoticeTitle"
app:layout_constraintBottom_toBottomOf="@id/tvMNoticeTitle"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginRight="@dimen/dp_10"
/>
<TextView
android:id="@+id/tvMNoticeContent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textColor="#CC203555"
android:textSize="@dimen/dp_14"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="@id/tvMNoticeTitle"
app:layout_constraintTop_toBottomOf="@id/tvMNoticeTitle"
app:layout_constraintRight_toRightOf="@id/tvMNoticeTime"
android:gravity="start"
android:maxLines="1"
android:ellipsize="end"
/>
</com.mogo.eagle.core.widget.RoundConstraintLayout>

View File

@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<com.mogo.eagle.core.widget.RoundCanClickConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/dp_291"
android:layout_height="@dimen/dp_80"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#CCFFFFFF"
app:roundLayoutRadius="@dimen/dp_16"
android:layout_marginTop="@dimen/dp_12"
android:layout_marginBottom="@dimen/dp_12">
<ImageView
android:id="@+id/ivMV2XImage"
android:layout_width="@dimen/dp_54"
android:layout_height="@dimen/dp_54"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginStart="@dimen/dp_13"
/>
<TextView
android:id="@+id/tvMV2XTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:textColor="#991A273F"
android:textSize="@dimen/dp_18"
android:layout_marginEnd="@dimen/dp_13"
/>
<TextView
android:id="@+id/tvMV2XContent"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/ivMV2XImage"
app:layout_constraintRight_toLeftOf="@id/tvMV2XTime"
android:gravity="start"
android:maxLines="1"
android:ellipsize="end"
android:textColor="#FF203555"
android:textSize="@dimen/dp_18"
android:layout_marginStart="@dimen/dp_20"
android:layout_marginEnd="@dimen/dp_18"
/>
</com.mogo.eagle.core.widget.RoundCanClickConstraintLayout>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.recyclerview.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/rvMBoxBubbleList"
android:layout_width="@dimen/dp_291"
android:layout_height="wrap_content"
>
</androidx.recyclerview.widget.RecyclerView>