From 5df1b21551465e2da72acdffb20c823efe8b6770 Mon Sep 17 00:00:00 2001 From: 18401019693 Date: Wed, 7 Sep 2022 15:12:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=94=A8=E6=88=B6=E5=88=B7?= =?UTF-8?q?=E6=96=B0=E6=A9=9F=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ConversationIMListManager.java | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/main/src/main/java/com/yunbao/main/manager/imrongcloud/ConversationIMListManager.java b/main/src/main/java/com/yunbao/main/manager/imrongcloud/ConversationIMListManager.java index 845713d7a..99df2a9aa 100644 --- a/main/src/main/java/com/yunbao/main/manager/imrongcloud/ConversationIMListManager.java +++ b/main/src/main/java/com/yunbao/main/manager/imrongcloud/ConversationIMListManager.java @@ -5,6 +5,7 @@ import android.content.Context; import android.content.Intent; import android.net.Uri; import android.os.Bundle; +import android.os.Handler; import android.text.TextUtils; 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.PDSightMessageItemProvider; -import java.util.ArrayList; import java.util.List; 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.imlib.RongIMClient; import io.rong.imlib.model.Conversation; -import io.rong.imlib.model.MessageContent; import io.rong.imlib.model.UserInfo; import io.rong.sight.SightExtensionModule; @@ -57,6 +56,7 @@ public class ConversationIMListManager { private Context mContext; //指导员ID private String targetId; + private Handler conversationIMListHandler = new Handler(); private ConversationIMListManager(Context context) { mContext = context; @@ -174,12 +174,15 @@ public class ConversationIMListManager { } + private String mUserId; + /** * 获取用户信息 * * @param userId */ private void addUserInfoProvider(String userId, Activity context) { + mUserId = userId; //获取用户信息 UserInfo userInfo = RongUserInfoManager.getInstance().getUserInfo(userId); if (null != userInfo) { @@ -187,33 +190,39 @@ public class ConversationIMListManager { Conversation.ConversationType type = Conversation.ConversationType.PRIVATE; 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 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]); SearchUserBean userBean = JSON.toJavaObject(obj, SearchUserBean.class); String userNiceName = ""; - String remark = InstructorRemarkManager.get(mContext).getInstructorRemark().get(userId); + String remark = InstructorRemarkManager.get(mContext).getInstructorRemark().get(mUserId); if (!TextUtils.isEmpty(remark)) { userNiceName = remark; } else { userNiceName = userBean.getUserNiceName(); } 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)); - RongUserInfoManager.getInstance().setUserInfoProvider(s -> { - RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo); - if (TextUtils.equals(userBean.getIs_admin(), "1")) { - targetId = userId; - setConversationToTop(userInfo.getUserId()); - } - return null; - }, true); - + RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo); + if (TextUtils.equals(userBean.getIs_admin(), "1")) { + targetId = mUserId; + setConversationToTop(userInfo.getUserId()); + } } } @@ -221,9 +230,7 @@ public class ConversationIMListManager { } }); } - - - } + }; /** * 消息置顶