私聊消息提醒文案统一

This commit is contained in:
huangjian
2021-11-16 15:50:27 +08:00
parent 58066c0f8f
commit f3f8a5a90a
13 changed files with 207 additions and 847 deletions

View File

@@ -29,6 +29,7 @@ import com.yizhuan.erban.R;
import com.yizhuan.erban.avroom.BottomViewListenerWrapper;
import com.yizhuan.erban.ui.utils.ImageLoadUtils;
import com.yizhuan.tutu.room_chat.activity.RoomMsgActivity;
import com.yizhuan.xchat_android_core.helper.ImHelperUtils;
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
import com.yizhuan.xchat_android_core.manager.IMMessageManager;
import com.yizhuan.xchat_android_core.market_verify.MarketVerifyModel;
@@ -436,7 +437,7 @@ public class BottomView extends RelativeLayout implements View.OnClickListener {
TextView tvContent = contentView.findViewById(R.id.tv_content);
ImageLoadUtils.loadAvatar(userInfo.getAvatar(), ivAvatar);
tvNickname.setText(StringExtensionKt.subAndReplaceDot(userInfo.getName(), 4));
tvContent.setText(recentContact.getContent());
tvContent.setText(ImHelperUtils.getMsgDigest(recentContact));
contentView.setOnClickListener(v -> RoomMsgActivity.startForPrivateChat(getContext(), recentContact.getFromAccount()));
int[] vLoc = new int[2];

View File

@@ -214,15 +214,6 @@ public class RecentContactsFragment extends TFragment {
}
}
@Override
public String getDigestOfAttachment(RecentContact recentContact, MsgAttachment attachment) {
return null;
}
@Override
public String getDigestOfTipMsg(RecentContact recent) {
return null;
}
};
}

View File

@@ -377,111 +377,6 @@ public class RecentListFragment extends BaseFragment {
}
}
/**
* 定义消息收到后显示的文案
* @param recent
* @param attachment 消息附件对象
* @return
*/
@Override
public String getDigestOfAttachment(RecentContact recent, MsgAttachment attachment) {
if (attachment instanceof CustomAttachment) {
CustomAttachment customAttachment = (CustomAttachment) attachment;
if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI) {
return "您关注的TA上线啦快去围观吧~~~";
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_GIFT) {
return "[礼物]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_NOTICE) {
NoticeAttachment noticeAttachment = (NoticeAttachment) attachment;
return noticeAttachment.getTitle();
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_PACKET) {
RedPacketAttachment redPacketAttachment = (RedPacketAttachment) attachment;
return "您收到一个" + redPacketAttachment.getRedPacketInfo().getPacketName() + "红包哦!";
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_LOTTERY) {
return "恭喜您,获得抽奖机会";
} else if (customAttachment.getFirst() == CUSTOM_MESS_HEAD_NOBLE) {
NobleAttachment nobleAttachment = (NobleAttachment) attachment;
return "提示:" + nobleAttachment.msg;
} else if (customAttachment.getFirst() == CUSTOM_MESS_HEAD_CAR) {
return ((CarAttachment) attachment).msg;
} else if (customAttachment.getFirst() == CUSTOM_MSG_ASSISTANT_MSG) {
return ((AssistantAttachment) attachment).title;
} else if (customAttachment.getFirst() == CUSTOM_MSG_NEWBIE) {
return ((NewbieHelloAttachment) attachment).getNewbieHelloInfo().message;
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_SHARE_IN_APP) {
switch (customAttachment.getSecond()) {
case CUSTOM_MSG_SHARE_ROOM:
return "[分享房间]";
case CUSTOM_MSG_SHARE_FAMILY:
return "[分享家族]";
case CUSTOM_MSG_SHARE_TEAM:
return "[分享群组]";
default:
return "[您收到一条分享消息]";
}
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_LUCKY_MONEY) {
switch (customAttachment.getSecond()) {
case CUSTOM_MSG_SUB_TYPE_SEND_LUCKY_MONEY:
return "[您收到了一个群红包]";
case CUSTOM_MSG_SUB_TYPE_RECEIVE_LUCKY_MONEY:
LuckyMoneyTipsAttachment luckyMoneyTipsAttachment = (LuckyMoneyTipsAttachment) attachment;
String currentUid = String.valueOf(AuthModel.get().getCurrentUid());
LuckyMoneyInfo luckyMoneyInfo = luckyMoneyTipsAttachment.getLuckyMoneyInfo();
String senderUid = String.valueOf(luckyMoneyInfo.getSenderUid());
String receiverUid = luckyMoneyInfo.getReceiveUid();
if (Objects.equals(currentUid, senderUid)) {
return "[" + luckyMoneyInfo.getReceiveNick() + "领取了你的红包]";
} else if (Objects.equals(currentUid, receiverUid)) {
return "[你领取了" + luckyMoneyInfo.getNick() + "的红包]";
} else {
return "[" + luckyMoneyInfo.getReceiveNick() + "领取了" + luckyMoneyInfo.getNick() + "的红包]";
}
}
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_COMMON_SYSTEM_MSG
|| customAttachment.getFirst() == CUSTOM_MSG_SHIFT_OUT
|| customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_COMMON_SYSTEM_MSG_V2) {
return "[您收到一条系统消息]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_PUBLIC_CHAT_HALL) {
switch (customAttachment.getSecond()) {
case CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_AIT_ME:
AitMeAttachment aitMeAttachment = (AitMeAttachment) customAttachment;
AitMeInfo aitMeInfo = aitMeAttachment.getAitMeInfo();
return aitMeInfo.getContent();
}
return "[您收到一条公聊大厅相关消息]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_MODULE_HALL) {
return "[您收到一条公会消息]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_IM_GAME) {
return "[您收到一条公会消息]";
} else if (customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_SIGN_IN
&& customAttachment.getSecond() == CustomAttachment.CUSTOM_MSG_SUB_JUMP_SIGN_IN_ACTIVITY) {
return "[签到提醒]";
} else if (customAttachment instanceof CarveUpGoldThirdLevelAttachment) {
return "[签到瓜分百万]";
} else if (customAttachment instanceof SysMsgVoiceAttachment) {
return "[声音瓶子审核消息]";
} else if (WorldDynamicAttachment.isShareMsg(customAttachment)) {
return "[分享一条动态]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_RED_PACKAGE) {
return "[您收到一个全服红包]";
} else if (customAttachment instanceof ChatHintAttachment) {
return "[风险提示]";
}
} else if (attachment instanceof AudioAttachment) {
return "[语音]";
}
return null;
}
@Override
public String getDigestOfTipMsg(RecentContact recent) {
return null;
}
});
}

