2019-12-29 22:15:01 +01:00
|
|
|
package org.schabi.newpipe.player.event;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Rect;
|
|
|
|
import android.util.AttributeSet;
|
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.ViewGroup;
|
2020-02-12 20:33:23 +01:00
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import androidx.annotation.NonNull;
|
2019-12-29 22:15:01 +01:00
|
|
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
|
|
|
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
|
|
|
boolean visible;
|
|
|
|
Rect globalRect = new Rect();
|
|
|
|
private boolean skippingInterception = false;
|
2020-07-12 02:59:47 +02:00
|
|
|
private final List<Integer> skipInterceptionOfElements = Arrays.asList(
|
2020-02-12 20:33:23 +01:00
|
|
|
R.id.detail_content_root_layout, R.id.relatedStreamsLayout, R.id.playQueuePanel, R.id.viewpager);
|
2020-02-05 06:59:30 +01:00
|
|
|
|
2019-12-29 22:15:01 +01:00
|
|
|
@Override
|
2020-02-12 20:33:23 +01:00
|
|
|
public boolean onInterceptTouchEvent(@NonNull CoordinatorLayout parent, @NonNull FrameLayout child, MotionEvent event) {
|
|
|
|
// Drop following when action ends
|
2020-02-05 06:59:30 +01:00
|
|
|
if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP)
|
|
|
|
skippingInterception = false;
|
|
|
|
|
2020-02-12 20:33:23 +01:00
|
|
|
// Found that user still swiping, continue following
|
2020-02-05 06:59:30 +01:00
|
|
|
if (skippingInterception) return false;
|
|
|
|
|
2020-03-10 10:06:38 +01:00
|
|
|
// Don't need to do anything if bottomSheet isn't expanded
|
|
|
|
if (getState() == BottomSheetBehavior.STATE_EXPANDED) {
|
|
|
|
// Without overriding scrolling will not work when user touches these elements
|
2020-07-12 02:59:47 +02:00
|
|
|
for (final Integer element : skipInterceptionOfElements) {
|
|
|
|
final ViewGroup viewGroup = child.findViewById(element);
|
2020-03-10 10:06:38 +01:00
|
|
|
if (viewGroup != null) {
|
|
|
|
visible = viewGroup.getGlobalVisibleRect(globalRect);
|
|
|
|
if (visible && globalRect.contains((int) event.getRawX(), (int) event.getRawY())) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|