Skip to content

Commit

Permalink
Merge pull request TeamNewPipe/NewPipe#5442 from Stypox/fix-close-popup
Browse files Browse the repository at this point in the history
Prevent IllegalArgumentException when closing popup
  • Loading branch information
XiangRongLin authored and tossj committed Apr 20, 2021
1 parent cf22a10 commit 9ca58b2
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions app/src/main/java/org/schabi/newpipelegacy/player/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1349,13 +1349,23 @@ public void closePopup() {

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);
}
}
}
Expand Down

0 comments on commit 9ca58b2

Please sign in to comment.