From 03c1ddd9ce7370424374482b2704215706f84f63 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 6 Feb 2019 10:59:10 +0000 Subject: [PATCH] Refactored swipe listener --- .../java/eu/faircode/email/ActivityBase.java | 13 ---- .../eu/faircode/email/FragmentMessages.java | 60 +++++++++++-------- .../eu/faircode/email/FragmentOptions.java | 2 +- 3 files changed, 37 insertions(+), 38 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivityBase.java b/app/src/main/java/eu/faircode/email/ActivityBase.java index 4f984abae3..4a4404cf83 100644 --- a/app/src/main/java/eu/faircode/email/ActivityBase.java +++ b/app/src/main/java/eu/faircode/email/ActivityBase.java @@ -26,7 +26,6 @@ import android.content.pm.PackageManager; import android.content.res.Configuration; import android.os.Bundle; import android.preference.PreferenceManager; -import android.view.MotionEvent; import android.view.View; import java.util.ArrayList; @@ -40,7 +39,6 @@ import androidx.fragment.app.Fragment; abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { private boolean contacts; - private SwipeListener swipeListener; @Override protected void onCreate(Bundle savedInstanceState) { @@ -67,17 +65,6 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc super.onCreate(savedInstanceState); } - void setSwipeListener(SwipeListener.ISwipeListener listener) { - swipeListener = new SwipeListener(this, listener); - } - - @Override - public boolean dispatchTouchEvent(MotionEvent ev) { - if (swipeListener != null) - swipeListener.onTouch(null, ev); - return super.dispatchTouchEvent(ev); - } - @Override protected void onResume() { Log.i("Resume " + this.getClass().getName()); diff --git a/app/src/main/java/eu/faircode/email/FragmentMessages.java b/app/src/main/java/eu/faircode/email/FragmentMessages.java index f141ed3924..776dd95f62 100644 --- a/app/src/main/java/eu/faircode/email/FragmentMessages.java +++ b/app/src/main/java/eu/faircode/email/FragmentMessages.java @@ -44,6 +44,7 @@ import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.SubMenu; import android.view.View; import android.view.ViewGroup; @@ -298,8 +299,6 @@ public class FragmentMessages extends FragmentBase { rvMessage.setAdapter(adapter); - new ItemTouchHelper(touchHelper).attachToRecyclerView(rvMessage); - bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { @@ -401,32 +400,29 @@ public class FragmentMessages extends FragmentBase { } }); - ActivityBase activity = (ActivityBase) getActivity(); - activity.setSwipeListener(new SwipeListener.ISwipeListener() { - @Override - public boolean onSwipeRight() { - boolean swipenav = prefs.getBoolean("swipenav", true); - if (!swipenav) + boolean swipenav = prefs.getBoolean("swipenav", true); + if (swipenav) { + Log.i("Swipe navigation"); + rvMessage.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { + @Override + public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent ev) { + swipeListener.onTouch(null, ev); return false; + } - if (previous != null) - navigate(previous, true); - return (previous != null); - } - - @Override - public boolean onSwipeLeft() { - boolean swipenav = prefs.getBoolean("swipenav", true); - if (!swipenav) - return false; - - if (next != null) - navigate(next, false); - return (next != null); - } - }); + @Override + public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent ev) { + } + @Override + public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) { + } + }); + } else + new ItemTouchHelper(touchHelper).attachToRecyclerView(rvMessage); } else { + new ItemTouchHelper(touchHelper).attachToRecyclerView(rvMessage); + selectionPredicate = new SelectionPredicateMessage(rvMessage); selectionTracker = new SelectionTracker.Builder<>( @@ -819,6 +815,22 @@ public class FragmentMessages extends FragmentBase { } }; + SwipeListener swipeListener = new SwipeListener(getContext(), new SwipeListener.ISwipeListener() { + @Override + public boolean onSwipeRight() { + if (previous != null) + navigate(previous, true); + return (previous != null); + } + + @Override + public boolean onSwipeLeft() { + if (next != null) + navigate(next, false); + return (next != null); + } + }); + private void onActionMove(String folderType) { Bundle args = new Bundle(); args.putLong("account", account); diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java index 61fac831e7..92842cc1e5 100644 --- a/app/src/main/java/eu/faircode/email/FragmentOptions.java +++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java @@ -94,7 +94,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O static String[] OPTIONS_RESTART = new String[]{ "unified", "date", "threading", "avatars", "identicons", "preview", "addresses", "autoimages", "actionbar", - "pull", "autoexpand", "autoclose", "autonext", + "pull", "swipenav", "autoexpand", "autoclose", "autonext", "debug" };