View File

@@ -1,14 +1,16 @@
package com.yizhuan.erban.ui.im.recent.holder;
import androidx.appcompat.widget.AppCompatImageView;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.widget.AppCompatImageView;
import com.netease.nim.uikit.business.recent.RecentContactsCallback;
import com.netease.nim.uikit.business.session.emoji.MoonUtil;
import com.netease.nim.uikit.business.session.helper.TeamNotificationHelper;
import com.netease.nim.uikit.business.uinfo.UserInfoHelper;
import com.netease.nim.uikit.common.ui.draggablebubbles.BubbleView;
import com.netease.nim.uikit.common.ui.imageview.HeadImageView;
@@ -17,30 +19,14 @@ import com.netease.nim.uikit.common.ui.recyclerview.holder.BaseViewHolder;
import com.netease.nim.uikit.common.ui.recyclerview.holder.RecyclerViewHolder;
import com.netease.nim.uikit.common.util.sys.TimeUtil;
import com.netease.nim.uikit.impl.cache.TeamDataCache;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.attachment.NotificationAttachment;
import com.netease.nimlib.sdk.msg.constant.MsgStatusEnum;
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.netease.nimlib.sdk.msg.model.RecentContact;
import com.netease.nimlib.sdk.team.model.Team;
import com.yizhuan.erban.R;
import com.yizhuan.erban.ui.im.recent.RecentContactsFragment;
import com.yizhuan.erban.ui.im.recent.adapter.RecentContactAdapter;
import com.yizhuan.xchat_android_core.im.custom.bean.AssistantAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.ImTipAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.MatchAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.NewbieHelloAttachment;
import java.util.ArrayList;
import java.util.List;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import com.yizhuan.xchat_android_core.helper.ImHelperUtils;
public abstract class RecentViewHolder extends RecyclerViewHolder<BaseQuickAdapter, BaseViewHolder, RecentContact> {
@@ -182,93 +168,7 @@ public abstract class RecentViewHolder extends RecyclerViewHolder<BaseQuickAdapt
}
protected String descOfMsg(RecentContact recent) {
if (recent.getMsgType() == MsgTypeEnum.text) {
return recent.getContent();
} else if (recent.getMsgType() == MsgTypeEnum.tip) {
String digest = null;
if (getCallback() != null) {
digest = getCallback().getDigestOfTipMsg(recent);
return ImHelperUtils.getMsgDigest(recent);
}
if (digest == null) {
digest = getDefaultDigest(null, recent);
}
return digest;
} else if (recent.getAttachment() != null) {
String digest = null;
if (getCallback() != null) {
digest = getCallback().getDigestOfAttachment(recent, recent.getAttachment());
}
if (digest == null) {
digest = getDefaultDigest(recent.getAttachment(), recent);
}
return digest;
}
return "";
}
// SDK本身只记录原始数据第三方APP可根据自己实际需求在最近联系人列表上显示缩略消息
// 以下为一些常见消息类型的示例。
private String getDefaultDigest(MsgAttachment attachment, RecentContact recent) {
switch (recent.getMsgType()) {
case text:
return recent.getContent();
case image:
return "[图片]";
case video:
return "[视频]";
case audio:
return "[语音消息]";
case location:
return "[位置]";
case file:
return "[文件]";
case tip:
List<String> uuids = new ArrayList<>();
uuids.add(recent.getRecentMessageId());
List<IMMessage> messages = NIMClient.getService(MsgService.class).queryMessageListByUuidBlock(uuids);
if (messages != null && messages.size() > 0) {
return messages.get(0).getContent();
}
return "[通知提醒]";
case notification:
return TeamNotificationHelper.getTeamNotificationText(recent.getContactId(),
recent.getFromAccount(),
(NotificationAttachment) recent.getAttachment());
case robot:
return "你收到一条消息...";
case custom:
if (attachment instanceof CustomAttachment) {
CustomAttachment customAttachment = (CustomAttachment) attachment;
switch (customAttachment.getFirst()) {
case CustomAttachment.CUSTOM_MSG_ASSISTANT_MSG:
AssistantAttachment monsterAwardAttachment = (AssistantAttachment) attachment;
switch (monsterAwardAttachment.getSecond()) {
case CustomAttachment.CUSTOM_MSG_ASSISTANT_COMMON_MSG:
return monsterAwardAttachment.title;
}
break;
case CustomAttachment.CUSTOM_MSG_IM_GAME:
return "[游戏邀请]";
case CustomAttachment.CUSTOM_MSG_IM_TIP:
ImTipAttachment imTipAttachment = (ImTipAttachment) attachment;
return imTipAttachment.getMsg();
case CustomAttachment.CUSTOM_MSG_LEVEL_UP:
return "[升级信息]";
case CustomAttachment.CUSTOM_MSG_NEWBIE:
NewbieHelloAttachment newbieHelloAttachment = (NewbieHelloAttachment) attachment;
return newbieHelloAttachment.getNewbieHelloInfo().message;
case CustomAttachment.CUSTOM_MSG_MATCH:
MatchAttachment matchAttachment = (MatchAttachment) attachment;
return matchAttachment.getContent();
}
}
default:
return "你收到一条消息...";
}
}
}

