修复聊天页面卡顿问题

This commit is contained in:
zlzw 2024-08-16 10:44:20 +08:00
parent 3143ec2be4
commit cfb5a5aac2
20 changed files with 131 additions and 34 deletions

View File

@ -29,6 +29,7 @@ import com.facebook.appevents.AppEventsLogger;
import com.fm.openinstall.OpenInstall;
import com.google.gson.Gson;
import com.pandoralive.shayu.R;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.LogUtils;
import com.tencent.imsdk.v2.V2TIMGroupMemberInfo;
import com.yunbao.common.http.Data;
@ -482,7 +483,7 @@ public class AppContext extends CommonAppContext {
NeverCrashUtils.getInstance().setDebugMode(BuildConfig.DEBUG).setMainCrashHandler((t, e) -> {
Log.e("ApplicationError", "主线程异常");//此处log只是展示当debug为true时主类内部log会打印异常信息
e.printStackTrace();
AppManager.runDebugCode(() -> {
DebugUtils.runDebugCode(() -> {
//闪退后finish所有Activity并且杀死进程
for (WeakReference<Activity> activity : activities) {
if (activity != null && activity.get() != null) {

View File

@ -10,6 +10,7 @@ import android.widget.Toast;
import com.yunbao.common.bean.CrashSaveBean;
import com.yunbao.common.utils.AppManager;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.FileUtil;
import com.yunbao.common.utils.SpUtil;
@ -105,10 +106,10 @@ public class NeverCrashUtils {
}
e.printStackTrace();
AppContext.setFirebaseCrashData();
AppManager.runDebugCode(() -> Toast.makeText(application, "发生闪退:" + e.getMessage(), Toast.LENGTH_SHORT).show());
DebugUtils.runDebugCode(() -> Toast.makeText(application, "发生闪退:" + e.getMessage(), Toast.LENGTH_SHORT).show());
FileUtil.saveStringToFile(new File(application.getDir("files", Context.MODE_PRIVATE).getAbsolutePath()), throwableToString(e), "error.log");
getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e);
AppManager.runDebugCode(() -> errorWhile = false);
DebugUtils.runDebugCode(() -> errorWhile = false);
// return;
}
}

View File

@ -13,6 +13,7 @@ import android.widget.TextView;
import androidx.annotation.NonNull;
import com.blankj.utilcode.util.LogUtils;
import com.yunbao.common.R;
import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.interfaces.OnRecyclerListRefreshListener;
@ -145,12 +146,12 @@ public class MainConversationListAdapter extends ConversationListAdapter {
} else if (holder.getView(R.id.rc_conversation_date) != null) {
holder.getView(R.id.rc_conversation_date).setVisibility(View.GONE);
}
if("0".equals(conversation.mCore.getDraft())){
holder.setImageDrawable(R.id.rc_conversation_live_online_icon,mContext.getResources().getDrawable(R.mipmap.msg_online));
holder.setText(R.id.rc_conversation_live_online,WordUtil.isNewZh()?"在線":"Online");
}else{
holder.setImageDrawable(R.id.rc_conversation_live_online_icon,mContext.getResources().getDrawable(R.mipmap.msg_off));
holder.setText(R.id.rc_conversation_live_online,WordUtil.isNewZh()?"離線":"Offline");
if ("0".equals(conversation.mCore.getDraft())) {
holder.setImageDrawable(R.id.rc_conversation_live_online_icon, mContext.getResources().getDrawable(R.mipmap.msg_online));
holder.setText(R.id.rc_conversation_live_online, WordUtil.isNewZh() ? "在線" : "Online");
} else {
holder.setImageDrawable(R.id.rc_conversation_live_online_icon, mContext.getResources().getDrawable(R.mipmap.msg_off));
holder.setText(R.id.rc_conversation_live_online, WordUtil.isNewZh() ? "離線" : "Offline");
}
if (holder.getView(R.id.rc_conversation_live_status) == null || IMLoginManager.get(holder.getContext()).getAnchorB() != 1) {
return;
@ -187,8 +188,11 @@ public class MainConversationListAdapter extends ConversationListAdapter {
}
}
private int listHashCode = 0;
@Override
public void setDataCollection(List<BaseUiConversation> data) {
public synchronized void setDataCollection(List<BaseUiConversation> data) {
if (data.hashCode() == listHashCode) return;
listHashCode = data.hashCode();
List<BaseUiConversation> tmp = new ArrayList<>();
Log.i("聊天数据源", "setDataCollection: " + data.hashCode());
List<String> urls = new ArrayList<>();
@ -219,8 +223,11 @@ public class MainConversationListAdapter extends ConversationListAdapter {
}
urls.add(item.mCore.getTargetId());
Log.i("聊天数据源", item.mCore.getConversationTitle() + "|" + item.mCore.getPortraitUrl() + "|" + item.mCore.getTargetId());
if (!tmpUids.contains(item.mCore.getTargetId())) {
BaseUiConversation cn = new SingleConversation(mContext, item.mCore);
srcList.add(cn);
tmpUids.add(item.mCore.getTargetId());
}
if (item.mCore.getConversationType() == Conversation.ConversationType.PRIVATE) {
if (item.mCore.getLatestMessage() instanceof MessageChatCardContent) {
@ -233,6 +240,8 @@ public class MainConversationListAdapter extends ConversationListAdapter {
super.setDataCollection(tmp);
}
private List<String> tmpUids = new ArrayList<>();
public void clear() {
mDataList.clear();
if (srcList != null) {

View File

@ -143,7 +143,7 @@ public abstract class AbsMainMessageChatListFragment extends Fragment {
isNet = true;
for (BaseUiConversation conversation : srcList) {
map.put(conversation.mCore.getTargetId(), conversation);
if (conversation.mCore.getConversationType() == Conversation.ConversationType.PRIVATE) {
if (conversation.mCore.getConversationType() == Conversation.ConversationType.PRIVATE&& !conversation.mCore.getTargetId().equals("__system__")) {
uids.add(conversation.mCore.getTargetId());
}
}

View File

@ -543,6 +543,13 @@ public class LiveHttpUtil {
HttpClient.getInstance().get("Live.getGiftListApp", LiveHttpConsts.GET_GIFT_LIST)
.execute(callback);
}
/**
* 获取礼物列表同时会返回剩余的钱新版 -用于获取联系方式时的礼物设置
*/
public static void getHotGiftList(HttpCallback callback) {
HttpClient.getInstance().get("Gift.getHotGiftList", LiveHttpConsts.GET_GIFT_LIST)
.execute(callback);
}
/**
* 获取包裹列表

View File

@ -123,6 +123,7 @@ public class InstructorRemarkManager extends BaseCacheManager {
@Override
public void run() {
IMLoginModel userInfo = IMLoginManager.get(context).getUserInfo();
if(userInfo==null)return;
HttpClient.getInstance().get("User.getInstructorRemark", "getInstructorRemark")
.params("uid", userInfo.getId(), true)
.params("token", userInfo.getToken(), true)

View File

@ -0,0 +1,19 @@
package com.yunbao.common.manager.imrongcloud;
import java.lang.reflect.Method;
import io.rong.imkit.userinfo.RongUserInfoManager;
import io.rong.imlib.model.UserInfo;
public class PDRongUserInfoManager {
public static void saveUserInfo(UserInfo userInfo) {
RongUserInfoManager instance = RongUserInfoManager.getInstance();
try {
Method method = instance.getClass().getDeclaredMethod("saveUserInfoCache", userInfo.getClass());
method.setAccessible(true);
method.invoke(instance, userInfo);
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -179,14 +179,6 @@ public class AppManager {
activityStack.clear();
}
/**
* 仅在debug下运行的代码
*/
public static void runDebugCode(Runnable runnable) {
if (BuildConfig.DEBUG) {
runnable.run();
}
}
/**

View File

@ -0,0 +1,30 @@
package com.yunbao.common.utils;
import android.util.Log;
import com.yunbao.common.BuildConfig;
public class DebugUtils {
/**
* 打印堆栈信息
*/
public static void showStackTrace(){
StackTraceElement[] stackTrace = new Throwable().getStackTrace();
StringBuilder sb=new StringBuilder();
for (StackTraceElement element : stackTrace) {
if(element!=null){
sb.append(element).append("\n");
}
}
Log.e("DebugUtils",sb.toString());
}
/**
* 仅在debug下运行的代码
*/
public static void runDebugCode(Runnable runnable) {
if (BuildConfig.DEBUG) {
runnable.run();
}
}
}

View File

@ -4,7 +4,7 @@ ext {
buildToolsVersion: "29.0.2",
minSdkVersion : 23,
targetSdkVersion : 34,
versionCode : 546,
versionCode : 550,
versionName : "6.8.0",
namespace : "com.pandoralive.shayu"
]

View File

@ -176,6 +176,7 @@ public class LiveAnchorEditCallMeAdapter extends RecyclerView.Adapter<LiveAnchor
public void onDismiss() {
}
})
.setHotGiftListUrl(true)
.setShowNumber(false)
.setTitle(mContext.getString(R.string.live_anchor_edit_call_me_select_gift))
.setHideGiftType(true)

View File

@ -62,7 +62,12 @@ public class GiftPopDialog extends AbsDialogPopupWindow implements ActionListene
private TextView mTitle;
private boolean isOldGiftList = false;
private boolean hideGiftType = false;
private boolean isHotGiftListUrl = false;
public GiftPopDialog setHotGiftListUrl(boolean hotGiftListUrl) {
isHotGiftListUrl = hotGiftListUrl;
return this;
}
public GiftPopDialog(@NonNull Context context) {
super(context);
@ -183,6 +188,25 @@ public class GiftPopDialog extends AbsDialogPopupWindow implements ActionListene
}
}
@Override
public void onFinish() {
if (mLoading != null) {
mLoading.setVisibility(View.INVISIBLE);
}
}
});
} else if (isHotGiftListUrl) {
LiveHttpUtil.getHotGiftList(new HttpCallback() {
@Override
public void onSuccess(int code, String msg, String[] info) {
if (code == 0 && info.length > 0) {
JSONObject obj = JSON.parseObject(info[0]);
JSONArray list = obj.getJSONArray("listarray");
setDate(list);
}
}
@Override
public void onFinish() {
if (mLoading != null) {

View File

@ -62,6 +62,7 @@ import com.yunbao.common.interfaces.OnItemClickListener;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.utils.AppManager;
import com.yunbao.common.utils.Bus;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.GiftCacheUtil;
@ -1092,7 +1093,7 @@ public class LiveGiftDialogFragment extends AbsDialogFragment implements View.On
Bus.get().post(event);
}).build().show();
AppManager.runDebugCode(() -> {
DebugUtils.runDebugCode(() -> {
Log.i("gifBean", mLiveGiftBean.toString());
});
} else if (code == 1001) {

View File

@ -44,6 +44,7 @@ import com.opensource.svgaplayer.SVGADrawable;
import com.opensource.svgaplayer.SVGAImageView;
import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.MobclickAgent;
import com.yunbao.common.CommonAppConfig;
@ -1432,7 +1433,7 @@ public class LiveGiftPopup extends AbsDialogFragment {
Bus.get().post(event);
}).build().show();
AppManager.runDebugCode(() -> {
DebugUtils.runDebugCode(() -> {
Log.i("gifBean", mGiftBean.toString());
});
} else if (code == 1001) {

View File

@ -70,6 +70,7 @@ import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;
import com.yunbao.common.bean.PrankProgressBean;
import com.yunbao.common.fragment.GiftWallMainTab1Fragment;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.MobclickAgent;
import com.yunbao.common.CommonAppConfig;
@ -2360,7 +2361,7 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
if (!IMLoginManager.get(mContext).hintChat()) {
msgLayout.setVisibility(View.VISIBLE);
}
AppManager.runDebugCode(() -> msgLayout.setVisibility(View.GONE));
DebugUtils.runDebugCode(() -> msgLayout.setVisibility(View.GONE));
if (d_pk_view != null) {
d_pk_view.setVisibility(View.GONE);
}

View File

@ -33,6 +33,7 @@ import com.lzf.easyfloat.permission.PermissionUtils;
import com.lzf.easyfloat.utils.LifecycleUtils;
import com.yunbao.common.event.LiveMsgWindowsCloseEvent;
import com.yunbao.common.manager.imrongcloud.RongcloudIMManager;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.MobclickAgent;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext;
@ -287,7 +288,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
liveImDeletUtil = new LiveImDeletUtil();
portraitLiveManager = this;
ininView();
AppManager.runDebugCode(() -> waitShowTopBannerTime = 1000);
DebugUtils.runDebugCode(() -> waitShowTopBannerTime = 1000);
}
/**
@ -875,7 +876,7 @@ public class PortraitLiveManager implements LivePlayListener, SocketMessageListe
}
}
//liveHandler.postDelayed(loadTimeoutRunnableGone, 15_000);
AppManager.runDebugCode(() -> {
DebugUtils.runDebugCode(() -> {
liveHandler.postDelayed(loadTimeoutRunnableGone, 1_000);
});
liveHandler.postDelayed(loadTimeoutRunnableGone, 4_000);

View File

@ -15,6 +15,7 @@ import com.yunbao.common.glide.ImgLoader;
import com.yunbao.common.http.base.HttpCallback;
import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.utils.AppManager;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.RouteUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
@ -94,7 +95,7 @@ public class MainMsgAddressBookListAdapter extends BaseAdapter<MessageChatUserBe
}
holder.getConvertView().setTag(mDataList.get(position));
holder.getConvertView().setOnClickListener(view -> {
AppManager.runDebugCode(new Runnable() {
DebugUtils.runDebugCode(new Runnable() {
@Override
public void run() {
MessageChatUserBean userBean = (MessageChatUserBean) view.getTag();

View File

@ -22,6 +22,7 @@ import android.widget.LinearLayout;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.MobclickAgent;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.CommonAppContext;
@ -317,7 +318,7 @@ public class MainStartDialogFragment extends AbsDialogFragment implements View.O
if (isWifiProxy(mContext) || checkVPN((ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE))) {
ToastUtil.show(WordUtil.isNewZh()?"檢測開啓了VPN或者代理請先關閉VPN或者代理再開播。":
"It is detected that VPN or proxy is turned on. Please turn off VPN or proxy before starting the broadcast.");
AppManager.runDebugCode(() -> mCallback.onLiveClick());
DebugUtils.runDebugCode(() -> mCallback.onLiveClick());
} else {
if (mCallback != null) {
MobclickAgent.onEvent(mContext, "home_page_broadcast", "点击开播按钮");

View File

@ -18,6 +18,7 @@ import com.yunbao.common.http.live.LiveNetManager;
import com.yunbao.common.interfaces.OnRecyclerListRefreshListener;
import com.yunbao.common.manager.IMLoginManager;
import com.yunbao.common.manager.InstructorRemarkManager;
import com.yunbao.common.manager.imrongcloud.PDRongUserInfoManager;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.common.utils.ToastUtil;
import com.yunbao.common.utils.WordUtil;
@ -135,7 +136,7 @@ public class MainMessageChatListSystemFragment extends AbsMainMessageChatListFra
@Override
public void onChatList() {
if(mAdapter==null) return;
if (mAdapter == null) return;
mAdapter.setChat();
init();
}
@ -233,6 +234,7 @@ public class MainMessageChatListSystemFragment extends AbsMainMessageChatListFra
@Override
public void onSuccess(List<MessageChatUserBean> data) {
List<BaseUiConversation> list = new ArrayList<>();
UserInfo userInfo=null;
for (MessageChatUserBean datum : data) {
Conversation conversation = new Conversation();
BaseUiConversation baseUiConversation = new SingleConversation(getContext(), conversation);
@ -247,10 +249,11 @@ public class MainMessageChatListSystemFragment extends AbsMainMessageChatListFra
list.add(baseUiConversation);
UserInfo userInfo = new UserInfo(baseUiConversation.mCore.getTargetId(),
userInfo = new UserInfo(baseUiConversation.mCore.getTargetId(),
baseUiConversation.mCore.getConversationTitle(),
Uri.parse(baseUiConversation.mCore.getPortraitUrl()));
RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo);
// RongUserInfoManager.getInstance().refreshUserInfoCache(userInfo);
PDRongUserInfoManager.saveUserInfo(userInfo);
}
if (!list.isEmpty()) {
List<BaseUiConversation> srcList = new ArrayList<>(mAdapter.getSrcList());

View File

@ -50,6 +50,7 @@ import com.opensource.svgaplayer.SVGAParser;
import com.opensource.svgaplayer.SVGAVideoEntity;
import com.yunbao.common.CommonAppConfig;
import com.yunbao.common.fragment.MainMessageRecommendFragment;
import com.yunbao.common.utils.DebugUtils;
import com.yunbao.common.utils.DialogUitl;
import com.yunbao.common.utils.DpUtil;
import com.yunbao.common.utils.MobclickAgent;
@ -339,7 +340,9 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
@Override
public void onPageSelected(int position) {
super.onPageSelected(position);
if(!StringUtil.isEmpty(search.getText().toString())) {
search.setText("");
}
selectTab(position);
}
});
@ -508,7 +511,7 @@ public class MainMessageViewHolder extends AbsMainViewHolder {
LiveNetManager.get(mContext).getIsAnchor(new com.yunbao.common.http.base.HttpCallback<MessageChatIsAnchor>() {
@Override
public void onSuccess(MessageChatIsAnchor data) {
AppManager.runDebugCode(() -> {
DebugUtils.runDebugCode(() -> {
more.setVisibility(View.VISIBLE);
});
if (data.getIsAnchor() == 1 && CommonAppConfig.getInstance().getUserBean().getUsers_type().equals("C")) {