فهرست منبع

0.0.48.beta26
- 修复特定设备下存在的关于 PopNotification 以及 PopTip 内存泄漏异常;

Kongzue 2 سال پیش
والد
کامیت
e6f37b4f42

+ 3 - 0
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopNotification.java

@@ -556,6 +556,9 @@ public class PopNotification extends BaseDialog implements NoTouchInterface {
                     if (popNotificationList != null) {
                         popNotificationList.remove(PopNotification.this);
                     }
+                    if (autoDismissTimer != null) {
+                        autoDismissTimer.cancel();
+                    }
                     isShow = false;
                     getDialogLifecycleCallback().onDismiss(me);
                     PopNotification.this.onDismiss(me);

+ 3 - 0
DialogX/src/main/java/com/kongzue/dialogx/dialogs/PopTip.java

@@ -517,6 +517,9 @@ public class PopTip extends BaseDialog implements NoTouchInterface {
                 public void onDismiss() {
                     if (popTipList != null) popTipList.remove(PopTip.this);
                     isShow = false;
+                    if (autoDismissTimer != null) {
+                        autoDismissTimer.cancel();
+                    }
                     getDialogLifecycleCallback().onDismiss(me);
                     PopTip.this.onDismiss(me);
                     dialogImpl = null;

+ 12 - 11
DialogX/src/main/java/com/kongzue/dialogx/util/views/DialogXBaseRelativeLayout.java

@@ -98,7 +98,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
                 requestFocus();
             }
             setBkgAlpha(0f);
-            if (parentDialog != null && parentDialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW) {
+            if (getParentDialog() != null && getParentDialog().getDialogImplMode() != DialogX.IMPL_MODE.VIEW) {
                 setFitsSystemWindows(true);
             }
             setClipChildren(false);
@@ -108,7 +108,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
 
     @Override
     protected boolean fitSystemWindows(Rect insets) {
-        if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || parentDialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW)) {
+        if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || (getParentDialog() != null && getParentDialog().getDialogImplMode() != DialogX.IMPL_MODE.VIEW))) {
             log("#fitSystemWindows paddingView: b=" + insets.bottom);
             paddingView(insets.left, insets.top, insets.right, insets.bottom);
         }
@@ -118,7 +118,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     @Override
     public WindowInsets dispatchApplyWindowInsets(WindowInsets insets) {
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
-            if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || parentDialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW)) {
+            if (!useWindowInsetsAnimation && (DialogX.useActivityLayoutTranslationNavigationBar || (getParentDialog() != null && getParentDialog().getDialogImplMode() != DialogX.IMPL_MODE.VIEW))) {
                 paddingView(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getSystemWindowInsetBottom());
                 log("#dispatchApplyWindowInsets paddingView: b=" + insets.getSystemWindowInsetBottom());
             }
@@ -168,7 +168,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
 
     @Override
     public boolean onTouchEvent(MotionEvent event) {
-        if (parentDialog instanceof NoTouchInterface){
+        if (getParentDialog() instanceof NoTouchInterface) {
             return super.onTouchEvent(event);
         }
         InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
@@ -188,7 +188,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
             }
             ViewCompat.requestApplyInsets(this);
 
-            if (parentDialog == null || parentDialog.getOwnActivity() == null) return;
+            if (getParentDialog() == null || getParentDialog().getOwnActivity() == null) return;
 
             View decorView = (View) getParent();
             if (decorView != null) {
@@ -270,9 +270,9 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     }
 
     private void getWindowInsetsByDisplayMetrics() {
-        if (parentDialog == null || parentDialog.getOwnActivity() == null) return;
+        if (getParentDialog() == null || getParentDialog().getOwnActivity() == null) return;
         DisplayMetrics displayMetrics = new DisplayMetrics();
-        parentDialog.getOwnActivity().getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
+        getParentDialog().getOwnActivity().getWindowManager().getDefaultDisplay().getRealMetrics(displayMetrics);
         Rect rect = new Rect();
         View decorView = (View) getParent();
         decorView.getWindowVisibleDisplayFrame(rect);
@@ -292,6 +292,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
         }
         getDynamicWindowInsetsAnimationListener(parentKey).remove(dynamicWindowInsetsAnimationListener);
         onSafeInsetsChangeListener = null;
+        parentDialog = null;
         super.onDetachedFromWindow();
     }
 
@@ -324,7 +325,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
 
     @Override
     public boolean requestFocus(int direction, Rect previouslyFocusedRect) {
-        if (parentDialog != null && parentDialog instanceof NoTouchInterface) {
+        if (getParentDialog() == null || getParentDialog() instanceof NoTouchInterface) {
             return false;
         }
         if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
@@ -425,7 +426,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
 
     public DialogXBaseRelativeLayout setParentDialog(BaseDialog parentDialog) {
         this.parentDialog = parentDialog;
-        if (parentDialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW) {
+        if (parentDialog!=null && parentDialog.getDialogImplMode() != DialogX.IMPL_MODE.VIEW) {
             setFitsSystemWindows(true);
             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                 paddingView(getRootWindowInsets());
@@ -440,7 +441,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
     protected void onConfigurationChanged(Configuration newConfig) {
         super.onConfigurationChanged(newConfig);
         boolean newLightStatus = ((newConfig.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO);
-        if (isLightMode != newLightStatus && DialogX.globalTheme == DialogX.THEME.AUTO) {
+        if (isLightMode != newLightStatus && DialogX.globalTheme == DialogX.THEME.AUTO && getParentDialog()!=null) {
             getParentDialog().restartDialog();
         }
     }
@@ -524,7 +525,7 @@ public class DialogXBaseRelativeLayout extends RelativeLayout {
 
     protected void log(String s) {
         if (debugMode) {
-            Log.e(">>>", s);
+            Log.e(">>>" , s);
         }
     }
 }

+ 11 - 2
app/src/main/java/com/kongzue/dialogxdemo/activity/MainActivity.java

@@ -1271,14 +1271,23 @@ public class MainActivity extends BaseActivity {
             @Override
             public void onClick(View v) {
                 notificationIndex++;
-                PopNotification.show("这是一条消息 " + notificationIndex)
+                PopNotification.build()
+                        .setMessage("这是一条消息 " + notificationIndex)
                         .setOnPopNotificationClickListener(new OnDialogButtonClickListener<PopNotification>() {
                             @Override
                             public boolean onClick(PopNotification dialog, View v) {
                                 TipDialog.show("点击了通知");
                                 return false;
                             }
-                        });
+                        })
+                        .showLong();
+
+                runDelayed(new Runnable() {
+                    @Override
+                    public void run() {
+                        finish();
+                    }
+                },500);
             }
         });
 

+ 1 - 1
gradle.properties

@@ -19,6 +19,6 @@ android.useAndroidX=true
 # Automatically convert third-party libraries to use AndroidX
 android.enableJetifier=true
 
-BUILD_VERSION=0.0.48.beta25
+BUILD_VERSION=0.0.48.beta26
 BUILD_VERSION_INT=47
 DIALOGX_STYLE_VERSION=5