融云設置已讀,未讀消息標識
需求:會話列表,以及會話界面發出去的消息前面加上已讀,未讀的標識
官方給的解決方案
1、您可以通過 rc_config.xml 里的開關,開啟消息的閱讀回執功能。默認 false 為關閉狀態,設置成 true 為開啟
2、請在 init 之后調用下面方法來設置支持消息回執的會話類型。目前只支持 PRIVATE、GROUP 和 DISCUSSION 三種類型
官方還有一個說的更詳細的文檔,忘了在哪里,找不到了
官方的沒法解決我的需求,就算它能顯示也不是我想要的。
處理會話界面
1、自定義類繼承自 MessageListAdpater, 然后重寫其中的 holder.sentStatus
2、布局是 rc_item_message.xml
3、自定義類集成自 ConversationFragment,然后重寫onResolveAdpater 中得到自定義adpter并返回
參考代碼
public class MyMessageListAdapter extends MessageListAdapter {
public MyMessageListAdapter(Context context) {
super(context);
}
@Override
protected void bindView(View v, int position, UIMessage data) {
super.bindView(v, position, data);
if(data != null){
final MessageListAdapter.ViewHolder holder = (MessageListAdapter.ViewHolder) v.getTag();
if(holder != null){
if (data.getMessageDirection().equals(Message.MessageDirection.RECEIVE)) {
holder.sentStatus.setVisibility(View.GONE);
} else {
LogUtils.i("msgStatus", data.getSentStatus().getValue() + "");
if (data.getSentStatus() == Message.SentStatus.SENT) {
holder.sentStatus.setCompoundDrawablesWithIntrinsicBounds(v.getContext().getResources().getDrawable(R.mipmap.ic_msg_sent),null,null,null);
holder.sentStatus.setText(R.string.im_msg_sent);
holder.sentStatus.setVisibility(View.VISIBLE);
} else if (data.getSentStatus() == Message.SentStatus.READ) {
holder.sentStatus.setText(R.string.im_msg_read);
holder.sentStatus.setCompoundDrawablesWithIntrinsicBounds(v.getContext().getResources().getDrawable(R.mipmap.ic_msg_read),null,null,null);
holder.sentStatus.setVisibility(View.VISIBLE);
}
}
}
}
}}
敲黑板:rc_config.xml 里的開關,開啟消息的閱讀回執功能。默認 false 為關閉狀態,設置成 true 為開啟 ,如果能正常顯示最好,不能正常顯示,需要在會話界面自己發送閱讀回執。
處理會話列表界面
集成 PrivateConversationProvider 然后重新 bindView 方法, 然后在此方法中 根據 Message.SentStatus來進行修改顯示內容
參考代碼:
@ConversationProviderTag(
conversationType = "private",
portraitPosition = 1
)
public class MyPrivateConversationProvider extends PrivateConversationProvider {
@Override
public void bindView(View view, int position, UIConversation data) {
super.bindView(view, position, data);
PrivateConversationProvider.ViewHolder holder = (PrivateConversationProvider.ViewHolder)view.getTag();
if(null != data && data.getConversationSenderId() != null && data.getConversationSenderId().equals(RongIM.getInstance().getCurrentUserId())){
if(data.getSentStatus() != null){
if(data.getSentStatus() == Message.SentStatus.FAILED || data.getSentStatus() == Message.SentStatus.SENDING){
holder.readStatus.setVisibility(View.GONE);
} else {
if(data.getSentStatus() == Message.SentStatus.SENT){
holder.readStatus.setImageResource(R.mipmap.ic_msg_sent);
holder.readStatus.setVisibility(View.VISIBLE);
} else if(data.getSentStatus() == Message.SentStatus.READ){
holder.readStatus.setImageResource(R.mipmap.ic_msg_read);
holder.readStatus.setVisibility(View.VISIBLE);
}
}
}
}
}}
提供下我問的工單
https://developer.rongcloud.cn/ticket/info/eB25GrlyC8EwlcdG1kY=
有問題請加Q群:142739277