Skip to content

Bug fix nearby notification card dismiss/restore issue #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.CardView;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

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

public PermissionType permissionType;

float x1,x2;

public NearbyNoificationCardView(@NonNull Context context) {
super(context);
this.context = context;
Expand Down Expand Up @@ -79,30 +83,6 @@ private void init() {
@Override
protected void onAttachedToWindow() {
super.onAttachedToWindow();
// Add swipe and dismiss property
SwipeDismissBehavior swipeDismissBehavior = new SwipeDismissBehavior();
swipeDismissBehavior.setSwipeDirection(SwipeDismissBehavior.SWIPE_DIRECTION_ANY);
swipeDismissBehavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
@Override
public void onDismiss(View view) {
/**
* Only dismissing view results a space after dismissed view. Since, we need to
* make view invisible at all.
*/
NearbyNoificationCardView.this.setVisibility(GONE);
// Save shared preference for nearby card view accordingly
((MainActivity) context).prefs.edit().putBoolean("displayNearbyCardView", false).apply();
ViewUtil.showLongToast(context, getResources().getString(R.string.nearby_notification_dismiss_message));
}

@Override
public void onDragStateChanged(int state) {

}
});
CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) this.getLayoutParams();
layoutParams.setBehavior(swipeDismissBehavior);

// If you don't setVisibility after getting layout params, then you will se an empty space in place of nerabyNotificationCardView
if (((MainActivity)context).prefs.getBoolean("displayNearbyCardView", true)) {
this.setVisibility(VISIBLE);
Expand All @@ -113,12 +93,37 @@ public void onDragStateChanged(int state) {


private void setActionListeners() {
this.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
((MainActivity)context).viewPager.setCurrentItem(1);
}
});
this.setOnClickListener(view -> ((MainActivity)context).viewPager.setCurrentItem(1));

this.setOnTouchListener(
(v, event) -> {
boolean isSwipe = false;
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
x1 = event.getX();
break;
case MotionEvent.ACTION_UP:
x2 = event.getX();
float 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) {
v.setVisibility(GONE);
// Save shared preference for nearby card view accordingly
((MainActivity) context).prefs.edit()
.putBoolean("displayNearbyCardView", false).apply();
ViewUtil.showLongToast(context, getResources().getString(R.string.nearby_notification_dismiss_message));
return true;
}
return false;
});
}

/**
Expand Down
32 changes: 12 additions & 20 deletions app/src/main/res/layout/fragment_contributions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,18 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<fr.free.nrw.commons.nearby.NearbyNoificationCardView
android:id="@+id/card_view_nearby"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:cardBackgroundColor="?attr/mainCardBackground"
>

</fr.free.nrw.commons.nearby.NearbyNoificationCardView>
</android.support.design.widget.CoordinatorLayout>

<fr.free.nrw.commons.nearby.NearbyNoificationCardView
android:id="@+id/card_view_nearby"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="?attr/mainCardBackground"
/>

<FrameLayout
android:layout_width="match_parent"
android:background="#000"
android:layout_height="match_parent"
android:id="@+id/root_frame">
</FrameLayout>
<FrameLayout
android:id="@+id/root_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000">
</FrameLayout>

</LinearLayout>