Merge pull request #5453 from ByteHamster/harder-drag

Make it harder to accidentally drag episodes in the queue
This commit is contained in:
ByteHamster 2021-10-05 22:25:25 +02:00 committed by GitHub
commit c52cf51857
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,7 @@ import android.view.MenuInflater;
import android.view.MotionEvent;
import android.view.View;
import androidx.core.view.ViewCompat;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.core.preferences.UserPreferences;
@ -37,22 +38,32 @@ public class QueueRecyclerAdapter extends EpisodeItemListAdapter {
@Override
@SuppressLint("ClickableViewAccessibility")
protected void afterBindViewHolder(EpisodeItemViewHolder holder, int pos) {
View.OnTouchListener startDragTouchListener = (v1, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
Log.d(TAG, "startDrag()");
swipeActions.startDrag(holder);
}
return false;
};
if (!dragDropEnabled || inActionMode()) {
holder.dragHandle.setVisibility(View.GONE);
holder.dragHandle.setOnTouchListener(null);
holder.coverHolder.setOnTouchListener(null);
} else {
holder.dragHandle.setVisibility(View.VISIBLE);
holder.dragHandle.setOnTouchListener(startDragTouchListener);
holder.coverHolder.setOnTouchListener(startDragTouchListener);
holder.dragHandle.setOnTouchListener((v1, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
Log.d(TAG, "startDrag()");
swipeActions.startDrag(holder);
}
return false;
});
holder.coverHolder.setOnTouchListener((v1, event) -> {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
boolean isLtr = ViewCompat.getLayoutDirection(holder.itemView) == ViewCompat.LAYOUT_DIRECTION_LTR;
float factor = isLtr ? 1 : -1;
if (factor * event.getX() < factor * 0.5 * v1.getWidth()) {
Log.d(TAG, "startDrag()");
swipeActions.startDrag(holder);
} else {
Log.d(TAG, "Ignoring drag in right half of the image");
}
}
return false;
});
}
holder.isInQueue.setVisibility(View.GONE);