View File

@@ -1,12 +1,14 @@
package com.yizhuan.tutu.room_chat.adapter;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import android.text.TextUtils;
import android.widget.ImageView;
import android.widget.TextView;
import com.netease.nim.uikit.business.recent.RecentContactsCallback;
import com.netease.nim.uikit.business.session.emoji.MoonUtil;
import com.netease.nim.uikit.business.session.helper.TeamNotificationHelper;
import com.netease.nim.uikit.business.uinfo.UserInfoHelper;
import com.netease.nim.uikit.common.ui.drop.DropFake;
import com.netease.nim.uikit.common.ui.imageview.HeadImageView;
@@ -15,28 +17,13 @@ import com.netease.nim.uikit.common.ui.recyclerview.holder.BaseViewHolder;
import com.netease.nim.uikit.common.ui.recyclerview.holder.RecyclerViewHolder;
import com.netease.nim.uikit.common.util.sys.TimeUtil;
import com.netease.nim.uikit.impl.cache.TeamDataCache;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.attachment.NotificationAttachment;
import com.netease.nimlib.sdk.msg.constant.MsgStatusEnum;
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.netease.nimlib.sdk.msg.model.RecentContact;
import com.netease.nimlib.sdk.team.model.Team;
import com.yizhuan.erban.R;
import com.yizhuan.erban.ui.im.recent.RecentContactsFragment;
import com.yizhuan.erban.ui.im.recent.adapter.RecentContactAdapter;
import com.yizhuan.xchat_android_core.im.custom.bean.AssistantAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.NewbieHelloAttachment;
import java.util.ArrayList;
import java.util.List;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import com.yizhuan.xchat_android_core.helper.ImHelperUtils;
public abstract class RoomMsgRecentViewHolder extends RecyclerViewHolder<BaseQuickAdapter, BaseViewHolder, RecentContact> {
@@ -180,115 +167,7 @@ public abstract class RoomMsgRecentViewHolder extends RecyclerViewHolder<BaseQui
}
protected String descOfMsg(RecentContact recent) {
if (recent.getMsgType() == MsgTypeEnum.text) {
return recent.getContent();
} else if (recent.getMsgType() == MsgTypeEnum.tip) {
String digest = null;
if (getCallback() != null) {
digest = getCallback().getDigestOfTipMsg(recent);
return ImHelperUtils.getMsgDigest(recent);
}
if (digest == null) {
digest = getDefaultDigest(null, recent);
}
return digest;
} else if (recent.getAttachment() != null) {
String digest = null;
if (getCallback() != null) {
digest = getCallback().getDigestOfAttachment(recent, recent.getAttachment());
}
if (digest == null) {
digest = getDefaultDigest(recent.getAttachment(), recent);
}
return digest;
}
return "";
}
// SDK本身只记录原始数据第三方APP可根据自己实际需求在最近联系人列表上显示缩略消息
// 以下为一些常见消息类型的示例。
private String getDefaultDigest(MsgAttachment attachment, RecentContact recent) {
switch (recent.getMsgType()) {
case text:
return recent.getContent();
case image:
return "[图片]";
case video:
return "[视频]";
case audio:
return "[语音消息]";
case location:
return "[位置]";
case file:
return "[文件]";
case tip:
List<String> uuids = new ArrayList<>();
uuids.add(recent.getRecentMessageId());
List<IMMessage> messages = NIMClient.getService(MsgService.class).queryMessageListByUuidBlock(uuids);
if (messages != null && messages.size() > 0) {
return messages.get(0).getContent();
}
return "[通知提醒]";
case notification:
return TeamNotificationHelper.getTeamNotificationText(recent.getContactId(),
recent.getFromAccount(),
(NotificationAttachment) recent.getAttachment());
case avchat:
// AVChatAttachment avchat = (AVChatAttachment) attachment;
// if (avchat.getState() == AVChatRecordState.Missed && !recent.getFromAccount().equals(NimUIKit.getAccount())) {
// // 未接通话请求
// StringBuilder sb = new StringBuilder("[未接");
// if (avchat.getType() == AVChatType.VIDEO) {
// sb.append("视频电话]");
// } else {
// sb.append("音频电话]");
// }
// return sb.toString();
// } else if (avchat.getState() == AVChatRecordState.Success) {
// StringBuilder sb = new StringBuilder();
// if (avchat.getType() == AVChatType.VIDEO) {
// sb.append("[视频电话]: ");
// } else {
// sb.append("[音频电话]: ");
// }
// sb.append(TimeUtil.secToTime(avchat.getDuration()));
// return sb.toString();
// } else {
// if (avchat.getType() == AVChatType.VIDEO) {
// return ("[视频电话]");
// } else {
// return ("[音频电话]");
// }
// }
case robot:
return "[机器人消息]";
case custom:
if (attachment instanceof CustomAttachment) {
CustomAttachment customAttachment = (CustomAttachment) attachment;
switch (customAttachment.getFirst()) {
case CustomAttachment.CUSTOM_MSG_ASSISTANT_MSG:
AssistantAttachment monsterAwardAttachment = (AssistantAttachment) attachment;
switch (monsterAwardAttachment.getSecond()) {
case CustomAttachment.CUSTOM_MSG_ASSISTANT_COMMON_MSG:
return monsterAwardAttachment.title;
}
break;
case CustomAttachment.CUSTOM_MSG_LEVEL_UP:
return "[升级信息]";
case CustomAttachment.CUSTOM_MSG_NEWBIE:
NewbieHelloAttachment newbieHelloAttachment = (NewbieHelloAttachment) attachment;
return newbieHelloAttachment.getNewbieHelloInfo().message;
}
}
default:
return "[自定义消息] ";
}
}
}

