Skip to content

Commit

Permalink
Use view binding (PlayerPopupCloseOverlayBinding) in VideoPlayerImpl.
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Dec 23, 2020
1 parent ca1d85d commit 515bcaa
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
48 changes: 24 additions & 24 deletions app/src/main/java/org/schabi/newpipe/player/VideoPlayerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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)
Expand All @@ -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();
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ abstract class BasePlayerGestureListener(
}

if (!isMovingInPopup) {
AnimationUtils.animateView(playerImpl.closeOverlayButton, true, 200)
AnimationUtils.animateView(playerImpl.closeButton, true, 200)
}

isMovingInPopup = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down

0 comments on commit 515bcaa

Please sign in to comment.