添加用戶刷新機制

This commit is contained in:
18401019693 2022-09-07 15:12:26 +08:00
parent a4007e555b
commit 5df1b21551

View File

@ -5,6 +5,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils; import android.text.TextUtils;
import android.view.View; import android.view.View;
@ -29,7 +30,6 @@ import com.yunbao.main.utils.PDLiveCustomConversationProvider;
import com.yunbao.main.utils.PDLiveMessageProcessor; import com.yunbao.main.utils.PDLiveMessageProcessor;
import com.yunbao.main.utils.PDSightMessageItemProvider; import com.yunbao.main.utils.PDSightMessageItemProvider;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import io.rong.imkit.IMCenter; import io.rong.imkit.IMCenter;
@ -45,7 +45,6 @@ import io.rong.imkit.utils.RouteUtils;
import io.rong.imkit.widget.adapter.ProviderManager; import io.rong.imkit.widget.adapter.ProviderManager;
import io.rong.imlib.RongIMClient; import io.rong.imlib.RongIMClient;
import io.rong.imlib.model.Conversation; import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.MessageContent;
import io.rong.imlib.model.UserInfo; import io.rong.imlib.model.UserInfo;
import io.rong.sight.SightExtensionModule; import io.rong.sight.SightExtensionModule;
@ -57,6 +56,7 @@ public class ConversationIMListManager {
private Context mContext; private Context mContext;
//指导员ID //指导员ID
private String targetId; private String targetId;
private Handler conversationIMListHandler = new Handler();
private ConversationIMListManager(Context context) { private ConversationIMListManager(Context context) {
mContext = context; mContext = context;
@ -174,12 +174,15 @@ public class ConversationIMListManager {
} }
private String mUserId;
/** /**
* 获取用户信息 * 获取用户信息
* *
* @param userId * @param userId
*/ */
private void addUserInfoProvider(String userId, Activity context) { private void addUserInfoProvider(String userId, Activity context) {
mUserId = userId;
//获取用户信息 //获取用户信息
UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(userId); UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(userId);
if (null != userInfo) { if (null != userInfo) {
@ -187,33 +190,39 @@ public class ConversationIMListManager {
Conversation.ConversationType type = Conversation.ConversationType.PRIVATE; Conversation.ConversationType type = Conversation.ConversationType.PRIVATE;
RouteUtils.routeToConversationActivity(context, type, userId, null); RouteUtils.routeToConversationActivity(context, type, userId, null);
}); });
} else { }
CommonHttpUtil.getUserBaseinfo(userId, new HttpCallback() { conversationIMListHandler.post(getUserBaseinfoRunnable);
}
/**
* 刷新用戶信息
*/
private Runnable getUserBaseinfoRunnable = new Runnable() {
@Override
public void run() {
CommonHttpUtil.getUserBaseinfo(mUserId, 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 && !TextUtils.equals("__system__", userId)) { if (code == 0 && info.length > 0 && !TextUtils.equals("__system__", mUserId)) {
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(mUserId);
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(mUserId, userNiceName, Uri.parse(userBean.getAvatar()));
//使用空白字段存储自己服务器用户的所有的信息 //使用空白字段存储自己服务器用户的所有的信息
userInfo.setExtra(GsonUtils.toJson(userBean)); userInfo.setExtra(GsonUtils.toJson(userBean));
RongUserInfoManager.getInstance().setUserInfoProvider(s -> { RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo);
RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo); if (TextUtils.equals(userBean.getIs_admin(), "1")) {
if (TextUtils.equals(userBean.getIs_admin(), "1")) { targetId = mUserId;
targetId = userId; setConversationToTop(userInfo.getUserId());
setConversationToTop(userInfo.getUserId()); }
}
return null;
}, true);
} }
} }
@ -221,9 +230,7 @@ public class ConversationIMListManager {
} }
}); });
} }
};
}
/** /**
* 消息置顶 * 消息置顶