1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2025-01-11 01:40:59 +00:00

Merge pull request #4360 from avently/player-overlays

Player overlays now centered
This commit is contained in:
Tobias Groza 2020-10-02 15:37:28 +02:00 committed by GitHub
commit 794c74e514
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 242 additions and 219 deletions

View File

@ -5,7 +5,6 @@ import android.graphics.Rect;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.OverScroller; import android.widget.OverScroller;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -14,6 +13,8 @@ import androidx.coordinatorlayout.widget.CoordinatorLayout;
import org.schabi.newpipe.R; import org.schabi.newpipe.R;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
// See https://stackoverflow.com/questions/56849221#57997489 // See https://stackoverflow.com/questions/56849221#57997489
public final class FlingBehavior extends AppBarLayout.Behavior { public final class FlingBehavior extends AppBarLayout.Behavior {
@ -25,6 +26,9 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
private boolean allowScroll = true; private boolean allowScroll = true;
private final Rect globalRect = new Rect(); private final Rect globalRect = new Rect();
private final List<Integer> skipInterceptionOfElements = Arrays.asList(
R.id.playQueuePanel, R.id.playbackSeekBar,
R.id.playPauseButton, R.id.playPreviousButton, R.id.playNextButton);
@Override @Override
public boolean onRequestChildRectangleOnScreen( public boolean onRequestChildRectangleOnScreen(
@ -60,21 +64,15 @@ public final class FlingBehavior extends AppBarLayout.Behavior {
public boolean onInterceptTouchEvent(final CoordinatorLayout parent, final AppBarLayout child, public boolean onInterceptTouchEvent(final CoordinatorLayout parent, final AppBarLayout child,
final MotionEvent ev) { final MotionEvent ev) {
final ViewGroup playQueue = child.findViewById(R.id.playQueuePanel); for (final Integer element : skipInterceptionOfElements) {
if (playQueue != null) { final View view = child.findViewById(element);
final boolean visible = playQueue.getGlobalVisibleRect(globalRect); if (view != null) {
final boolean visible = view.getGlobalVisibleRect(globalRect);
if (visible && globalRect.contains((int) ev.getRawX(), (int) ev.getRawY())) { if (visible && globalRect.contains((int) ev.getRawX(), (int) ev.getRawY())) {
allowScroll = false; allowScroll = false;
return false; return false;
} }
} }
final View seekBar = child.findViewById(R.id.playbackSeekBar);
if (seekBar != null) {
final boolean visible = seekBar.getGlobalVisibleRect(globalRect);
if (visible && globalRect.contains((int) ev.getRawX(), (int) ev.getRawY())) {
allowScroll = false;
return false;
}
} }
allowScroll = true; allowScroll = true;
switch (ev.getActionMasked()) { switch (ev.getActionMasked()) {

View File

@ -172,6 +172,8 @@ public class VideoPlayerImpl extends VideoPlayer
private RecyclerView itemsList; private RecyclerView itemsList;
private ItemTouchHelper itemTouchHelper; private ItemTouchHelper itemTouchHelper;
private RelativeLayout playerOverlays;
private boolean queueVisible; private boolean queueVisible;
private MainPlayer.PlayerType playerType = MainPlayer.PlayerType.VIDEO; private MainPlayer.PlayerType playerType = MainPlayer.PlayerType.VIDEO;
@ -305,6 +307,8 @@ public class VideoPlayerImpl extends VideoPlayer
this.itemsListCloseButton = view.findViewById(R.id.playQueueClose); this.itemsListCloseButton = view.findViewById(R.id.playQueueClose);
this.itemsList = view.findViewById(R.id.playQueue); this.itemsList = view.findViewById(R.id.playQueue);
this.playerOverlays = view.findViewById(R.id.player_overlays);
closingOverlayView = view.findViewById(R.id.closingOverlay); closingOverlayView = view.findViewById(R.id.closingOverlay);
titleTextView.setSelected(true); titleTextView.setSelected(true);
@ -481,6 +485,16 @@ public class VideoPlayerImpl extends VideoPlayer
return windowInsets; return windowInsets;
}); });
} }
// PlaybackControlRoot already consumed window insets but we should pass them to
// player_overlays too. Without it they will be off-centered
getControlsRoot().addOnLayoutChangeListener((v, left, top, right, bottom,
oldLeft, oldTop, oldRight, oldBottom) ->
playerOverlays.setPadding(
v.getPaddingLeft(),
v.getPaddingTop(),
v.getPaddingRight(),
v.getPaddingBottom()));
} }
public boolean onKeyDown(final int keyCode) { public boolean onKeyDown(final int keyCode) {

View File

@ -5,7 +5,6 @@ import android.graphics.Rect;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout; import android.widget.FrameLayout;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.coordinatorlayout.widget.CoordinatorLayout;
@ -21,12 +20,12 @@ public class CustomBottomSheetBehavior extends BottomSheetBehavior<FrameLayout>
super(context, attrs); super(context, attrs);
} }
boolean visible;
Rect globalRect = new Rect(); Rect globalRect = new Rect();
private boolean skippingInterception = false; private boolean skippingInterception = false;
private final List<Integer> skipInterceptionOfElements = Arrays.asList( private final List<Integer> skipInterceptionOfElements = Arrays.asList(
R.id.detail_content_root_layout, R.id.relatedStreamsLayout, R.id.detail_content_root_layout, R.id.relatedStreamsLayout,
R.id.playQueuePanel, R.id.viewpager, R.id.bottomControls); R.id.playQueuePanel, R.id.viewpager, R.id.bottomControls,
R.id.playPauseButton, R.id.playPreviousButton, R.id.playNextButton);
@Override @Override
public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent, public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
@ -48,9 +47,9 @@ public class CustomBottomSheetBehavior extends BottomSheetBehavior<FrameLayout>
&& event.getAction() == MotionEvent.ACTION_DOWN) { && event.getAction() == MotionEvent.ACTION_DOWN) {
// Without overriding scrolling will not work when user touches these elements // Without overriding scrolling will not work when user touches these elements
for (final Integer element : skipInterceptionOfElements) { for (final Integer element : skipInterceptionOfElements) {
final ViewGroup viewGroup = child.findViewById(element); final View view = child.findViewById(element);
if (viewGroup != null) { if (view != null) {
visible = viewGroup.getGlobalVisibleRect(globalRect); final boolean visible = view.getGlobalVisibleRect(globalRect);
if (visible if (visible
&& globalRect.contains((int) event.getRawX(), (int) event.getRawY())) { && globalRect.contains((int) event.getRawX(), (int) event.getRawY())) {
// Makes bottom part of the player draggable in portrait when // Makes bottom part of the player draggable in portrait when

View File

@ -530,6 +530,11 @@
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/player_overlays"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -548,7 +553,6 @@
tools:visibility="visible" /> tools:visibility="visible" />
</LinearLayout> </LinearLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/loading_panel" android:id="@+id/loading_panel"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -643,6 +647,8 @@
tools:visibility="visible" /> tools:visibility="visible" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout>
<TextView <TextView
android:id="@+id/resizing_indicator" android:id="@+id/resizing_indicator"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -12,7 +12,7 @@
android:paddingTop="6dp" android:paddingTop="6dp"
android:paddingBottom="6dp"> android:paddingBottom="6dp">
<ImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/itemSelected" android:id="@+id/itemSelected"
android:layout_width="10dp" android:layout_width="10dp"
android:layout_height="10dp" android:layout_height="10dp"
@ -38,7 +38,7 @@
android:src="@drawable/dummy_thumbnail" android:src="@drawable/dummy_thumbnail"
tools:ignore="RtlHardcoded"/> tools:ignore="RtlHardcoded"/>
<ImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/itemHandle" android:id="@+id/itemHandle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"

View File

@ -526,6 +526,11 @@
</RelativeLayout> </RelativeLayout>
<RelativeLayout
android:id="@+id/player_overlays"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -544,7 +549,6 @@
tools:visibility="visible" /> tools:visibility="visible" />
</LinearLayout> </LinearLayout>
<RelativeLayout <RelativeLayout
android:id="@+id/loading_panel" android:id="@+id/loading_panel"
android:layout_width="match_parent" android:layout_width="match_parent"
@ -639,6 +643,8 @@
tools:visibility="visible" /> tools:visibility="visible" />
</RelativeLayout> </RelativeLayout>
</RelativeLayout>
<TextView <TextView
android:id="@+id/resizing_indicator" android:id="@+id/resizing_indicator"
android:layout_width="wrap_content" android:layout_width="wrap_content"