1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 16:40:32 +00:00

Use view binding (PlayerPopupCloseOverlayBinding) in VideoPlayerImpl.

This commit is contained in:
Isira Seneviratne 2020-12-23 06:47:36 +05:30 committed by Stypox
parent 0c86a4e608
commit fa75c79d34
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
3 changed files with 26 additions and 26 deletions

View File

@ -39,6 +39,7 @@ import android.util.TypedValue;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.Gravity; import android.view.Gravity;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -73,11 +74,11 @@ import com.google.android.exoplayer2.source.MediaSource;
import com.google.android.exoplayer2.text.CaptionStyleCompat; import com.google.android.exoplayer2.text.CaptionStyleCompat;
import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout;
import com.google.android.exoplayer2.ui.SubtitleView; import com.google.android.exoplayer2.ui.SubtitleView;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.assist.FailReason;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import org.schabi.newpipe.databinding.PlayerBinding; 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.StreamInfo;
import org.schabi.newpipe.extractor.stream.VideoStream; import org.schabi.newpipe.extractor.stream.VideoStream;
import org.schabi.newpipe.fragments.OnScrollBelowItemsListener; import org.schabi.newpipe.fragments.OnScrollBelowItemsListener;
@ -172,8 +173,7 @@ public class VideoPlayerImpl extends VideoPlayer
private WindowManager.LayoutParams popupLayoutParams; private WindowManager.LayoutParams popupLayoutParams;
public WindowManager windowManager; public WindowManager windowManager;
private View closeOverlayView; private PlayerPopupCloseOverlayBinding closeOverlayBinding;
private FloatingActionButton closeOverlayButton;
public boolean isPopupClosing = false; public boolean isPopupClosing = false;
@ -1341,10 +1341,10 @@ public class VideoPlayerImpl extends VideoPlayer
} }
private int distanceFromCloseButton(final MotionEvent popupMotionEvent) { private int distanceFromCloseButton(final MotionEvent popupMotionEvent) {
final int closeOverlayButtonX = closeOverlayButton.getLeft() final int closeOverlayButtonX = closeOverlayBinding.closeButton.getLeft()
+ closeOverlayButton.getWidth() / 2; + closeOverlayBinding.closeButton.getWidth() / 2;
final int closeOverlayButtonY = closeOverlayButton.getTop() final int closeOverlayButtonY = closeOverlayBinding.closeButton.getTop()
+ closeOverlayButton.getHeight() / 2; + closeOverlayBinding.closeButton.getHeight() / 2;
final float fingerX = popupLayoutParams.x + popupMotionEvent.getX(); final float fingerX = popupLayoutParams.x + popupMotionEvent.getX();
final float fingerY = popupLayoutParams.y + popupMotionEvent.getY(); final float fingerY = popupLayoutParams.y + popupMotionEvent.getY();
@ -1354,7 +1354,7 @@ public class VideoPlayerImpl extends VideoPlayer
} }
private float getClosingRadius() { private float getClosingRadius() {
final int buttonRadius = closeOverlayButton.getWidth() / 2; final int buttonRadius = closeOverlayBinding.closeButton.getWidth() / 2;
// 20% wider than the button itself // 20% wider than the button itself
return buttonRadius * 1.2f; return buttonRadius * 1.2f;
} }
@ -1641,12 +1641,11 @@ public class VideoPlayerImpl extends VideoPlayer
} }
// closeOverlayView is already added to windowManager // closeOverlayView is already added to windowManager
if (closeOverlayView != null) { if (closeOverlayBinding != null) {
return; return;
} }
closeOverlayView = View.inflate(service, R.layout.player_popup_close_overlay, null); closeOverlayBinding = PlayerPopupCloseOverlayBinding.inflate(LayoutInflater.from(service));
closeOverlayButton = closeOverlayView.findViewById(R.id.closeButton);
final int flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE final int flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
| WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
@ -1661,8 +1660,8 @@ public class VideoPlayerImpl extends VideoPlayer
closeOverlayLayoutParams.softInputMode = closeOverlayLayoutParams.softInputMode =
WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE; WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
closeOverlayButton.setVisibility(View.GONE); closeOverlayBinding.closeButton.setVisibility(View.GONE);
windowManager.addView(closeOverlayView, closeOverlayLayoutParams); windowManager.addView(closeOverlayBinding.getRoot(), closeOverlayLayoutParams);
} }
private void initVideoPlayer() { private void initVideoPlayer() {
@ -1835,22 +1834,23 @@ public class VideoPlayerImpl extends VideoPlayer
} }
public void removePopupFromView() { public void removePopupFromView() {
final boolean isCloseOverlayHasParent = closeOverlayView != null final boolean isCloseOverlayHasParent = closeOverlayBinding != null
&& closeOverlayView.getParent() != null; && closeOverlayBinding.getRoot().getParent() != null;
if (popupHasParent()) { if (popupHasParent()) {
windowManager.removeView(getRootView()); windowManager.removeView(getRootView());
} }
if (isCloseOverlayHasParent) { if (isCloseOverlayHasParent) {
windowManager.removeView(closeOverlayView); windowManager.removeView(closeOverlayBinding.getRoot());
} }
} }
private void animateOverlayAndFinishService() { private void animateOverlayAndFinishService() {
final int targetTranslationY = (int) (closeOverlayButton.getRootView().getHeight() final int targetTranslationY =
- closeOverlayButton.getY()); (int) (closeOverlayBinding.closeButton.getRootView().getHeight()
- closeOverlayBinding.closeButton.getY());
closeOverlayButton.animate().setListener(null).cancel(); closeOverlayBinding.closeButton.animate().setListener(null).cancel();
closeOverlayButton.animate() closeOverlayBinding.closeButton.animate()
.setInterpolator(new AnticipateInterpolator()) .setInterpolator(new AnticipateInterpolator())
.translationY(targetTranslationY) .translationY(targetTranslationY)
.setDuration(400) .setDuration(400)
@ -1866,8 +1866,8 @@ public class VideoPlayerImpl extends VideoPlayer
} }
private void end() { private void end() {
windowManager.removeView(closeOverlayView); windowManager.removeView(closeOverlayBinding.getRoot());
closeOverlayView = null; closeOverlayBinding = null;
service.onDestroy(); service.onDestroy();
} }
@ -2062,8 +2062,8 @@ public class VideoPlayerImpl extends VideoPlayer
popupHeight = height; popupHeight = height;
} }
public View getCloseOverlayButton() { public View getCloseButton() {
return closeOverlayButton; return closeOverlayBinding.closeButton;
} }
public View getClosingOverlay() { public View getClosingOverlay() {

View File

@ -371,7 +371,7 @@ abstract class BasePlayerGestureListener(
} }
if (!isMovingInPopup) { if (!isMovingInPopup) {
AnimationUtils.animateView(playerImpl.closeOverlayButton, true, 200) AnimationUtils.animateView(playerImpl.closeButton, true, 200)
} }
isMovingInPopup = true isMovingInPopup = true

View File

@ -243,7 +243,7 @@ public class PlayerGestureListener
animateView(playerImpl.getClosingOverlay(), false, 0); animateView(playerImpl.getClosingOverlay(), false, 0);
if (!playerImpl.isPopupClosing) { if (!playerImpl.isPopupClosing) {
animateView(playerImpl.getCloseOverlayButton(), false, 200); animateView(playerImpl.getCloseButton(), false, 200);
} }
} }
} }