View File

@@ -198,15 +198,6 @@ public class RoomMsgRecentContactsFragment extends TFragment {
}
}
@Override
public String getDigestOfAttachment(RecentContact recentContact, MsgAttachment attachment) {
return null;
}
@Override
public String getDigestOfTipMsg(RecentContact recent) {
return null;
}
};
}

View File

@@ -202,95 +202,6 @@ public class RoomMsgRecentListFragment extends BaseFragment {
}
}
@Override
public String getDigestOfAttachment(RecentContact recent, MsgAttachment attachment) {
if (attachment instanceof CustomAttachment) {
CustomAttachment customAttachment = (CustomAttachment) attachment;
if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI) {
return "您关注的TA上线啦快去围观吧~~~";
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_GIFT) {
return "[礼物]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_NOTICE) {
NoticeAttachment noticeAttachment = (NoticeAttachment) attachment;
return noticeAttachment.getTitle();
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_PACKET) {
RedPacketAttachment redPacketAttachment = (RedPacketAttachment) attachment;
return "您收到一个" + redPacketAttachment.getRedPacketInfo().getPacketName() + "红包哦!";
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_LOTTERY) {
return "恭喜您,获得抽奖机会";
} else if (customAttachment.getFirst() == CUSTOM_MESS_HEAD_NOBLE) {
NobleAttachment nobleAttachment = (NobleAttachment) attachment;
return "提示:" + nobleAttachment.msg;
} else if (customAttachment.getFirst() == CUSTOM_MESS_HEAD_CAR) {
return ((CarAttachment) attachment).msg;
} else if (customAttachment.getFirst() == CUSTOM_MSG_ASSISTANT_MSG) {
return ((AssistantAttachment) attachment).title;
} else if (customAttachment.getFirst() == CUSTOM_MSG_NEWBIE) {
return ((NewbieHelloAttachment) attachment).getNewbieHelloInfo().message;
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_SHARE_IN_APP) {
switch (customAttachment.getSecond()) {
case CUSTOM_MSG_SHARE_ROOM:
return "[分享房间]";
case CUSTOM_MSG_SHARE_FAMILY:
return "[分享家族]";
case CUSTOM_MSG_SHARE_TEAM:
return "[分享群组]";
case CUSTOM_MSG_SHARE_MINI_WORLD:
return "[分享话题]";
}
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_LUCKY_MONEY) {
switch (customAttachment.getSecond()) {
case CUSTOM_MSG_SUB_TYPE_SEND_LUCKY_MONEY:
return "[您收到了一个群红包]";
case CUSTOM_MSG_SUB_TYPE_RECEIVE_LUCKY_MONEY:
LuckyMoneyTipsAttachment luckyMoneyTipsAttachment = (LuckyMoneyTipsAttachment) attachment;
String currentUid = String.valueOf(AuthModel.get().getCurrentUid());
LuckyMoneyInfo luckyMoneyInfo = luckyMoneyTipsAttachment.getLuckyMoneyInfo();
String senderUid = String.valueOf(luckyMoneyInfo.getSenderUid());
String receiverUid = luckyMoneyInfo.getReceiveUid();
if (Objects.equals(currentUid, senderUid)) {
return "[" + luckyMoneyInfo.getReceiveNick() + "领取了你的红包]";
} else if (Objects.equals(currentUid, receiverUid)) {
return "[你领取了" + luckyMoneyInfo.getNick() + "的红包]";
} else {
return "[" + luckyMoneyInfo.getReceiveNick() + "领取了" + luckyMoneyInfo.getNick() + "的红包]";
}
}
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_COMMON_SYSTEM_MSG
|| customAttachment.getFirst() == CUSTOM_MSG_SHIFT_OUT
|| customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_COMMON_SYSTEM_MSG_V2) {
return "[您收到一条系统消息]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_SHARE_IN_APP) {
return "[您收到一条分享消息]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_PUBLIC_CHAT_HALL) {
switch (customAttachment.getSecond()) {
case CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_AIT_ME:
AitMeAttachment aitMeAttachment = (AitMeAttachment) customAttachment;
AitMeInfo aitMeInfo = aitMeAttachment.getAitMeInfo();
return aitMeInfo.getContent();
}
return "[您收到一条公聊大厅相关消息]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_MODULE_HALL) {
return "[您收到一条房间消息]";
} else if (customAttachment instanceof SysMsgVoiceAttachment) {
return "[声音瓶子审核消息]";
} else if (customAttachment instanceof ChatHintAttachment) {
return "[风险提示]";
}
} else if (attachment instanceof AudioAttachment) {
return "[语音]";
}
return null;
}
@Override
public String getDigestOfTipMsg(RecentContact recent) {
return null;
}
});
}

View File

