diff --git a/app/src/main/java/com/shayu/phonelive/AppContext.java b/app/src/main/java/com/shayu/phonelive/AppContext.java index d08d84b24..9e8a813e1 100644 --- a/app/src/main/java/com/shayu/phonelive/AppContext.java +++ b/app/src/main/java/com/shayu/phonelive/AppContext.java @@ -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); + } } diff --git a/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java new file mode 100644 index 000000000..bf9b557c4 --- /dev/null +++ b/app/src/main/java/com/shayu/phonelive/NeverCrashUtils.java @@ -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; + } + + /** + * 主线程发生异常时的回调,可用于打印日志文件 + *
+ * 注意跨线程操作的可能 + */ + public NeverCrashUtils setMainCrashHandler(MainCrashHandler mainCrashHandler) { + mainCrashHandler = mainCrashHandler; + return this; + } + + private synchronized UncaughtCrashHandler getUncaughtCrashHandler() { + if (null == uncaughtCrashHandler) { + uncaughtCrashHandler = (t, e) -> { + }; + } + return uncaughtCrashHandler; + } + + /** + * 子线程发生异常时的回调,可用于打印日志文件 + *
+ * 注意跨线程操作的可能
+ */
+ 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);
+ }
+}
\ No newline at end of file
diff --git a/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java b/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java
index eea5cf065..a565bc090 100644
--- a/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java
+++ b/live/src/main/java/com/yunbao/live/dialog/LiveUserMoreDialogFragment.java
@@ -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);
}
/**
diff --git a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java
index 47157cf4f..a0a00f18d 100644
--- a/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java
+++ b/live/src/main/java/com/yunbao/live/views/LiveRoomViewHolder.java
@@ -1478,7 +1478,8 @@ public class LiveRoomViewHolder extends AbsViewHolder implements View.OnClickLis
} else if (i == R.id.ft_hot_add) {
((LiveActivity) mContext).openHotListWindow(1);
} else if (i == R.id.user_guard) {
- ((LiveActivity) mContext).openUserMoreListWindow(2, true);
+ // ((LiveActivity) mContext).openUserMoreListWindow(2, true);
+ ((LiveActivity) mContext).openGuardListWindow();
}
}
diff --git a/live/src/main/res/layout/dialog_user_more_list.xml b/live/src/main/res/layout/dialog_user_more_list.xml
index 21e4ea6ed..e04a0f272 100644
--- a/live/src/main/res/layout/dialog_user_more_list.xml
+++ b/live/src/main/res/layout/dialog_user_more_list.xml
@@ -73,7 +73,7 @@
android:text="@string/live_guard"
android:textColor="#ff646464"
android:textSize="16sp"
- android:visibility="gone" />
+ android:visibility="visible" />