Skip to content

Commit

Permalink
Skipped interception of buttons in the player in some cases and made …
Browse files Browse the repository at this point in the history
…image view from playQueue visible
  • Loading branch information
avently committed Oct 1, 2020
1 parent 3a3ecc7 commit dd726fa
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.OverScroller;

import androidx.annotation.NonNull;
Expand All @@ -14,6 +13,8 @@
import org.schabi.newpipe.R;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;

// See https://stackoverflow.com/questions/56849221#57997489
public final class FlingBehavior extends AppBarLayout.Behavior {
Expand All @@ -25,6 +26,9 @@ public FlingBehavior(final Context context, final AttributeSet attrs) {

private boolean allowScroll = true;
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
public boolean onRequestChildRectangleOnScreen(
Expand Down Expand Up @@ -60,20 +64,14 @@ public boolean onRequestChildRectangleOnScreen(

public boolean onInterceptTouchEvent(final CoordinatorLayout parent, final AppBarLayout child,
final MotionEvent ev) {
final ViewGroup playQueue = child.findViewById(R.id.playQueuePanel);
if (playQueue != null) {
final boolean visible = playQueue.getGlobalVisibleRect(globalRect);
if (visible && globalRect.contains((int) ev.getRawX(), (int) ev.getRawY())) {
allowScroll = 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;
for (final Integer element : skipInterceptionOfElements) {
final View view = child.findViewById(element);
if (view != null) {
final boolean visible = view.getGlobalVisibleRect(globalRect);
if (visible && globalRect.contains((int) ev.getRawX(), (int) ev.getRawY())) {
allowScroll = false;
return false;
}
}
}
allowScroll = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
Expand All @@ -21,12 +20,12 @@ public CustomBottomSheetBehavior(final Context context, final AttributeSet attrs
super(context, attrs);
}

boolean visible;
Rect globalRect = new Rect();
private boolean skippingInterception = false;
private final List<Integer> skipInterceptionOfElements = Arrays.asList(
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
public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
Expand All @@ -48,9 +47,9 @@ public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
&& event.getAction() == MotionEvent.ACTION_DOWN) {
// Without overriding scrolling will not work when user touches these elements
for (final Integer element : skipInterceptionOfElements) {
final ViewGroup viewGroup = child.findViewById(element);
if (viewGroup != null) {
visible = viewGroup.getGlobalVisibleRect(globalRect);
final View view = child.findViewById(element);
if (view != null) {
final boolean visible = view.getGlobalVisibleRect(globalRect);
if (visible
&& globalRect.contains((int) event.getRawX(), (int) event.getRawY())) {
// Makes bottom part of the player draggable in portrait when
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/play_queue_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:paddingTop="6dp"
android:paddingBottom="6dp">

<ImageView
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/itemSelected"
android:layout_width="10dp"
android:layout_height="10dp"
Expand All @@ -38,7 +38,7 @@
android:src="@drawable/dummy_thumbnail"
tools:ignore="RtlHardcoded"/>

<ImageView
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/itemHandle"
android:layout_width="wrap_content"
android:layout_height="match_parent"
Expand Down

0 comments on commit dd726fa

Please sign in to comment.