mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
Show campaigns (#2113)
* Show campaigns * Added a ui util class SwipableCardView which passes the onSwipe event to its children * NearbyCardView & CampaignView extend SwipableCardView * Fetch campaigns in ContributionsFragment * Added an option to enable disable campaign in Settings/Preferences * synced strings with master * removed duplicate initialsation of CampaignPresenter
This commit is contained in:
parent
707c52c768
commit
1b01c6517f
22 changed files with 608 additions and 47 deletions
|
|
@ -0,0 +1,72 @@
|
|||
package fr.free.nrw.commons.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.CardView;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* A card view which informs onSwipe events to its child
|
||||
*/
|
||||
public abstract class SwipableCardView extends CardView {
|
||||
float x1, x2;
|
||||
private static final float MINIMUM_THRESHOLD_FOR_SWIPE = 100;
|
||||
|
||||
public SwipableCardView(@NonNull Context context) {
|
||||
super(context);
|
||||
interceptOnTouchListener();
|
||||
}
|
||||
|
||||
public SwipableCardView(@NonNull Context context, @Nullable AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
interceptOnTouchListener();
|
||||
}
|
||||
|
||||
public SwipableCardView(@NonNull Context context, @Nullable AttributeSet attrs,
|
||||
int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
interceptOnTouchListener();
|
||||
}
|
||||
|
||||
private void interceptOnTouchListener() {
|
||||
this.setOnTouchListener((v, event) -> {
|
||||
boolean isSwipe = false;
|
||||
float deltaX = 0.0f;
|
||||
Log.e("#SwipableCardView#", event.getAction() + "");
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
x1 = event.getX();
|
||||
break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
x2 = event.getX();
|
||||
deltaX = x2 - x1;
|
||||
if (deltaX < 0) {
|
||||
//Right to left swipe
|
||||
isSwipe = true;
|
||||
} else if (deltaX > 0) {
|
||||
//Left to right swipe
|
||||
isSwipe = true;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (isSwipe && (pixelToDp(Math.abs(deltaX)) > MINIMUM_THRESHOLD_FOR_SWIPE)) {
|
||||
return onSwipe(v);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* abstract function which informs swipe events to those who have inherited from it
|
||||
*/
|
||||
public abstract boolean onSwipe(View view);
|
||||
|
||||
private float pixelToDp(float pixels) {
|
||||
return (pixels / Resources.getSystem().getDisplayMetrics().density);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue