1
0
Эх сурвалжийг харах

0.0.50.beta31 pre
- 修复 FitSystemBarUtils 可能存在的因 OnGlobalLayoutListener 引发的内存泄漏问题;

Kongzue 2 сар өмнө
parent
commit
dd8ff9aec8

+ 2 - 0
DialogX/src/main/java/com/kongzue/dialogx/impl/DialogFragmentImpl.java

@@ -10,6 +10,7 @@ import android.graphics.PixelFormat;
 import android.graphics.drawable.ColorDrawable;
 import android.os.Build;
 import android.os.Bundle;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.MotionEvent;
 import android.view.View;
@@ -79,6 +80,7 @@ public class DialogFragmentImpl extends DialogFragment {
                 for (BaseDialog dialog : BaseDialog.getRunningDialogList()) {
                     if (dialog.getOwnActivity() == activity && dialog != baseDialog && dialog.getDialogImplMode() == baseDialog.getDialogImplMode()) {
                         if (!(dialog instanceof NoTouchInterface) && dialog.getDialogView() != null) {
+                            Log.e(">>>", "onTouch: dialog=" + dialog + "  baseDialog="+baseDialog );
                             dialog.getDialogView().dispatchTouchEvent(event);
                             return true;
                         }

+ 4 - 0
DialogX/src/main/java/com/kongzue/dialogx/util/views/DialogXBaseRelativeLayout.java

@@ -269,6 +269,10 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
         if (onLifecycleCallBack != null) {
             onLifecycleCallBack.onDismiss();
         }
+        if (fitSystemBarUtils != null) {
+            fitSystemBarUtils.recycle();
+        }
+        fitSystemBarUtils = null;
         onSafeInsetsChangeListener = null;
         super.onDetachedFromWindow();
     }

+ 24 - 3
DialogX/src/main/java/com/kongzue/dialogx/util/views/FitSystemBarUtils.java

@@ -51,6 +51,8 @@ public class FitSystemBarUtils {
 
     private CallBack callBack;
 
+    private BaseDialog dialog;
+
     /**
      * 绑定到View
      *
@@ -137,6 +139,9 @@ public class FitSystemBarUtils {
 //        view.setFitsSystemWindows(true);
         contentView = view;
         this.callBack = callBack;
+        if (view instanceof DialogXBaseRelativeLayout) {
+            dialog = ((DialogXBaseRelativeLayout) view).getParentDialog();
+        }
         applyWindowInsets();
     }
 
@@ -517,7 +522,7 @@ public class FitSystemBarUtils {
     }
 
     private boolean isFullScreen() {
-        Activity activity = BaseDialog.getTopActivity();
+        Activity activity = getActivity();
         if (activity == null) {
             return false;
         }
@@ -535,7 +540,7 @@ public class FitSystemBarUtils {
     }
 
     private int checkOrientationAndStatusBarSide() {
-        Activity activity = BaseDialog.getTopActivity();
+        Activity activity = getActivity();
         if (activity == null) {
             return 0;
         }
@@ -563,7 +568,7 @@ public class FitSystemBarUtils {
     private ViewTreeObserver.OnGlobalLayoutListener onGlobalLayoutListener;
 
     private View getDecorView() {
-        Activity activity = BaseDialog.getTopActivity();
+        Activity activity = getActivity();
         if (activity == null) {
             return null;
         }
@@ -612,4 +617,20 @@ public class FitSystemBarUtils {
         }
         return -1;
     }
+
+    private Activity getActivity() {
+        if (dialog == null) return BaseDialog.getTopActivity();
+        return dialog.getOwnActivity();
+    }
+
+    public void recycle() {
+        View decorView = getDecorView();
+        if (decorView != null && onGlobalLayoutListener != null) {
+            decorView.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayoutListener);
+        }
+        onGlobalLayoutListener = null;
+        callBack = null;
+        contentView = null;
+        dialog = null;
+    }
 }

+ 26 - 14
app/src/main/java/com/kongzue/dialogxdemo/activity/MainActivity.java

@@ -592,20 +592,32 @@ public class MainActivity extends BaseActivity {
         btnWaitDialog.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
-                WaitDialog.show("Please Wait!").setOnBackPressedListener(new OnBackPressedListener<WaitDialog>() {
-                    @Override
-                    public boolean onBackPressed(WaitDialog dialog) {
-                        PopTip.show("按下返回").setButton("取消", new OnDialogButtonClickListener<PopTip>() {
-                            @Override
-                            public boolean onClick(PopTip dialog, View v) {
-                                WaitDialog.dismiss();
-                                return false;
-                            }
-                        });
-                        return false;
-                    }
-                });
-                WaitDialog.dismiss(3000);
+//                WaitDialog.show("Please Wait!").setOnBackPressedListener(new OnBackPressedListener<WaitDialog>() {
+//                    @Override
+//                    public boolean onBackPressed(WaitDialog dialog) {
+//                        PopTip.show("按下返回").setButton("取消", new OnDialogButtonClickListener<PopTip>() {
+//                            @Override
+//                            public boolean onClick(PopTip dialog, View v) {
+//                                WaitDialog.dismiss();
+//                                return false;
+//                            }
+//                        });
+//                        return false;
+//                    }
+//                });
+//                WaitDialog.dismiss(3000);
+
+                WaitDialog.build()
+                        .setDialogImplMode(DialogX.IMPL_MODE.DIALOG_FRAGMENT)
+                        .setStyle(MaterialStyle.style())
+                        .setMessageContent("msg")
+                        .show();
+
+                WaitDialog.build()
+                        .setDialogImplMode(DialogX.IMPL_MODE.DIALOG_FRAGMENT)
+                        .setStyle(MaterialStyle.style())
+                        .setMessageContent("msg2")
+                        .show();
             }
         });