@@ -1,10 +1,63 @@
package com.yizhuan.xchat_android_core.helper;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_HEAD_CAR;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MESS_HEAD_NOBLE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_ASSISTANT_MSG;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_COMMON_SYSTEM_MSG;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_LOTTERY;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_LUCKY_MONEY;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_NOTICE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_PACKET;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_HEADER_TYPE_SHARE_IN_APP;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_MODULE_HALL;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_NEWBIE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_PUBLIC_CHAT_HALL;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_RED_PACKAGE;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SHARE_FAMILY;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SHARE_ROOM;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SHARE_TEAM;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SHIFT_OUT;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_AIT_ME;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_TYPE_RECEIVE_LUCKY_MONEY;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_MSG_SUB_TYPE_SEND_LUCKY_MONEY;
import androidx.annotation.NonNull;
import com.netease.nim.uikit.business.session.helper.TeamNotificationHelper;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.chatroom.ChatRoomMessageBuilder;
import com.netease.nimlib.sdk.chatroom.model.ChatRoomMessage;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.attachment.AudioAttachment;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.attachment.NotificationAttachment;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import com.netease.nimlib.sdk.msg.model.RecentContact;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.community.im.WorldDynamicAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.AssistantAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.CarAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.CarveUpGoldThirdLevelAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.ChatHintAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.ImTipAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.LuckyMoneyTipsAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.MatchAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.NewbieHelloAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.NobleAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.NoticeAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.RedPacketAttachment;
import com.yizhuan.xchat_android_core.im.custom.bean.SysMsgVoiceAttachment;
import com.yizhuan.xchat_android_core.luckymoney.LuckyMoneyInfo;
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager;
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
import com.yizhuan.xchat_android_core.public_chat_hall.attachment.AitMeAttachment;
import com.yizhuan.xchat_android_core.public_chat_hall.bean.AitMeInfo;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import io.reactivex.Single;
@@ -27,4 +80,144 @@ public class ImHelperUtils {
return IMNetEaseManager.get().sendChatRoomMessage(message, false);
}
/**
* 定义消息收到后显示的文案
*
* @param recent
* @return
*/
public static String getMsgDigest(@NonNull RecentContact recent) {
MsgAttachment attachment = recent.getAttachment();
switch (recent.getMsgType()) {
case text:
return recent.getContent();
case image:
return "[图片]";
case video:
return "[视频]";
case audio:
return "[语音消息]";
case location:
return "[位置]";
case file:
return "[文件]";
case tip:
List<String> uuids = new ArrayList<>();
uuids.add(recent.getRecentMessageId());
List<IMMessage> messages = NIMClient.getService(MsgService.class).queryMessageListByUuidBlock(uuids);
if (messages != null && messages.size() > 0) {
return messages.get(0).getContent();
}
return "[通知提醒]";
case notification:
return TeamNotificationHelper.getTeamNotificationText(recent.getContactId(),
recent.getFromAccount(),
(NotificationAttachment) recent.getAttachment());
case robot:
return "你收到一条消息...";
case custom:
if (attachment instanceof CustomAttachment) {
CustomAttachment customAttachment = (CustomAttachment) attachment;
if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_OPEN_ROOM_NOTI) {
return "您关注的TA上线啦快去围观吧~~~";
} else if (customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_IM_TIP) {
ImTipAttachment imTipAttachment = (ImTipAttachment) attachment;
return imTipAttachment.getMsg();
} else if (customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_TYPE_GIFT) {
return "[礼物]";
} else if (customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_IM_GAME) {
return "[游戏邀请]";
} else if (customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_LEVEL_UP) {
return "[升级信息]";
} else if (customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_MATCH) {
MatchAttachment matchAttachment = (MatchAttachment) attachment;
return matchAttachment.getContent();
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_NOTICE) {
NoticeAttachment noticeAttachment = (NoticeAttachment) attachment;
return noticeAttachment.getTitle();
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_PACKET) {
RedPacketAttachment redPacketAttachment = (RedPacketAttachment) attachment;
return "您收到一个" + redPacketAttachment.getRedPacketInfo().getPacketName() + "红包哦!";
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_LOTTERY) {
return "恭喜您,获得抽奖机会";
} else if (customAttachment.getFirst() == CUSTOM_MESS_HEAD_NOBLE) {
NobleAttachment nobleAttachment = (NobleAttachment) attachment;
return "提示:" + nobleAttachment.msg;
} else if (customAttachment.getFirst() == CUSTOM_MESS_HEAD_CAR) {
return ((CarAttachment) attachment).msg;
} else if (customAttachment.getFirst() == CUSTOM_MSG_ASSISTANT_MSG) {
return ((AssistantAttachment) attachment).title;
} else if (customAttachment.getFirst() == CUSTOM_MSG_NEWBIE) {
return ((NewbieHelloAttachment) attachment).getNewbieHelloInfo().message;
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_SHARE_IN_APP) {
switch (customAttachment.getSecond()) {
case CUSTOM_MSG_SHARE_ROOM:
return "[分享房间]";
case CUSTOM_MSG_SHARE_FAMILY:
return "[分享家族]";
case CUSTOM_MSG_SHARE_TEAM:
return "[分享群组]";
default:
return "[您收到一条分享消息]";
}
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_TYPE_LUCKY_MONEY) {
switch (customAttachment.getSecond()) {
case CUSTOM_MSG_SUB_TYPE_SEND_LUCKY_MONEY:
return "[您收到了一个群红包]";
case CUSTOM_MSG_SUB_TYPE_RECEIVE_LUCKY_MONEY:
LuckyMoneyTipsAttachment luckyMoneyTipsAttachment = (LuckyMoneyTipsAttachment) attachment;
String currentUid = String.valueOf(AuthModel.get().getCurrentUid());
LuckyMoneyInfo luckyMoneyInfo = luckyMoneyTipsAttachment.getLuckyMoneyInfo();
String senderUid = String.valueOf(luckyMoneyInfo.getSenderUid());
String receiverUid = luckyMoneyInfo.getReceiveUid();
if (Objects.equals(currentUid, senderUid)) {
return "[" + luckyMoneyInfo.getReceiveNick() + "领取了你的红包]";
} else if (Objects.equals(currentUid, receiverUid)) {
return "[你领取了" + luckyMoneyInfo.getNick() + "的红包]";
} else {
return "[" + luckyMoneyInfo.getReceiveNick() + "领取了" + luckyMoneyInfo.getNick() + "的红包]";
}
}
} else if (customAttachment.getFirst() == CUSTOM_MSG_HEADER_COMMON_SYSTEM_MSG
|| customAttachment.getFirst() == CUSTOM_MSG_SHIFT_OUT
|| customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_HEADER_COMMON_SYSTEM_MSG_V2) {
return "[您收到一条系统消息]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_PUBLIC_CHAT_HALL) {
switch (customAttachment.getSecond()) {
case CUSTOM_MSG_SUB_PUBLIC_CHAT_HALL_AIT_ME:
AitMeAttachment aitMeAttachment = (AitMeAttachment) customAttachment;
AitMeInfo aitMeInfo = aitMeAttachment.getAitMeInfo();
return aitMeInfo.getContent();
}
return "[您收到一条公聊大厅相关消息]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_MODULE_HALL) {
return "[您收到一条公会消息]";
} else if (customAttachment.getFirst() == CustomAttachment.CUSTOM_MSG_SIGN_IN
&& customAttachment.getSecond() == CustomAttachment.CUSTOM_MSG_SUB_JUMP_SIGN_IN_ACTIVITY) {
return "[签到提醒]";
} else if (customAttachment instanceof CarveUpGoldThirdLevelAttachment) {
return "[签到瓜分百万]";
} else if (customAttachment instanceof SysMsgVoiceAttachment) {
return "[声音瓶子审核消息]";
} else if (WorldDynamicAttachment.isShareMsg(customAttachment)) {
return "[分享一条动态]";
} else if (customAttachment.getFirst() == CUSTOM_MSG_RED_PACKAGE) {
return "[您收到一个全服红包]";
} else if (customAttachment instanceof ChatHintAttachment) {
return "[风险提示]";
}
} else if (attachment instanceof AudioAttachment) {
return "[语音]";
}
default:
return "你收到一条消息";
}
}
}

