修复 [反餽問題]

This commit is contained in:
zlzw 2024-04-03 16:11:57 +08:00
parent fb81ca8c54
commit 088868201d
6 changed files with 89 additions and 9 deletions

View File

@ -1,7 +1,9 @@
package com.yunbao.share.ui;
import android.content.Context;
import android.net.Uri;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.EditText;
@ -9,20 +11,28 @@ import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lxj.xpopup.XPopup;
import com.pdlive.shayu.R;
import com.yunbao.common.bean.UserBean;
import com.yunbao.common.dialog.AbsDialogFullScreenPopupWindow;
import com.yunbao.common.dialog.DebugDialog;
import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.manager.InstructorRemarkManager;
import com.yunbao.common.utils.AppManager;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.share.adapters.InternalShareAdapter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import io.rong.imkit.conversationlist.model.SingleConversation;
import io.rong.imkit.userinfo.RongUserInfoManager;
import io.rong.imkit.widget.refresh.SmartRefreshLayout;
import io.rong.imkit.widget.refresh.api.RefreshLayout;
import io.rong.imkit.widget.refresh.listener.OnLoadMoreListener;
@ -32,6 +42,7 @@ import io.rong.imlib.IRongCoreCallback;
import io.rong.imlib.IRongCoreEnum;
import io.rong.imlib.RongCoreClient;
import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.UserInfo;
public class AppInternalShareDialog extends AbsDialogFullScreenPopupWindow {
EditText search;
@ -151,22 +162,72 @@ public class AppInternalShareDialog extends AbsDialogFullScreenPopupWindow {
private void refreshData() {
RongCoreClient.getInstance().getConversationListByPage(new IRongCoreCallback.ResultCallback<List<Conversation>>() {
boolean isNeedData = false;
List<String> needUidList = new ArrayList<>();
@Override
public void onSuccess(List<Conversation> conversations) {
isNeedData = false;
needUidList.clear();
if (conversations.isEmpty()) {
mRefreshLayout.finishLoadMoreWithNoMoreData();
return;
}
List<SingleConversation> tmp = new ArrayList<>();
for (Conversation conversation : conversations) {
if(conversation.getTargetId().contains("__system__")){
continue;
}
if (StringUtil.isEmpty(conversation.getPortraitUrl())) {
isNeedData = true;
needUidList.add(conversation.getTargetId());
continue;
}
tmp.add(new SingleConversation(getContext(), conversation));
}
if (isNeedData) {
checkUserData();
return;
}
startTime = conversations.get(conversations.size() - 1).getSentTime();
listData.addAll(tmp);
adapter.setList(listData);
mRefreshLayout.finishRefresh(true);
}
private void checkUserData() {
Iterator<String> iterator = needUidList.iterator();
while (iterator.hasNext()) {
String userId = iterator.next();
CommonHttpUtil.getUserBaseinfo(userId, new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0 && !TextUtils.equals("__system__", userId)) {
JSONObject obj = JSON.parseObject(info[0]);
UserBean userBean = JSON.toJavaObject(obj, UserBean.class);
needUidList.remove(userBean.getId());
UserInfo userInfo = new UserInfo(userBean.getId(), userBean.getUserNiceName(), Uri.parse(userBean.getAvatar()));
userInfo.setExtra(obj.toString());
RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo);
Conversation conversation=new Conversation();
conversation.setTargetId(userBean.getId());
conversation.setConversationTitle(userBean.getUserNiceName());
conversation.setPortraitUrl(userBean.getAvatar());
SingleConversation singleConversation = new SingleConversation(getContext(), conversation);
listData.add(singleConversation);
if (needUidList.isEmpty()) {
adapter.setList(listData);
mRefreshLayout.finishRefresh(true);
}
} else {
Log.i("刷新用户", "3>" + code + "|" + msg + "|" + info.length);
}
}
});
}
}
@Override
public void onError(IRongCoreEnum.CoreErrorCode e) {
ToastUtil.show("出错了:" + e.getMessage());

View File

@ -6,4 +6,14 @@ import com.yunbao.common.bean.BaseModel;
* 融云连接状态监听通知
*/
public class RongIMConnectionStatusEvent extends BaseModel {
private int status;
public int getStatus() {
return status;
}
public RongIMConnectionStatusEvent setStatus(int status) {
this.status = status;
return this;
}
}

View File

@ -190,13 +190,14 @@ public class RongcloudIMManager {
break;
//用户账号在其它设备登录此设备被踢下线
case KICKED_OFFLINE_BY_OTHER_CLIENT:
EventBus.getDefault().post(new RongIMConnectionStatusEvent());
EventBus.getDefault().post(new RongIMConnectionStatusEvent().setStatus(-1));
break;
//连接暂时挂起多是由于网络问题导致SDK 会在合适时机进行自动重连
case SUSPEND:
break;
//连接成功
case CONNECTED:
EventBus.getDefault().post(new RongIMConnectionStatusEvent().setStatus(1));
break;
//连接超时SDK 将停止连接用户需要做超时处理再自行调用连接接口进行连接
case TIMEOUT:

View File

@ -1438,9 +1438,13 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
*/
@Subscribe(threadMode = ThreadMode.MAIN)
public void userSignOut(RongIMConnectionStatusEvent model) {
IMLoginManager.get(mContext).logout(this);
CommonAppConfig.getInstance().clearLoginInfo();
LoginActivity.forward();
if(model.getStatus()==-1) {
IMLoginManager.get(mContext).logout(this);
CommonAppConfig.getInstance().clearLoginInfo();
LoginActivity.forward();
}else if(model.getStatus()==1){
ConversationIMListManager.get(mContext).addUserInfoProvider();
}
}
/**

View File

@ -55,7 +55,7 @@ public class MessageStatusConfigDialog extends AbsDialogCenterPopupWindow {
.setOpenOff(status, new HttpCallback<List<BaseModel>>() {
@Override
public void onSuccess(List<BaseModel> data) {
ToastUtil.show("成功");
ToastUtil.show(WordUtil.isNewZh()?"成功":"Success");
dismiss();
UserInfoManager.updateMyInfo(mContext, null);
}

View File

@ -11,6 +11,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import com.alibaba.fastjson.JSON;
@ -29,14 +30,16 @@ import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
import com.yunbao.live.activity.PDLIiveChatActivity;
import com.yunbao.main.activity.PDLiveConversationActivity;
import com.yunbao.live.bean.SearchUserBean;
import com.yunbao.live.dialog.PDLIiveChatConversationFragment;
import com.yunbao.main.R;
import com.yunbao.main.activity.PDLiveConversationActivity;
import com.yunbao.main.activity.PDLiveConversationListActivity;
import com.yunbao.main.dialog.MsgChatClickDialog;
import com.yunbao.main.utils.PDLiveCustomConversationProvider;
import com.yunbao.main.utils.PDLiveMessageProcessor;
import com.yunbao.main.utils.PDSightMessageItemProvider;
import com.yunbao.main.views.MessageChatExtensionConfig;
import java.util.Arrays;
import java.util.List;
@ -58,9 +61,6 @@ import io.rong.imlib.model.Conversation;
import io.rong.imlib.model.UserInfo;
import io.rong.sight.SightExtensionModule;
import com.yunbao.main.R;
import com.yunbao.main.views.MessageChatExtensionConfig;
/**
* 会话列表管理
*/
@ -157,12 +157,14 @@ public class ConversationIMListManager {
*/
public void addUserInfoProvider() {
RongUserInfoManager.getInstance().setUserInfoProvider(userId -> {
Log.i("刷新用户", "1>" + userId);
CommonHttpUtil.getUserBaseinfo(userId, new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0 && !TextUtils.equals("__system__", userId)) {
JSONObject obj = JSON.parseObject(info[0]);
SearchUserBean userBean = JSON.toJavaObject(obj, SearchUserBean.class);
Log.i("刷新用户2", "2>" + userBean.getId() + "|" + userId + "|" + userBean.getAvatar());
String userNiceName = "";
String remark = InstructorRemarkManager.get(mContext).getInstructorRemark().get(userId);
if (!TextUtils.isEmpty(remark)) {
@ -180,6 +182,8 @@ public class ConversationIMListManager {
}
}
} else {
Log.i("刷新用户", "3>" + code + "|" + msg + "|" + info.length);
}
}