添加用戶刷新機制

This commit is contained in:
18401019693 2022-09-07 16:42:53 +08:00
parent 5df1b21551
commit 6c9ac9807f
2 changed files with 46 additions and 48 deletions

View File

@ -110,8 +110,8 @@ public class PDLIiveChatActivity extends FragmentActivity {
private void initData() { private void initData() {
IMLoginManager.get(mContext).checkInstructor(); IMLoginManager.get(mContext).checkInstructor();
//刷新列表内用户信息 // //刷新列表内用户信息
addUserInfoProvider(); // addUserInfoProvider();
//获取一下系统通知 //获取一下系统通知
MessageIMManager.get(this).getSystemMessages(); MessageIMManager.get(this).getSystemMessages();
@ -144,39 +144,39 @@ public class PDLIiveChatActivity extends FragmentActivity {
conversationListFragment.addHeaderView(rootView); conversationListFragment.addHeaderView(rootView);
} }
/** // /**
* 刷新用户信息(异步) // * 刷新用户信息(异步)
*/ // */
public void addUserInfoProvider() { // public void addUserInfoProvider() {
RongUserInfoManager.getInstance().setUserInfoProvider(userId -> { // RongUserInfoManager.getInstance().setUserInfoProvider(userId -> {
CommonHttpUtil.getUserBaseinfo(userId, new HttpCallback() { // CommonHttpUtil.getUserBaseinfo(userId, new HttpCallback() {
@Override // @Override
public void onSuccess(int code, String msg, String[] info) { // public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) { // if (code == 0 && info.length > 0) {
JSONObject obj = JSON.parseObject(info[0]); // JSONObject obj = JSON.parseObject(info[0]);
SearchUserBean userBean = JSON.toJavaObject(obj, SearchUserBean.class); // SearchUserBean userBean = JSON.toJavaObject(obj, SearchUserBean.class);
String userNiceName = ""; // String userNiceName = "";
String remark = InstructorRemarkManager.get(mContext).getInstructorRemark().get(userId); // String remark = InstructorRemarkManager.get(mContext).getInstructorRemark().get(userId);
if (!TextUtils.isEmpty(remark)) { // if (!TextUtils.isEmpty(remark)) {
userNiceName = remark; // userNiceName = remark;
} else { // } else {
userNiceName = userBean.getUserNiceName(); // userNiceName = userBean.getUserNiceName();
} // }
if (!TextUtils.isEmpty(userNiceName) && !TextUtils.isEmpty(userBean.getAvatar())) { // if (!TextUtils.isEmpty(userNiceName) && !TextUtils.isEmpty(userBean.getAvatar())) {
UserInfo userInfo = new UserInfo(userId, userNiceName, Uri.parse(userBean.getAvatar())); // UserInfo userInfo = new UserInfo(userId, userNiceName, Uri.parse(userBean.getAvatar()));
//使用空白字段存储自己服务器用户的所有的信息 // //使用空白字段存储自己服务器用户的所有的信息
userInfo.setExtra(GsonUtils.toJson(userBean)); // userInfo.setExtra(GsonUtils.toJson(userBean));
RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo); // RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo);
} // }
} // }
//
} // }
}); // });
//
return null; // return null;
}, true); // }, true);
//
} // }
@Override @Override
protected void onDestroy() { protected void onDestroy() {

View File

@ -55,12 +55,13 @@ public class PDLiveCustomConversationProvider extends BaseConversationProvider {
public void bindViewHolder(ViewHolder holder, BaseUiConversation uiConversation, int position, List<BaseUiConversation> list, IViewProviderListener<BaseUiConversation> listener) { public void bindViewHolder(ViewHolder holder, BaseUiConversation uiConversation, int position, List<BaseUiConversation> list, IViewProviderListener<BaseUiConversation> listener) {
//根据业务需要自定义处理 //根据业务需要自定义处理
super.bindViewHolder(holder, uiConversation, position, list, listener); super.bindViewHolder(holder, uiConversation, position, list, listener);
String targetId = uiConversation.mCore.getTargetId(); String targetId = uiConversation.mCore.getTargetId();
UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(targetId); UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(targetId);
if (userInfo != null && !TextUtils.isEmpty(userInfo.getExtra())) { if ((userInfo != null && !TextUtils.isEmpty(userInfo.getExtra()))|| TextUtils.equals(userInfo.getName(), "指导员测试")) {
IMLoginModel model = new Gson().fromJson(userInfo.getExtra(), IMLoginModel.class); IMLoginModel model = new Gson().fromJson(userInfo.getExtra(), IMLoginModel.class);
//指导员对话逻辑 //指导员对话逻辑
if (model != null && TextUtils.equals(model.getIsAdmin(), "1")) { if ((model != null && TextUtils.equals(model.getIsAdmin(), "1")) ) {
RelativeLayout conversationItem = holder.getView(R.id.rc_conversation_item); RelativeLayout conversationItem = holder.getView(R.id.rc_conversation_item);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) conversationItem.getLayoutParams(); RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) conversationItem.getLayoutParams();
params.height = DpUtil.dp2px(143); params.height = DpUtil.dp2px(143);
@ -77,10 +78,15 @@ public class PDLiveCustomConversationProvider extends BaseConversationProvider {
holder.setVisible(R.id.administrator_layout, true); holder.setVisible(R.id.administrator_layout, true);
holder.setImageUri(R.id.img_administrator, userInfo.getPortraitUri()); holder.setImageUri(R.id.img_administrator, userInfo.getPortraitUri());
holder.setText(R.id.conversation_title, userInfo.getName()); holder.setText(R.id.conversation_title, userInfo.getName());
if (TextUtils.isEmpty(uiConversation.mConversationContent)){
if (uiConversation.mCore.getLatestMessage() instanceof TextMessage) { if (uiConversation.mCore.getLatestMessage() instanceof TextMessage) {
TextMessage message = (TextMessage) uiConversation.mCore.getLatestMessage(); TextMessage message = (TextMessage) uiConversation.mCore.getLatestMessage();
holder.setText(R.id.conversation_content, message.getContent()); holder.setText(R.id.conversation_content, message.getContent());
} }
}else {
holder.setText(R.id.conversation_content,uiConversation.mConversationContent);
}
if (uiConversation.mCore.getUnreadMessageCount() == 0) { if (uiConversation.mCore.getUnreadMessageCount() == 0) {
holder.setVisible(R.id.conversation_unread, false); holder.setVisible(R.id.conversation_unread, false);
} else { } else {
@ -105,15 +111,7 @@ public class PDLiveCustomConversationProvider extends BaseConversationProvider {
if (conversationUnread != null) { if (conversationUnread != null) {
Glide.with(holder.getContext()).asDrawable().load(R.mipmap.rc_unread_count_bg_normal).into(conversationUnread); Glide.with(holder.getContext()).asDrawable().load(R.mipmap.rc_unread_count_bg_normal).into(conversationUnread);
} }
if (imgNew != null) {
if (userInfo != null && !TextUtils.isEmpty(userInfo.getExtra())) {
IMLoginModel model = new Gson().fromJson(userInfo.getExtra(), IMLoginModel.class);
if (model != null && TextUtils.equals(model.getIsAdmin(), "1"))
Glide.with(holder.getContext()).asDrawable().load("https://downs.yaoulive.com/Instructors.png").into(imgNew);
}
}
readReceipt.setVisibility(View.VISIBLE); readReceipt.setVisibility(View.VISIBLE);
if (RongConfigCenter.featureConfig().isReadReceiptConversationType(Conversation.ConversationType.PRIVATE) && if (RongConfigCenter.featureConfig().isReadReceiptConversationType(Conversation.ConversationType.PRIVATE) &&
uiConversation.mCore.getSenderUserId().equals(RongIMClient.getInstance().getCurrentUserId()) && uiConversation.mCore.getSenderUserId().equals(RongIMClient.getInstance().getCurrentUserId()) &&