This commit is contained in:
itgaojian163 2024-10-30 20:55:29 +08:00
parent e7cdff8188
commit 7600f0d041
12 changed files with 68 additions and 6 deletions

View File

@ -117,31 +117,37 @@ class ChatMsgAdapter(var datas: List<MsgBean>) :
MsgTypeStateEnum.MSG_FROM_OTHER_TXT -> { MsgTypeStateEnum.MSG_FROM_OTHER_TXT -> {
(holder.binding as ItemMsgOtherBinding).pos = position (holder.binding as ItemMsgOtherBinding).pos = position
(holder.binding as ItemMsgOtherBinding).bean = list[position] (holder.binding as ItemMsgOtherBinding).bean = list[position]
(holder.binding as ItemMsgOtherBinding).state = list[position].sendState
}//收到文本信息 }//收到文本信息
MsgTypeStateEnum.MSG_TO_OTHER_MOVIE -> { MsgTypeStateEnum.MSG_TO_OTHER_MOVIE -> {
(holder.binding as ItemMsgMyVideoBinding).pos = position (holder.binding as ItemMsgMyVideoBinding).pos = position
(holder.binding as ItemMsgMyVideoBinding).bean = list[position] (holder.binding as ItemMsgMyVideoBinding).bean = list[position]
(holder.binding as ItemMsgMyVideoBinding).state = list[position].sendState
}//发送视频 }//发送视频
MsgTypeStateEnum.MSG_FROM_OTHER_MOVIE -> { MsgTypeStateEnum.MSG_FROM_OTHER_MOVIE -> {
(holder.binding as ItemMsgOtherVideoBinding).pos = position (holder.binding as ItemMsgOtherVideoBinding).pos = position
(holder.binding as ItemMsgOtherVideoBinding).bean = list[position] (holder.binding as ItemMsgOtherVideoBinding).bean = list[position]
(holder.binding as ItemMsgOtherVideoBinding).state = list[position].sendState
}//收到视频 }//收到视频
MsgTypeStateEnum.MSG_TO_OTHER_IMG -> { MsgTypeStateEnum.MSG_TO_OTHER_IMG -> {
(holder.binding as ItemMsgMyImgBinding).pos = position (holder.binding as ItemMsgMyImgBinding).pos = position
(holder.binding as ItemMsgMyImgBinding).bean = list[position] (holder.binding as ItemMsgMyImgBinding).bean = list[position]
(holder.binding as ItemMsgMyImgBinding).state = list[position].sendState
}//发送图片 }//发送图片
MsgTypeStateEnum.MSG_FROM_OTHER_IMG -> { MsgTypeStateEnum.MSG_FROM_OTHER_IMG -> {
(holder.binding as ItemMsgOtherImgBinding).pos = position (holder.binding as ItemMsgOtherImgBinding).pos = position
(holder.binding as ItemMsgOtherImgBinding).bean = list[position] (holder.binding as ItemMsgOtherImgBinding).bean = list[position]
(holder.binding as ItemMsgOtherImgBinding).state = list[position].sendState
}//收到图片 }//收到图片
MsgTypeStateEnum.MSG_TO_OTHER_VOICE -> { MsgTypeStateEnum.MSG_TO_OTHER_VOICE -> {
(holder.binding as ItemMsgMyAudioBinding).pos = position (holder.binding as ItemMsgMyAudioBinding).pos = position
(holder.binding as ItemMsgMyAudioBinding).bean = list[position] (holder.binding as ItemMsgMyAudioBinding).bean = list[position]
(holder.binding as ItemMsgMyAudioBinding).state = list[position].sendState
}//语音 }//语音
MsgTypeStateEnum.MSG_FROM_OTHER_VOICE -> { MsgTypeStateEnum.MSG_FROM_OTHER_VOICE -> {
(holder.binding as ItemMsgOtherAudioBinding).pos = position (holder.binding as ItemMsgOtherAudioBinding).pos = position
(holder.binding as ItemMsgOtherAudioBinding).bean = list[position] (holder.binding as ItemMsgOtherAudioBinding).bean = list[position]
(holder.binding as ItemMsgOtherAudioBinding).state = list[position].sendState
}//语音 }//语音
else -> { else -> {
throw IllegalArgumentException("Invalid view type") throw IllegalArgumentException("Invalid view type")

View File

@ -4,6 +4,7 @@ import androidx.room.ColumnInfo
import androidx.room.Entity import androidx.room.Entity
import androidx.room.Ignore import androidx.room.Ignore
import androidx.room.PrimaryKey import androidx.room.PrimaryKey
import androidx.room.TypeConverters
import java.io.Serializable import java.io.Serializable
@Entity(tableName = "db_msg") @Entity(tableName = "db_msg")
@ -21,7 +22,7 @@ data class MsgBean(
@ColumnInfo(name = "body") @ColumnInfo(name = "body")
var body: String, //消息体 var body: String, //消息体
@ColumnInfo(name = "timestamp") @ColumnInfo(name = "timestamp")
var timestamp: Long, // 时间戳 var timestamp: Long,
@ColumnInfo(name = "sendState") @ColumnInfo(name = "sendState")
var sendState: Int, //发送状态 11发送中 12发送失败 13发送成功 var sendState: Int, //发送状态 11发送中 12发送失败 13发送成功
@ColumnInfo(name = "fromName") @ColumnInfo(name = "fromName")

View File

@ -28,13 +28,13 @@ object MsgTypeStateEnum {
const val MSG_FROM_OTHER_FILE: Int = 152 // * 152 其他人发送给我的文件信息 const val MSG_FROM_OTHER_FILE: Int = 152 // * 152 其他人发送给我的文件信息
const val MSG_TO_OTHER_HREF: Int = 161 // * 161 我发送给其他人的文件信息 const val MSG_TO_OTHER_HREF: Int = 161 // * 161 我发送给其他人的文件信息
const val MSG_FROM_OTHER_HREF: Int = 162 // * 162 其他人发送给我的文件信息 const val MSG_FROM_OTHER_HREF: Int = 162 // * 162 其他人发送给我的文件信息
const val MSG_SEND_ING: Int = 1001//11 //发送中 const val MSG_SEND_ING: Int = 1001//11 //发送中
const val MSG_SEND_FAIL: Int = 1002//12 //发送失败 const val MSG_SEND_FAIL: Int = 1002//12 //发送失败
const val MSG_SEND_SUCCESS: Int = 1003////发送成功 const val MSG_SEND_SUCCESS: Int = 1003////发送成功
} }
@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER)
@IntDef( @IntDef(
MSG_TO_OTHER_TXT, MSG_TO_OTHER_TXT,
MSG_FROM_OTHER_TXT, MSG_FROM_OTHER_TXT,

View File

@ -1,5 +1,6 @@
package com.tenlionsoft.aimz_k.widget package com.tenlionsoft.aimz_k.widget
import android.view.View
import android.widget.ImageView import android.widget.ImageView
import androidx.databinding.BindingAdapter import androidx.databinding.BindingAdapter
import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.LinearLayoutManager
@ -9,6 +10,7 @@ import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions import com.bumptech.glide.request.RequestOptions
import com.tenlionsoft.aimz_k.R import com.tenlionsoft.aimz_k.R
import com.tenlionsoft.aimz_k.model.MsgTypeStateEnum
object BindingUtils { object BindingUtils {
@ -46,4 +48,28 @@ object BindingUtils {
imageView.setImageResource(url) imageView.setImageResource(url)
} }
//发送中
@BindingAdapter("isShowLoading")
@JvmStatic
fun sending(view: View, status: Int) {
when (status) {
MsgTypeStateEnum.MSG_SEND_SUCCESS -> view.visibility = View.GONE
MsgTypeStateEnum.MSG_SEND_FAIL -> view.visibility = View.GONE
MsgTypeStateEnum.MSG_SEND_ING -> view.visibility = View.VISIBLE
else -> view.visibility = View.GONE
}
}
//发送失败
@BindingAdapter("isShowFail")
@JvmStatic
fun sendFail(view: View, status: Int) {
when (status) {
MsgTypeStateEnum.MSG_SEND_SUCCESS -> view.visibility = View.GONE
MsgTypeStateEnum.MSG_SEND_FAIL -> view.visibility = View.GONE
MsgTypeStateEnum.MSG_SEND_ING -> view.visibility = View.VISIBLE
else -> view.visibility = View.GONE
}
}
} }

View File

@ -11,9 +11,10 @@
<variable <variable
name="bean" name="bean"
type="com.tenlionsoft.aimz_k.model.MsgBean" /> type="com.tenlionsoft.aimz_k.model.MsgBean" />
<variable <variable
name="state" name="state"
type="com.tenlionsoft.aimz_k.model.MsgState" /> type="Integer" />
</data> </data>
<LinearLayout <LinearLayout

View File

@ -10,6 +10,9 @@
<variable <variable
name="bean" name="bean"
type="com.tenlionsoft.aimz_k.model.MsgBean" /> type="com.tenlionsoft.aimz_k.model.MsgBean" />
<variable
name="state"
type="Integer" />
</data> </data>
<LinearLayout <LinearLayout

View File

@ -11,6 +11,9 @@
<variable <variable
name="bean" name="bean"
type="com.tenlionsoft.aimz_k.model.MsgBean" /> type="com.tenlionsoft.aimz_k.model.MsgBean" />
<variable
name="state"
type="Integer" />
</data> </data>
<LinearLayout <LinearLayout

View File

@ -11,6 +11,9 @@
<variable <variable
name="bean" name="bean"
type="com.tenlionsoft.aimz_k.model.MsgBean" /> type="com.tenlionsoft.aimz_k.model.MsgBean" />
<variable
name="state"
type="Integer" />
</data> </data>
<LinearLayout <LinearLayout

View File

@ -10,6 +10,10 @@
<variable <variable
name="bean" name="bean"
type="com.tenlionsoft.aimz_k.model.MsgBean" /> type="com.tenlionsoft.aimz_k.model.MsgBean" />
<variable
name="state"
type="Integer" />
</data> </data>
<LinearLayout <LinearLayout

View File

@ -3,12 +3,20 @@
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools">
<data> <data>
<variable <variable
name="pos" name="pos"
type="Integer" /> type="Integer" />
<variable <variable
name="bean" name="bean"
type="com.tenlionsoft.aimz_k.model.MsgBean" /> type="com.tenlionsoft.aimz_k.model.MsgBean" />
<variable
name="state"
type="Integer" />
<import type="com.tenlionsoft.aimz_k.widget.BindingUtils" />
</data> </data>
<LinearLayout <LinearLayout
@ -68,6 +76,7 @@
<ProgressBar <ProgressBar
android:id="@+id/pb_sending" android:id="@+id/pb_sending"
isShowLoading="@{state}"
android:layout_width="15dp" android:layout_width="15dp"
android:layout_height="15dp" android:layout_height="15dp"
android:layout_centerInParent="true" android:layout_centerInParent="true"
@ -76,12 +85,12 @@
<ImageView <ImageView
android:id="@+id/iv_msg_state_fail" android:id="@+id/iv_msg_state_fail"
isShowFail="@{state}"
android:layout_width="15dp" android:layout_width="15dp"
android:layout_height="15dp" android:layout_height="15dp"
android:layout_centerInParent="true" android:layout_centerInParent="true"
android:src="@drawable/msg_state_fail_resend" android:src="@drawable/msg_state_fail_resend"
android:visibility="gone" tools:visibility="gone" />
tools:visibility="visible" />
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
</layout> </layout>

View File

@ -11,6 +11,9 @@
<variable <variable
name="bean" name="bean"
type="com.tenlionsoft.aimz_k.model.MsgBean" /> type="com.tenlionsoft.aimz_k.model.MsgBean" />
<variable
name="state"
type="Integer" />
</data> </data>
<LinearLayout <LinearLayout

View File

@ -12,6 +12,9 @@
<variable <variable
name="bean" name="bean"
type="com.tenlionsoft.aimz_k.model.MsgBean" /> type="com.tenlionsoft.aimz_k.model.MsgBean" />
<variable
name="state"
type="Integer" />
</data> </data>
<LinearLayout <LinearLayout