View File

@@ -1,6 +1,5 @@
package com.netease.nim.uikit.business.recent;
import com.netease.nimlib.sdk.msg.attachment.MsgAttachment;
import com.netease.nimlib.sdk.msg.model.RecentContact;
/**
@@ -27,20 +26,4 @@ public interface RecentContactsCallback {
*/
void onItemClick(RecentContact recent);
/**
* 设置自定义消息的摘要信息,展示在最近联系人列表的消息缩略栏上.
* 当然,你也可以自定义一些内建消息的缩略语,例如图片,语音,音视频会话等,自定义的缩略语会被优先使用。
*
* @param attachment 消息附件对象
* @return 消息摘要
*/
String getDigestOfAttachment(RecentContact recent, MsgAttachment attachment);
/**
* 设置Tip消息的摘要信息展示在最近联系人列表的消息缩略栏上
*
* @param recent 最近联系人
* @return Tip消息摘要
*/
String getDigestOfTipMsg(RecentContact recent);
}

View File

@@ -1,55 +0,0 @@
package com.netease.nim.uikit.business.recent.adapter;
import androidx.recyclerview.widget.RecyclerView;
import com.netease.nim.uikit.R;
import com.netease.nim.uikit.business.recent.RecentContactsCallback;
import com.netease.nim.uikit.business.recent.holder.CommonRecentViewHolder;
import com.netease.nim.uikit.business.recent.holder.TeamRecentViewHolder;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseMultiItemQuickAdapter;
import com.netease.nim.uikit.common.ui.recyclerview.holder.BaseViewHolder;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.RecentContact;
import java.util.List;
/**
* Created by huangjun on 2016/12/11.
*/
public class RecentContactAdapter extends BaseMultiItemQuickAdapter<RecentContact, BaseViewHolder> {
interface ViewType {
int VIEW_TYPE_COMMON = 1;
int VIEW_TYPE_TEAM = 2;
}
private RecentContactsCallback callback;
public RecentContactAdapter(RecyclerView recyclerView, List<RecentContact> data) {
super(recyclerView, data);
addItemType(ViewType.VIEW_TYPE_COMMON, R.layout.nim_recent_contact_list_item, CommonRecentViewHolder.class);
addItemType(ViewType.VIEW_TYPE_TEAM, R.layout.nim_recent_contact_list_item, TeamRecentViewHolder.class);
}
@Override
protected int getViewType(RecentContact item) {
return item.getSessionType() == SessionTypeEnum.Team ? ViewType.VIEW_TYPE_TEAM : ViewType.VIEW_TYPE_COMMON;
}
@Override
protected String getItemKey(RecentContact item) {
StringBuilder sb = new StringBuilder();
sb.append(item.getSessionType().getValue()).append("_").append(item.getContactId());
return sb.toString();
}
public RecentContactsCallback getCallback() {
return callback;
}
public void setCallback(RecentContactsCallback callback) {
this.callback = callback;
}
}

View File

