add:新增全局异常捕获类,暂未启用,有调试需要时可以在AppContext调用
fix:修复周榜、观众来回切换在网络慢的情况下会闪退的问题 fix:优化观众列表切换内容在网络慢的情况下有数据残留的问题 update:根据需求恢复在线守护列表到观众列表中 update:根据需求点击守护icon直接到守护列表
This commit is contained in:
parent
ac53f7b219
commit
1028e39555
@ -101,6 +101,8 @@ public class AppContext extends CommonAppContext {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
//注册全局异常捕获
|
||||
//registerError();
|
||||
sInstance = this;
|
||||
L.setDeBug(BuildConfig.DEBUG);
|
||||
AppEventsLogger.activateApp(this);
|
||||
@ -238,4 +240,21 @@ public class AppContext extends CommonAppContext {
|
||||
RongcloudIMManager.removeRongcloudIMOnReceiveMessageListener();
|
||||
super.onTerminate();
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册全局异常捕获,有需要时可以在onCreate调用
|
||||
*/
|
||||
private void registerError(){
|
||||
NeverCrashUtils.getInstance()
|
||||
.setDebugMode(BuildConfig.DEBUG)
|
||||
.setMainCrashHandler((t, e) -> {
|
||||
Log.e("ApplicationError", "主线程异常");//此处log只是展示,当debug为true时,主类内部log会打印异常信息
|
||||
e.printStackTrace();
|
||||
})
|
||||
.setUncaughtCrashHandler((t, e) -> {
|
||||
Log.e("ApplicationError", "子线程异常");//此处log只是展示,当debug为true时,主类内部log会打印异常信息
|
||||
e.printStackTrace();
|
||||
})
|
||||
.register(this);
|
||||
}
|
||||
}
|
||||
|
110
app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java
Normal file
110
app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java
Normal file
@ -0,0 +1,110 @@
|
||||
package com.shayu.phonelive;
|
||||
import android.app.Application;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* @ClassName NeverCrashUtils
|
||||
* @Description 全局捕获异常
|
||||
*/
|
||||
public class NeverCrashUtils {
|
||||
|
||||
private final static String TAG = NeverCrashUtils.class.getSimpleName();
|
||||
private final static NeverCrashUtils INSTANCE = new NeverCrashUtils();
|
||||
|
||||
private boolean debugMode;
|
||||
private MainCrashHandler mainCrashHandler;
|
||||
private UncaughtCrashHandler uncaughtCrashHandler;
|
||||
|
||||
private NeverCrashUtils() {
|
||||
}
|
||||
|
||||
public static NeverCrashUtils getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private synchronized MainCrashHandler getMainCrashHandler() {
|
||||
if (null == mainCrashHandler) {
|
||||
mainCrashHandler = (t, e) -> {
|
||||
};
|
||||
}
|
||||
return mainCrashHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主线程发生异常时的回调,可用于打印日志文件
|
||||
* <p>
|
||||
* 注意跨线程操作的可能
|
||||
*/
|
||||
public NeverCrashUtils setMainCrashHandler(MainCrashHandler mainCrashHandler) {
|
||||
mainCrashHandler = mainCrashHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
private synchronized UncaughtCrashHandler getUncaughtCrashHandler() {
|
||||
if (null == uncaughtCrashHandler) {
|
||||
uncaughtCrashHandler = (t, e) -> {
|
||||
};
|
||||
}
|
||||
return uncaughtCrashHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* 子线程发生异常时的回调,可用于打印日志文件
|
||||
* <p>
|
||||
* 注意跨线程操作的可能
|
||||
*/
|
||||
public NeverCrashUtils setUncaughtCrashHandler(UncaughtCrashHandler uncaughtCrashHandler) {
|
||||
this.uncaughtCrashHandler = uncaughtCrashHandler;
|
||||
return this;
|
||||
}
|
||||
|
||||
private boolean isDebugMode() {
|
||||
return debugMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* debug模式,会打印log日志,且toast提醒发生异常,反之则都没有
|
||||
*/
|
||||
public NeverCrashUtils setDebugMode(boolean debugMode) {
|
||||
this.debugMode = debugMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 完成监听异常的注册
|
||||
* @param application application
|
||||
*/
|
||||
public void register(Application application) {
|
||||
//主线程异常拦截
|
||||
new Handler(Looper.getMainLooper()).post(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
Looper.loop();
|
||||
} catch (Throwable e) {
|
||||
if (isDebugMode()) {
|
||||
Log.e(TAG, "未捕获的主线程异常行为", e);
|
||||
}
|
||||
getMainCrashHandler().mainException(Looper.getMainLooper().getThread(), e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//子线程异常拦截
|
||||
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
|
||||
if (isDebugMode()) {
|
||||
Log.e(TAG, "未捕获的子线程异常行为", e);
|
||||
}
|
||||
getUncaughtCrashHandler().uncaughtException(t, e);
|
||||
});
|
||||
}
|
||||
|
||||
public interface MainCrashHandler {
|
||||
void mainException(Thread t, Throwable e);
|
||||
}
|
||||
|
||||
public interface UncaughtCrashHandler {
|
||||
void uncaughtException(Thread t, Throwable e);
|
||||
}
|
||||
}
|
@ -332,8 +332,11 @@ public class LiveUserMoreDialogFragment extends AbsDialogFragment implements Vie
|
||||
}
|
||||
|
||||
void Up() {
|
||||
userMoreInfoAdapter.clearData();
|
||||
bottom_msg.setVisibility(View.VISIBLE);
|
||||
title.setVisibility(View.GONE);
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) mRefreshView.getLayoutParams();
|
||||
params.bottomMargin=DpUtil.dp2px(65);
|
||||
if (Tips.equals("1")) {
|
||||
tags.setText("開通貴族,尊享超多特權!");
|
||||
btn.setBackgroundResource(R.mipmap.btn_openvip);
|
||||
@ -361,6 +364,7 @@ public class LiveUserMoreDialogFragment extends AbsDialogFragment implements Vie
|
||||
type = "fans";
|
||||
no_more.setImageResource(R.mipmap.bixin);
|
||||
}else if(Tips.equals("4")){
|
||||
params.bottomMargin=DpUtil.dp2px(0);
|
||||
userMoreInfoAdapter.type = "4";
|
||||
bottom_msg.setVisibility(View.GONE);
|
||||
type="dayRank";
|
||||
@ -368,6 +372,7 @@ public class LiveUserMoreDialogFragment extends AbsDialogFragment implements Vie
|
||||
gz_view.setVisibility(View.GONE);
|
||||
no_more.setImageResource(R.drawable.img_rank_empty);
|
||||
}else if (Tips.equals("5")){
|
||||
params.bottomMargin=DpUtil.dp2px(0);
|
||||
userMoreInfoAdapter.type = "5";
|
||||
bottom_msg.setVisibility(View.GONE);
|
||||
type="weekRank";
|
||||
@ -375,6 +380,7 @@ public class LiveUserMoreDialogFragment extends AbsDialogFragment implements Vie
|
||||
no_more.setImageResource(R.drawable.img_rank_empty);
|
||||
setTextColor(weekRank,audience_btn,guard_btn,fans_btn,gz_view,dayRank);
|
||||
}
|
||||
mRefreshView.setLayoutParams(params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user