Skip to content

Commit 282aa69

Browse files
Merge pull request #5 from ashishkumar468/neslihanturan-mainUIChanges
Bug fix nearby notification card dismiss/restore issue
2 parents b133f46 + 463bb78 commit 282aa69

File tree

2 files changed

+47
-50
lines changed

2 files changed

+47
-50
lines changed

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

+35-30
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@
99
import android.support.v7.app.AlertDialog;
1010
import android.support.v7.widget.CardView;
1111
import android.util.AttributeSet;
12+
import android.view.MotionEvent;
1213
import android.view.View;
1314
import android.widget.Button;
1415
import android.widget.ImageView;
1516
import android.widget.ProgressBar;
1617
import android.widget.RelativeLayout;
1718
import android.widget.TextView;
1819

20+
import android.widget.Toast;
1921
import fr.free.nrw.commons.R;
2022
import fr.free.nrw.commons.contributions.MainActivity;
2123
import fr.free.nrw.commons.utils.ViewUtil;
@@ -39,6 +41,8 @@ public class NearbyNoificationCardView extends CardView{
3941

4042
public PermissionType permissionType;
4143

44+
float x1,x2;
45+
4246
public NearbyNoificationCardView(@NonNull Context context) {
4347
super(context);
4448
this.context = context;
@@ -79,30 +83,6 @@ private void init() {
7983
@Override
8084
protected void onAttachedToWindow() {
8185
super.onAttachedToWindow();
82-
// Add swipe and dismiss property
83-
SwipeDismissBehavior swipeDismissBehavior = new SwipeDismissBehavior();
84-
swipeDismissBehavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_ANY);
85-
swipeDismissBehavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
86-
@Override
87-
public void onDismiss(View view) {
88-
/**
89-
* Only dismissing view results a space after dismissed view. Since, we need to
90-
* make view invisible at all.
91-
*/
92-
NearbyNoificationCardView.this.setVisibility(GONE);
93-
// Save shared preference for nearby card view accordingly
94-
((MainActivity) context).prefs.edit().putBoolean("displayNearbyCardView", false).apply();
95-
ViewUtil.showLongToast(context, getResources().getString(R.string.nearby_notification_dismiss_message));
96-
}
97-
98-
@Override
99-
public void onDragStateChanged(int state) {
100-
101-
}
102-
});
103-
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) this.getLayoutParams();
104-
layoutParams.setBehavior(swipeDismissBehavior);
105-
10686
// If you don't setVisibility after getting layout params, then you will se an empty space in place of nerabyNotificationCardView
10787
if (((MainActivity)context).prefs.getBoolean("displayNearbyCardView", true)) {
10888
this.setVisibility(VISIBLE);
@@ -113,12 +93,37 @@ public void onDragStateChanged(int state) {
11393

11494

11595
private void setActionListeners() {
116-
this.setOnClickListener(new OnClickListener() {
117-
@Override
118-
public void onClick(View view) {
119-
((MainActivity)context).viewPager.setCurrentItem(1);
120-
}
121-
});
96+
this.setOnClickListener(view -> ((MainActivity)context).viewPager.setCurrentItem(1));
97+
98+
this.setOnTouchListener(
99+
(v, event) -> {
100+
boolean isSwipe = false;
101+
switch (event.getAction()) {
102+
case MotionEvent.ACTION_DOWN:
103+
x1 = event.getX();
104+
break;
105+
case MotionEvent.ACTION_UP:
106+
x2 = event.getX();
107+
float deltaX = x2 - x1;
108+
if (deltaX < 0) {
109+
//Right to left swipe
110+
isSwipe = true;
111+
} else if (deltaX > 0) {
112+
//Left to right swipe
113+
isSwipe = true;
114+
}
115+
break;
116+
}
117+
if (isSwipe) {
118+
v.setVisibility(GONE);
119+
// Save shared preference for nearby card view accordingly
120+
((MainActivity) context).prefs.edit()
121+
.putBoolean("displayNearbyCardView", false).apply();
122+
ViewUtil.showLongToast(context, getResources().getString(R.string.nearby_notification_dismiss_message));
123+
return true;
124+
}
125+
return false;
126+
});
122127
}
123128

124129
/**

app/src/main/res/layout/fragment_contributions.xml

+12-20
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,18 @@
55
xmlns:app="http://schemas.android.com/apk/res-auto"
66
android:orientation="vertical">
77

8-
<android.support.design.widget.CoordinatorLayout
9-
android:layout_width="match_parent"
10-
android:layout_height="wrap_content">
11-
12-
<fr.free.nrw.commons.nearby.NearbyNoificationCardView
13-
android:id="@+id/card_view_nearby"
14-
android:layout_height="wrap_content"
15-
android:layout_width="match_parent"
16-
app:cardBackgroundColor="?attr/mainCardBackground"
17-
>
18-
19-
</fr.free.nrw.commons.nearby.NearbyNoificationCardView>
20-
</android.support.design.widget.CoordinatorLayout>
21-
8+
<fr.free.nrw.commons.nearby.NearbyNoificationCardView
9+
android:id="@+id/card_view_nearby"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
app:cardBackgroundColor="?attr/mainCardBackground"
13+
/>
2214

23-
<FrameLayout
24-
android:layout_width="match_parent"
25-
android:background="#000"
26-
android:layout_height="match_parent"
27-
android:id="@+id/root_frame">
28-
</FrameLayout>
15+
<FrameLayout
16+
android:id="@+id/root_frame"
17+
android:layout_width="match_parent"
18+
android:layout_height="match_parent"
19+
android:background="#000">
20+
</FrameLayout>
2921

3022
</LinearLayout>

0 commit comments

Comments
 (0)