From d4a33603ab2755522198bf5f9d7737539fee13c0 Mon Sep 17 00:00:00 2001 From: Stypox Date: Sun, 17 Jan 2021 14:04:07 +0100 Subject: [PATCH] Prevent IllegalArgumentException when closing popup --- .../item/PickerSubscriptionItem.kt | 2 +- .../org/schabi/newpipe/player/Player.java | 22 ++++++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerSubscriptionItem.kt b/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerSubscriptionItem.kt index 3540e6938..d4d4e7db1 100644 --- a/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerSubscriptionItem.kt +++ b/app/src/main/java/org/schabi/newpipe/local/subscription/item/PickerSubscriptionItem.kt @@ -46,6 +46,6 @@ data class PickerSubscriptionItem( fun updateSelected(containerView: View, isSelected: Boolean) { this.isSelected = isSelected PickerSubscriptionItemBinding.bind(containerView).selectedHighlight - .animate(isSelected, 150, AnimationType.LIGHT_SCALE_AND_ALPHA) + .animate(isSelected, 150, AnimationType.LIGHT_SCALE_AND_ALPHA) } } diff --git a/app/src/main/java/org/schabi/newpipe/player/Player.java b/app/src/main/java/org/schabi/newpipe/player/Player.java index b2b65477a..13a0a7d02 100644 --- a/app/src/main/java/org/schabi/newpipe/player/Player.java +++ b/app/src/main/java/org/schabi/newpipe/player/Player.java @@ -1349,13 +1349,23 @@ public final class Player implements public void removePopupFromView() { if (windowManager != null) { - final boolean isCloseOverlayHasParent = closeOverlayBinding != null - && closeOverlayBinding.closeButton.getParent() != null; - if (popupHasParent()) { - windowManager.removeView(binding.getRoot()); + // wrap in try-catch since it could sometimes generate errors randomly + try { + if (popupHasParent()) { + windowManager.removeView(binding.getRoot()); + } + } catch (final IllegalArgumentException e) { + Log.w(TAG, "Failed to remove popup from window manager", e); } - if (isCloseOverlayHasParent) { - windowManager.removeView(closeOverlayBinding.getRoot()); + + try { + final boolean closeOverlayHasParent = closeOverlayBinding != null + && closeOverlayBinding.getRoot().getParent() != null; + if (closeOverlayHasParent) { + windowManager.removeView(closeOverlayBinding.getRoot()); + } + } catch (final IllegalArgumentException e) { + Log.w(TAG, "Failed to remove popup overlay from window manager", e); } } }