@@ -1,58 +0,0 @@
package com.netease.nim.uikit.business.recent.holder;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseQuickAdapter;
import com.netease.nim.uikit.impl.NimUIKitImpl;
import com.netease.nimlib.sdk.msg.constant.MsgTypeEnum;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.RecentContact;
public class CommonRecentViewHolder extends RecentViewHolder {
CommonRecentViewHolder(BaseQuickAdapter adapter) {
super(adapter);
}
@Override
protected String getContent(RecentContact recent) {
return descOfMsg(recent);
}
@Override
protected String getOnlineStateContent(RecentContact recent) {
if (recent.getSessionType() == SessionTypeEnum.P2P && NimUIKitImpl.enableOnlineState()) {
return NimUIKitImpl.getOnlineStateContentProvider().getSimpleDisplay(recent.getContactId());
} else {
return super.getOnlineStateContent(recent);
}
}
String descOfMsg(RecentContact recent) {
if (recent.getMsgType() == MsgTypeEnum.text) {
return recent.getContent();
} else if (recent.getMsgType() == MsgTypeEnum.tip) {
String digest = null;
if (getCallback() != null) {
digest = getCallback().getDigestOfTipMsg(recent);
}
if (digest == null) {
digest = NimUIKitImpl.getRecentCustomization().getDefaultDigest(recent);
}
return digest;
} else if (recent.getAttachment() != null) {
String digest = null;
if (getCallback() != null) {
digest = getCallback().getDigestOfAttachment(recent, recent.getAttachment());
}
if (digest == null) {
digest = NimUIKitImpl.getRecentCustomization().getDefaultDigest(recent);
}
return digest;
}
return "[未知]";
}
}

View File

@@ -1,227 +0,0 @@
package com.netease.nim.uikit.business.recent.holder;
import android.graphics.drawable.AnimationDrawable;
import android.os.Handler;
import android.text.TextUtils;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;
import com.netease.nim.uikit.R;
import com.netease.nim.uikit.api.NimUIKit;
import com.netease.nim.uikit.business.recent.RecentContactsCallback;
import com.netease.nim.uikit.business.recent.adapter.RecentContactAdapter;
import com.netease.nim.uikit.business.session.emoji.MoonUtil;
import com.netease.nim.uikit.business.uinfo.UserInfoHelper;
import com.netease.nim.uikit.common.ui.drop.DropFake;
import com.netease.nim.uikit.common.ui.drop.DropManager;
import com.netease.nim.uikit.common.ui.imageview.HeadImageView;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseQuickAdapter;
import com.netease.nim.uikit.common.ui.recyclerview.holder.BaseViewHolder;
import com.netease.nim.uikit.common.ui.recyclerview.holder.RecyclerViewHolder;
import com.netease.nim.uikit.common.util.sys.ScreenUtil;
import com.netease.nim.uikit.common.util.sys.TimeUtil;
import com.netease.nimlib.sdk.msg.constant.MsgStatusEnum;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.RecentContact;
import com.netease.nimlib.sdk.team.model.Team;
public abstract class RecentViewHolder extends RecyclerViewHolder<BaseQuickAdapter, BaseViewHolder, RecentContact> {
public RecentViewHolder(BaseQuickAdapter adapter) {
super(adapter);
}
private int lastUnreadCount = 0;
protected FrameLayout portraitPanel;
protected HeadImageView imgHead;
protected TextView tvNickname;
protected TextView tvMessage;
protected TextView tvDatetime;
// 消息发送错误状态标记,目前没有逻辑处理
protected ImageView imgMsgStatus;
protected View bottomLine;
protected View topLine;
// 未读红点(一个占坑,一个全屏动画)
protected DropFake tvUnread;
private ImageView imgUnreadExplosion;
protected TextView tvOnlineState;
// 子类覆写
protected abstract String getContent(RecentContact recent);
@Override
public void convert(BaseViewHolder holder, RecentContact data, int position, boolean isScrolling) {
inflate(holder, data);
refresh(holder, data, position);
}
public void inflate(BaseViewHolder holder, final RecentContact recent) {
this.portraitPanel = holder.getView(R.id.portrait_panel);
this.imgHead = holder.getView(R.id.img_head);
this.tvNickname = holder.getView(R.id.tv_nickname);
this.tvMessage = holder.getView(R.id.tv_message);
this.tvUnread = holder.getView(R.id.unread_number_tip);
this.imgUnreadExplosion = holder.getView(R.id.unread_number_explosion);
this.tvDatetime = holder.getView(R.id.tv_date_time);
this.imgMsgStatus = holder.getView(R.id.img_msg_status);
this.bottomLine = holder.getView(R.id.bottom_line);
this.topLine = holder.getView(R.id.top_line);
this.tvOnlineState = holder.getView(R.id.tv_online_state);
holder.addOnClickListener(R.id.unread_number_tip);
this.tvUnread.setTouchListener(new DropFake.ITouchListener() {
@Override
public void onDown() {
DropManager.getInstance().setCurrentId(recent);
DropManager.getInstance().down(tvUnread, tvUnread.getText());
}
@Override
public void onMove(float curX, float curY) {
DropManager.getInstance().move(curX, curY);
}
@Override
public void onUp() {
DropManager.getInstance().up();
}
});
}
public void refresh(BaseViewHolder holder, RecentContact recent, final int position) {
// unread count animation
boolean shouldBoom = lastUnreadCount > 0 && recent.getUnreadCount() == 0; // 未读数从N->0执行爆裂动画;
lastUnreadCount = recent.getUnreadCount();
updateBackground(holder, recent, position);
loadPortrait(recent);
updateNickLabel(UserInfoHelper.getUserTitleName(recent.getContactId(), recent.getSessionType()));
updateOnlineState(recent);
updateMsgLabel(holder, recent);
updateNewIndicator(recent);
if (shouldBoom) {
Object o = DropManager.getInstance().getCurrentId();
if (o instanceof String && o.equals("0")) {
imgUnreadExplosion.setImageResource(R.drawable.nim_explosion);
imgUnreadExplosion.setVisibility(View.VISIBLE);
new Handler().post(new Runnable() {
@Override
public void run() {
((AnimationDrawable) imgUnreadExplosion.getDrawable()).start();
// 解决部分手机动画无法播放的问题(例如华为荣耀)
getAdapter().notifyItemChanged(getAdapter().getViewHolderPosition(position));
}
});
}
} else {
imgUnreadExplosion.setVisibility(View.GONE);
}
}
private void updateBackground(BaseViewHolder holder, RecentContact recent, int position) {
topLine.setVisibility(getAdapter().isFirstDataItem(position) ? View.GONE : View.VISIBLE);
bottomLine.setVisibility(getAdapter().isLastDataItem(position) ? View.VISIBLE : View.GONE);
if ((recent.getTag() & 1) == 0) {
holder.getConvertView().setBackgroundResource(R.drawable.nim_touch_bg);
} else {
holder.getConvertView().setBackgroundResource(R.drawable.nim_recent_contact_sticky_selecter);
}
}
protected void loadPortrait(RecentContact recent) {
// 设置头像
if (recent.getSessionType() == SessionTypeEnum.P2P) {
imgHead.loadBuddyAvatar(recent.getContactId());
} else if (recent.getSessionType() == SessionTypeEnum.Team) {
Team team = NimUIKit.getTeamProvider().getTeamById(recent.getContactId());
imgHead.loadTeamIconByTeam(team);
}
}
protected void updateNewIndicator(RecentContact recent) {
int unreadNum = recent.getUnreadCount();
tvUnread.setVisibility(unreadNum > 0 ? View.VISIBLE : View.GONE);
tvUnread.setText(unreadCountShowRule(unreadNum));
}
private void updateMsgLabel(BaseViewHolder holder, RecentContact recent) {
// 显示消息具体内容
MoonUtil.identifyRecentVHFaceExpressionAndTags(holder.getContext(), tvMessage, getContent(recent), -1, 0.45f);
//tvMessage.setText(getContent());
MsgStatusEnum status = recent.getMsgStatus();
switch (status) {
case fail:
imgMsgStatus.setImageResource(R.drawable.nim_g_ic_failed_small);
imgMsgStatus.setVisibility(View.VISIBLE);
break;
case sending:
imgMsgStatus.setImageResource(R.drawable.nim_recent_contact_ic_sending);
imgMsgStatus.setVisibility(View.VISIBLE);
break;
default:
imgMsgStatus.setVisibility(View.GONE);
break;
}
String timeString = TimeUtil.getTimeShowString(recent.getTime(), true);
tvDatetime.setText(timeString);
}
protected String getOnlineStateContent(RecentContact recent) {
return "";
}
protected void updateOnlineState(RecentContact recent) {
if (recent.getSessionType() == SessionTypeEnum.Team) {
tvOnlineState.setVisibility(View.GONE);
} else {
String onlineStateContent = getOnlineStateContent(recent);
if (TextUtils.isEmpty(onlineStateContent)) {
tvOnlineState.setVisibility(View.GONE);
} else {
tvOnlineState.setVisibility(View.VISIBLE);
tvOnlineState.setText(getOnlineStateContent(recent));
}
}
}
protected void updateNickLabel(String nick) {
int labelWidth = ScreenUtil.screenWidth;
labelWidth -= ScreenUtil.dip2px(50 + 70); // 减去固定的头像和时间宽度
if (labelWidth > 0) {
tvNickname.setMaxWidth(labelWidth);
}
tvNickname.setText(nick);
}
protected String unreadCountShowRule(int unread) {
unread = Math.min(unread, 99);
return String.valueOf(unread);
}
protected RecentContactsCallback getCallback() {
return ((RecentContactAdapter) getAdapter()).getCallback();
}
}

