From 41e5fecbeae69e653b2a48de558fdd1125c0e48f Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Thu, 19 Nov 2020 18:49:06 +0900 Subject: [PATCH] Check if view is attached before animating controls. Should fix https://github.com/austinhuang0131/barinsta/issues/302 --- .../instagrabber/fragments/PostViewV2Fragment.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java index a4330185..a2d56916 100644 --- a/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java +++ b/app/src/main/java/awais/instagrabber/fragments/PostViewV2Fragment.java @@ -35,6 +35,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.content.PermissionChecker; +import androidx.core.view.ViewCompat; import androidx.core.widget.NestedScrollView; import androidx.fragment.app.DialogFragment; import androidx.navigation.NavController; @@ -1055,9 +1056,12 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment { private void showPlayerControls() { hideCaption(); - // previously invisible view View view = binding.playerControls.getRoot(); + if (!ViewCompat.isAttachedToWindow(view)) { + view.setVisibility(View.VISIBLE); + return; + } // get the center for the clipping circle int cx = view.getWidth() / 2; // int cy = view.getHeight() / 2; @@ -1078,6 +1082,10 @@ public class PostViewV2Fragment extends SharedElementTransitionDialogFragment { private void hidePlayerControls() { // previously visible view final View view = binding.playerControls.getRoot(); + if (!ViewCompat.isAttachedToWindow(view)) { + view.setVisibility(View.GONE); + return; + } // get the center for the clipping circle int cx = view.getWidth() / 2;