Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue-10971-swipe-down-gesture-too-sensitive #11642

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ dependencies {
// name and the commit hash with the commit hash of the (pushed) commit you want to test
// This works thanks to JitPack: https://jitpack.io/
implementation 'com.github.TeamNewPipe:nanojson:1d9e1aea9049fc9f85e68b43ba39fe7be1c1f751'
// WORKAROUND: v0.24.2 can't be resolved by jitpack -> use git commit hash instead
implementation 'com.github.TeamNewPipe:NewPipeExtractor:176da72cb4c3ec4679211339b0e59f6b01bf2f52'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:v0.24.2'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please clean your git history (rebase) and this is fixed on the dev branch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your detailed advice. I am still wondering about whether implementing swipe down threshold is a proper methods to solve this. As when the threshold is implemented. Within the threshold, the user gesture will be ignored and no interaction can be seen. Previously, the instantce user drag the screen, the view window will move with the drag. After distance threshold implementation, within the threshold distance, when you drag, there is no response, the window will not move. I am not very sure if this is the correct direction to solve this problem.

implementation 'com.github.TeamNewPipe:NoNonsense-FilePicker:5.0.0'

/** Checkstyle **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,6 @@ private void setupBottomPlayer() {
@Override
public void onStateChanged(@NonNull final View bottomSheet, final int newState) {
updateBottomSheetState(newState);

switch (newState) {
case BottomSheetBehavior.STATE_HIDDEN:
moveFocusToMainFragment(true);
Expand Down Expand Up @@ -2369,6 +2368,26 @@ && isPlayerAvailable()
}
}

private String getStateName(final int state) {
switch (state) {
case BottomSheetBehavior.STATE_DRAGGING:
return "DRAGGING";
case BottomSheetBehavior.STATE_SETTLING:
return "SETTLING";
case BottomSheetBehavior.STATE_EXPANDED:
return "EXPANDED";
case BottomSheetBehavior.STATE_COLLAPSED:
return "COLLAPSED";
case BottomSheetBehavior.STATE_HIDDEN:
return "HIDDEN";
case BottomSheetBehavior.STATE_HALF_EXPANDED:
return "HALF_EXPANDED";
default:
return "UNKNOWN";
}
}


@Override
public void onSlide(@NonNull final View bottomSheet, final float slideOffset) {
setOverlayLook(binding.appBarLayout, behavior, slideOffset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;
Expand All @@ -22,6 +23,9 @@ public class CustomBottomSheetBehavior extends BottomSheetBehavior<FrameLayout>
public CustomBottomSheetBehavior(@NonNull final Context context,
@Nullable final AttributeSet attrs) {
super(context, attrs);
final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
final int screenHeight = displayMetrics.heightPixels; //record the screen height
dragThreshold = (float) (0.05 * screenHeight); // Adjust this value as needed
}

Rect globalRect = new Rect();
Expand All @@ -30,6 +34,10 @@ public CustomBottomSheetBehavior(@NonNull final Context context,
R.id.detail_content_root_layout, R.id.relatedItemsLayout,
R.id.itemsListPanel, R.id.view_pager, R.id.tab_layout, R.id.bottomControls,
R.id.playPauseButton, R.id.playPreviousButton, R.id.playNextButton);
private float startY = 0f;
private float totalDrag = 0f;
private final float dragThreshold;


@Override
public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
Expand All @@ -39,6 +47,9 @@ public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
if (event.getAction() == MotionEvent.ACTION_CANCEL
|| event.getAction() == MotionEvent.ACTION_UP) {
skippingInterception = false;
//reset the variables
totalDrag = 0f;
startY = 0f;
u7759982 marked this conversation as resolved.
Show resolved Hide resolved
}

// Found that user still swiping, continue following
Expand Down Expand Up @@ -77,6 +88,28 @@ public boolean onInterceptTouchEvent(@NonNull final CoordinatorLayout parent,
}
}
}
// Implement the distance threshold logic, when the gesture move distance
// is shorter than the threshold, just do not intercept the touch event.
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN://initialize the tracked total distance
startY = event.getY();
totalDrag = 0f;
break;
case MotionEvent.ACTION_MOVE://accumulate the total distance
final float currentY = event.getY();
totalDrag += Math.abs(currentY - startY);
startY = currentY;
if (totalDrag < dragThreshold) {
return false; // Do not intercept touch events yet if shorter than threshold
} else {
return super.onInterceptTouchEvent(parent, child, event);
}
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL://reset the drag distance and start point
totalDrag = 0f;
startY = 0f;
break;
}

return super.onInterceptTouchEvent(parent, child, event);
}
Expand Down
Loading