View File

@@ -1,44 +0,0 @@
package com.netease.nim.uikit.business.recent.holder;
import android.text.TextUtils;
import com.netease.nim.uikit.api.NimUIKit;
import com.netease.nim.uikit.business.recent.TeamMemberAitHelper;
import com.netease.nim.uikit.business.team.helper.TeamHelper;
import com.netease.nim.uikit.common.ui.recyclerview.adapter.BaseQuickAdapter;
import com.netease.nimlib.sdk.msg.attachment.NotificationAttachment;
import com.netease.nimlib.sdk.msg.model.RecentContact;
public class TeamRecentViewHolder extends CommonRecentViewHolder {
public TeamRecentViewHolder(BaseQuickAdapter adapter) {
super(adapter);
}
@Override
protected String getContent(RecentContact recent) {
String content = descOfMsg(recent);
String fromId = recent.getFromAccount();
if (!TextUtils.isEmpty(fromId)
&& !fromId.equals(NimUIKit.getAccount())
&& !(recent.getAttachment() instanceof NotificationAttachment)) {
String tid = recent.getContactId();
String teamNick = getTeamUserDisplayName(tid, fromId);
content = teamNick + ": " + content;
if (TeamMemberAitHelper.hasAitExtension(recent)) {
if (recent.getUnreadCount() == 0) {
TeamMemberAitHelper.clearRecentContactAited(recent);
} else {
content = TeamMemberAitHelper.getAitAlertString(content);
}
}
}
return content;
}
private String getTeamUserDisplayName(String tid, String account) {
return TeamHelper.getTeamMemberDisplayName(tid, account);
}
}