2022-04-08 09:35:14 +02:00
|
|
|
package org.schabi.newpipe.player.gesture;
|
2019-12-29 22:15:01 +01:00
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Rect;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.MotionEvent;
|
2020-08-16 21:20:37 +02:00
|
|
|
import android.view.View;
|
2020-02-12 20:33:23 +01:00
|
|
|
import android.widget.FrameLayout;
|
2021-01-15 17:11:04 +01:00
|
|
|
|
2020-02-12 20:33:23 +01:00
|
|
|
import androidx.annotation.NonNull;
|
2019-12-29 22:15:01 +01:00
|
|
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
2021-01-15 17:11:04 +01:00
|
|
|
|
2019-12-29 22:15:01 +01:00
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
2021-01-15 17:11:04 +01:00
|
|
|
|
2019-12-29 22:15:01 +01:00
|
|
|
import org.schabi.newpipe.R;
|
|
|
|
|
2020-02-12 20:33:23 +01:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
public class CustomBottomSheetBehavior extends BottomSheetBehavior<FrameLayout> {
|
2019-12-29 22:15:01 +01:00
|
|
|
|
2020-07-12 02:59:47 +02:00
|
|
|
public CustomBottomSheetBehavior(final Context context, final AttributeSet attrs) {
|
2019-12-29 22:15:01 +01:00
|
|
|
super(context, attrs);
|
|
|
|
}
|
|
|
|
|
2020-02-12 20:33:23 +01:00
|
|
|
Rect globalRect = new Rect();
|
|
|
|
private boolean skippingInterception = false;
|
2020-07-12 02:59:47 +02:00
|
|
|
private final List<Integer> skipInterceptionOfElements = Arrays.asList(
|
2021-03-31 20:16:08 +02:00
|
|
|
R.id.detail_content_root_layout, R.id.relatedItemsLayout,
|
2020-12-08 21:47:02 +01:00
|
|
|
R.id.itemsListPanel, R.id.view_pager, R.id.tab_layout, R.id.bottomControls,
|
2020-10-01 02:10:42 +02:00
|
|
|
R.id.playPauseButton, R.id.playPreviousButton, R.id.playNextButton);
|
2020-02-05 06:59:30 +01:00
|
|
|
|
2019-12-29 22:15:01 +01:00
|
|
|
@Override
|
2020-07-14 19:21:32 +02:00
|
|
|
public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
|
|
|
|
@NonNull final FrameLayout child,
|
|
|
|
final MotionEvent event) {
|
2020-02-12 20:33:23 +01:00
|
|
|
// Drop following when action ends
|
2020-07-14 19:21:32 +02:00
|
|
|
if (event.getAction() == MotionEvent.ACTION_CANCEL
|
|
|
|
|| event.getAction() == MotionEvent.ACTION_UP) {
|
2020-02-05 06:59:30 +01:00
|
|
|
skippingInterception = false;
|
2020-07-14 19:21:32 +02:00
|
|
|
}
|
2020-02-05 06:59:30 +01:00
|
|
|
|
2020-02-12 20:33:23 +01:00
|
|
|
// Found that user still swiping, continue following
|
2020-09-17 18:01:20 +02:00
|
|
|
if (skippingInterception || getState() == BottomSheetBehavior.STATE_SETTLING) {
|
2020-07-14 19:21:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
2020-02-05 06:59:30 +01:00
|
|
|
|
2020-10-10 15:00:39 +02:00
|
|
|
// The interception listens for the child view with the id "fragment_player_holder",
|
|
|
|
// so the following two-finger gesture will be triggered only for the player view on
|
|
|
|
// portrait and for the top controls (visible) on landscape.
|
2020-10-11 13:56:30 +02:00
|
|
|
setSkipCollapsed(event.getPointerCount() == 2);
|
2020-10-10 15:00:39 +02:00
|
|
|
if (event.getPointerCount() == 2) {
|
|
|
|
return super.onInterceptTouchEvent(parent, child, event);
|
|
|
|
}
|
|
|
|
|
2020-03-10 10:06:38 +01:00
|
|
|
// Don't need to do anything if bottomSheet isn't expanded
|
2020-09-16 22:41:49 +02:00
|
|
|
if (getState() == BottomSheetBehavior.STATE_EXPANDED
|
|
|
|
&& event.getAction() == MotionEvent.ACTION_DOWN) {
|
2020-03-10 10:06:38 +01:00
|
|
|
// Without overriding scrolling will not work when user touches these elements
|
2020-07-12 02:59:47 +02:00
|
|
|
for (final Integer element : skipInterceptionOfElements) {
|
2020-10-01 02:10:42 +02:00
|
|
|
final View view = child.findViewById(element);
|
|
|
|
if (view != null) {
|
|
|
|
final boolean visible = view.getGlobalVisibleRect(globalRect);
|
2020-07-14 19:21:32 +02:00
|
|
|
if (visible
|
|
|
|
&& globalRect.contains((int) event.getRawX(), (int) event.getRawY())) {
|
2020-08-16 21:20:37 +02:00
|
|
|
// Makes bottom part of the player draggable in portrait when
|
|
|
|
// playbackControlRoot is hidden
|
|
|
|
if (element == R.id.bottomControls
|
|
|
|
&& child.findViewById(R.id.playbackControlRoot)
|
|
|
|
.getVisibility() != View.VISIBLE) {
|
|
|
|
return super.onInterceptTouchEvent(parent, child, event);
|
|
|
|
}
|
2020-03-10 10:06:38 +01:00
|
|
|
skippingInterception = true;
|
|
|
|
return false;
|
|
|
|
}
|
2020-02-12 20:33:23 +01:00
|
|
|
}
|
2020-02-05 06:59:30 +01:00
|
|
|
}
|
2019-12-29 22:15:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return super.onInterceptTouchEvent(parent, child, event);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|