mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
* Added a threshold on swipe, ie. if a swipe is considered a swipe only if it covers a distance of 100dp
This commit is contained in:
parent
8eac08fc04
commit
4930a82ea2
1 changed files with 9 additions and 2 deletions
|
|
@ -2,6 +2,7 @@ package fr.free.nrw.commons.nearby;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.design.widget.CoordinatorLayout;
|
import android.support.design.widget.CoordinatorLayout;
|
||||||
|
|
@ -28,6 +29,7 @@ import timber.log.Timber;
|
||||||
*/
|
*/
|
||||||
public class NearbyNoificationCardView extends CardView{
|
public class NearbyNoificationCardView extends CardView{
|
||||||
|
|
||||||
|
private static final float MINIMUM_THRESHOLD_FOR_SWIPE = 100;
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
private Button permissionRequestButton;
|
private Button permissionRequestButton;
|
||||||
|
|
@ -98,13 +100,14 @@ public class NearbyNoificationCardView extends CardView{
|
||||||
this.setOnTouchListener(
|
this.setOnTouchListener(
|
||||||
(v, event) -> {
|
(v, event) -> {
|
||||||
boolean isSwipe = false;
|
boolean isSwipe = false;
|
||||||
|
float deltaX=0.0f;
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
x1 = event.getX();
|
x1 = event.getX();
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
x2 = event.getX();
|
x2 = event.getX();
|
||||||
float deltaX = x2 - x1;
|
deltaX = x2 - x1;
|
||||||
if (deltaX < 0) {
|
if (deltaX < 0) {
|
||||||
//Right to left swipe
|
//Right to left swipe
|
||||||
isSwipe = true;
|
isSwipe = true;
|
||||||
|
|
@ -114,7 +117,7 @@ public class NearbyNoificationCardView extends CardView{
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (isSwipe) {
|
if (isSwipe && (pixelToDp(Math.abs(deltaX)) > MINIMUM_THRESHOLD_FOR_SWIPE)) {
|
||||||
v.setVisibility(GONE);
|
v.setVisibility(GONE);
|
||||||
// Save shared preference for nearby card view accordingly
|
// Save shared preference for nearby card view accordingly
|
||||||
((MainActivity) context).prefs.edit()
|
((MainActivity) context).prefs.edit()
|
||||||
|
|
@ -126,6 +129,10 @@ public class NearbyNoificationCardView extends CardView{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private float pixelToDp(float pixels) {
|
||||||
|
return (pixels / Resources.getSystem().getDisplayMetrics().density);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets permission request button visible and content layout invisible, then adds correct
|
* Sets permission request button visible and content layout invisible, then adds correct
|
||||||
* permission request actions to permission request button according to PermissionType enum
|
* permission request actions to permission request button according to PermissionType enum
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue