一、前言
融云im sdk默认的已读图标不好看也不满足需求,需求要文本显示,更直观。
二、效果图
QQ图片20220506163356.jpg QQ图片20220506163555.jpg三、解决思路
- 开启已读未读功能。
- 会话界面里面自定义MessageListAdapter。
- 会话列表界面自定义PrivateConversationProvider。
四、参考示例代码:
MyMessageListAdapter.kt
class MyMessageListAdapter(listener: IViewProviderListener<UiMessage>) :
MessageListAdapter(listener) {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
super.onBindViewHolder(holder, position)
val listPosition = position - this.headersCount
if (listPosition >= 0) {
val uiMessage = getItem(listPosition)
val isSender = uiMessage.message.messageDirection == Message.MessageDirection.SEND
if (holder.getView<TextView>(R.id.app_read_receipt) != null){
if (RongConfigCenter.conversationConfig().isShowReadReceipt(uiMessage.message.conversationType) && isSender
&& uiMessage.content !is CustomizeGiftsMessage) {
when (uiMessage.message.sentStatus) {
Message.SentStatus.READ -> {
holder.setText(
R.id.app_read_receipt,
holder.context.getString(R.string.read)
)
holder.setVisible(R.id.app_read_receipt, true)
}
Message.SentStatus.SENT -> {
holder.setText(
R.id.app_read_receipt,
holder.context.getString(R.string.unread)
)
holder.setVisible(R.id.app_read_receipt, true)
}
else -> {
holder.setVisible(R.id.app_read_receipt, false)
}
}
} else {
holder.setVisible(R.id.app_read_receipt, false)
}
}
//隐藏原来的已读控件
if (holder.getView<TextView>(R.id.rc_read_receipt) != null){
holder.setVisible(R.id.rc_read_receipt, false)
}
}
}}
MyPrivateConversationProvider.class
public class MyPrivateConversationProvider extends BaseConversationProvider {
public MyPrivateConversationProvider() {
}
public boolean isItemViewType(BaseUiConversation item) {
return Conversation.ConversationType.PRIVATE.equals(item.mCore.getConversationType());
}
public void bindViewHolder(ViewHolder holder, BaseUiConversation baseUiConversation, int position, List<BaseUiConversation> list, IViewProviderListener<BaseUiConversation> listener) {
super.bindViewHolder(holder, baseUiConversation, position, list, listener);
//不用它们的已读未读,改为我们的,隐藏它们的holder.setVisible(R.id.rc_conversation_read_receipt,false);
LogUtils.INSTANCE.o("bindViewHolder1",baseUiConversation.mCore);
if (!baseUiConversation.mCore.getTargetId().contains(ImType.MYCUS) && baseUiConversation.mCore.getSenderUserId().equals(SPUtil.getTargetId())) {
if (baseUiConversation.mCore.getSentStatus() == Message.SentStatus.READ) {
holder.setText(
R.id.app_conversation_read_receipt, holder.getContext().getString(
R.string.read));
holder.setVisible(R.id.app_conversation_read_receipt, true);
} else if (baseUiConversation.mCore.getSentStatus() == Message.SentStatus.SENT) {
holder.setText(
R.id.app_conversation_read_receipt, holder.getContext().getString(
R.string.unread));
holder.setVisible(R.id.app_conversation_read_receipt, true);
} else {
holder.setVisible(R.id.app_conversation_read_receipt, false);
}
注:记得在相应的item布局加上用来显示已读未读的文本控件。
还有问题可私信我
网友评论