Skip to content

Commit 4930a82

Browse files
ashishkumar468maskaravivek
authored andcommitted
Bug fix issue #1999 (#2000)
* Added a threshold on swipe, ie. if a swipe is considered a swipe only if it covers a distance of 100dp
1 parent 8eac08f commit 4930a82

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/src/main/java/fr/free/nrw/commons/nearby/NearbyNoificationCardView.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import android.content.Context;
44
import android.content.Intent;
5+
import android.content.res.Resources;
56
import android.support.annotation.NonNull;
67
import android.support.annotation.Nullable;
78
import android.support.design.widget.CoordinatorLayout;
@@ -28,6 +29,7 @@
2829
*/
2930
public class NearbyNoificationCardView extends CardView{
3031

32+
private static final float MINIMUM_THRESHOLD_FOR_SWIPE = 100;
3133
private Context context;
3234

3335
private Button permissionRequestButton;
@@ -98,13 +100,14 @@ private void setActionListeners() {
98100
this.setOnTouchListener(
99101
(v, event) -> {
100102
boolean isSwipe = false;
103+
float deltaX=0.0f;
101104
switch (event.getAction()) {
102105
case MotionEvent.ACTION_DOWN:
103106
x1 = event.getX();
104107
break;
105108
case MotionEvent.ACTION_UP:
106109
x2 = event.getX();
107-
float deltaX = x2 - x1;
110+
deltaX = x2 - x1;
108111
if (deltaX < 0) {
109112
//Right to left swipe
110113
isSwipe = true;
@@ -114,7 +117,7 @@ private void setActionListeners() {
114117
}
115118
break;
116119
}
117-
if (isSwipe) {
120+
if (isSwipe && (pixelToDp(Math.abs(deltaX)) > MINIMUM_THRESHOLD_FOR_SWIPE)) {
118121
v.setVisibility(GONE);
119122
// Save shared preference for nearby card view accordingly
120123
((MainActivity) context).prefs.edit()
@@ -126,6 +129,10 @@ private void setActionListeners() {
126129
});
127130
}
128131

132+
private float pixelToDp(float pixels) {
133+
return (pixels / Resources.getSystem().getDisplayMetrics().density);
134+
}
135+
129136
/**
130137
* Sets permission request button visible and content layout invisible, then adds correct
131138
* permission request actions to permission request button according to PermissionType enum

0 commit comments

Comments
 (0)