From 515bcaaa019d5b7ef613f62f275398c33f8ec169 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Wed, 23 Dec 2020 06:47:36 +0530 Subject: [PATCH] Use view binding (PlayerPopupCloseOverlayBinding) in VideoPlayerImpl. --- .../newpipe/player/VideoPlayerImpl.java | 48 +++++++++---------- .../player/event/BasePlayerGestureListener.kt | 2 +- .../player/event/PlayerGestureListener.java | 2 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java index 9f348546f8b..848f130198f 100644 --- a/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java +++ b/app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java @@ -39,6 +39,7 @@ import android.view.GestureDetector; import android.view.Gravity; import android.view.KeyEvent; +import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -73,11 +74,11 @@ import com.google.android.exoplayer2.text.CaptionStyleCompat; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.SubtitleView; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.nostra13.universalimageloader.core.assist.FailReason; import org.schabi.newpipe.R; import org.schabi.newpipe.databinding.PlayerBinding; +import org.schabi.newpipe.databinding.PlayerPopupCloseOverlayBinding; import org.schabi.newpipe.extractor.stream.StreamInfo; import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; @@ -172,8 +173,7 @@ public class VideoPlayerImpl extends VideoPlayer private WindowManager.LayoutParams popupLayoutParams; public WindowManager windowManager; - private View closeOverlayView; - private FloatingActionButton closeOverlayButton; + private PlayerPopupCloseOverlayBinding closeOverlayBinding; public boolean isPopupClosing = false; @@ -1326,10 +1326,10 @@ public boolean isPlayerStopped() { } private int distanceFromCloseButton(final MotionEvent popupMotionEvent) { - final int closeOverlayButtonX = closeOverlayButton.getLeft() - + closeOverlayButton.getWidth() / 2; - final int closeOverlayButtonY = closeOverlayButton.getTop() - + closeOverlayButton.getHeight() / 2; + final int closeOverlayButtonX = closeOverlayBinding.closeButton.getLeft() + + closeOverlayBinding.closeButton.getWidth() / 2; + final int closeOverlayButtonY = closeOverlayBinding.closeButton.getTop() + + closeOverlayBinding.closeButton.getHeight() / 2; final float fingerX = popupLayoutParams.x + popupMotionEvent.getX(); final float fingerY = popupLayoutParams.y + popupMotionEvent.getY(); @@ -1339,7 +1339,7 @@ private int distanceFromCloseButton(final MotionEvent popupMotionEvent) { } private float getClosingRadius() { - final int buttonRadius = closeOverlayButton.getWidth() / 2; + final int buttonRadius = closeOverlayBinding.closeButton.getWidth() / 2; // 20% wider than the button itself return buttonRadius * 1.2f; } @@ -1626,12 +1626,11 @@ private void initPopupCloseOverlay() { } // closeOverlayView is already added to windowManager - if (closeOverlayView != null) { + if (closeOverlayBinding != null) { return; } - closeOverlayView = View.inflate(service, R.layout.player_popup_close_overlay, null); - closeOverlayButton = closeOverlayView.findViewById(R.id.closeButton); + closeOverlayBinding = PlayerPopupCloseOverlayBinding.inflate(LayoutInflater.from(service)); final int flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE @@ -1646,8 +1645,8 @@ private void initPopupCloseOverlay() { closeOverlayLayoutParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; - closeOverlayButton.setVisibility(View.GONE); - windowManager.addView(closeOverlayView, closeOverlayLayoutParams); + closeOverlayBinding.closeButton.setVisibility(View.GONE); + windowManager.addView(closeOverlayBinding.getRoot(), closeOverlayLayoutParams); } private void initVideoPlayer() { @@ -1820,22 +1819,23 @@ public void closePopup() { } public void removePopupFromView() { - final boolean isCloseOverlayHasParent = closeOverlayView != null - && closeOverlayView.getParent() != null; + final boolean isCloseOverlayHasParent = closeOverlayBinding != null + && closeOverlayBinding.getRoot().getParent() != null; if (popupHasParent()) { windowManager.removeView(getRootView()); } if (isCloseOverlayHasParent) { - windowManager.removeView(closeOverlayView); + windowManager.removeView(closeOverlayBinding.getRoot()); } } private void animateOverlayAndFinishService() { - final int targetTranslationY = (int) (closeOverlayButton.getRootView().getHeight() - - closeOverlayButton.getY()); + final int targetTranslationY = + (int) (closeOverlayBinding.closeButton.getRootView().getHeight() + - closeOverlayBinding.closeButton.getY()); - closeOverlayButton.animate().setListener(null).cancel(); - closeOverlayButton.animate() + closeOverlayBinding.closeButton.animate().setListener(null).cancel(); + closeOverlayBinding.closeButton.animate() .setInterpolator(new AnticipateInterpolator()) .translationY(targetTranslationY) .setDuration(400) @@ -1851,8 +1851,8 @@ public void onAnimationEnd(final Animator animation) { } private void end() { - windowManager.removeView(closeOverlayView); - closeOverlayView = null; + windowManager.removeView(closeOverlayBinding.getRoot()); + closeOverlayBinding = null; service.onDestroy(); } @@ -2047,8 +2047,8 @@ public void setPopupHeight(final float height) { popupHeight = height; } - public View getCloseOverlayButton() { - return closeOverlayButton; + public View getCloseButton() { + return closeOverlayBinding.closeButton; } public View getClosingOverlay() { diff --git a/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt b/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt index 043e7f31de6..d34746ca50c 100644 --- a/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt +++ b/app/src/main/java/org/schabi/newpipe/player/event/BasePlayerGestureListener.kt @@ -371,7 +371,7 @@ abstract class BasePlayerGestureListener( } if (!isMovingInPopup) { - AnimationUtils.animateView(playerImpl.closeOverlayButton, true, 200) + AnimationUtils.animateView(playerImpl.closeButton, true, 200) } isMovingInPopup = true diff --git a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java index b6916e620ad..8f95147810d 100644 --- a/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java +++ b/app/src/main/java/org/schabi/newpipe/player/event/PlayerGestureListener.java @@ -243,7 +243,7 @@ public void onScrollEnd(@NotNull final MainPlayer.PlayerType playerType, animateView(playerImpl.getClosingOverlay(), false, 0); if (!playerImpl.isPopupClosing) { - animateView(playerImpl.getCloseOverlayButton(), false, 200); + animateView(playerImpl.getCloseButton(), false, 200); } } }