Refactored swipe listener

pull/147/head
M66B 6 years ago
parent 0b08d00d61
commit 03c1ddd9ce

@ -26,7 +26,6 @@ import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Bundle; import android.os.Bundle;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import java.util.ArrayList; import java.util.ArrayList;
@ -40,7 +39,6 @@ import androidx.fragment.app.Fragment;
abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { abstract class ActivityBase extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
private boolean contacts; private boolean contacts;
private SwipeListener swipeListener;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -67,17 +65,6 @@ abstract class ActivityBase extends AppCompatActivity implements SharedPreferenc
super.onCreate(savedInstanceState); 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 @Override
protected void onResume() { protected void onResume() {
Log.i("Resume " + this.getClass().getName()); Log.i("Resume " + this.getClass().getName());

@ -44,6 +44,7 @@ import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.SubMenu; import android.view.SubMenu;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -298,8 +299,6 @@ public class FragmentMessages extends FragmentBase {
rvMessage.setAdapter(adapter); rvMessage.setAdapter(adapter);
new ItemTouchHelper(touchHelper).attachToRecyclerView(rvMessage);
bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { bottom_navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
@ -401,32 +400,29 @@ public class FragmentMessages extends FragmentBase {
} }
}); });
ActivityBase activity = (ActivityBase) getActivity(); boolean swipenav = prefs.getBoolean("swipenav", true);
activity.setSwipeListener(new SwipeListener.ISwipeListener() { if (swipenav) {
@Override Log.i("Swipe navigation");
public boolean onSwipeRight() { rvMessage.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
boolean swipenav = prefs.getBoolean("swipenav", true); @Override
if (!swipenav) public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent ev) {
return false; swipeListener.onTouch(null, ev);
if (previous != null)
navigate(previous, true);
return (previous != null);
}
@Override
public boolean onSwipeLeft() {
boolean swipenav = prefs.getBoolean("swipenav", true);
if (!swipenav)
return false; return false;
}
if (next != null) @Override
navigate(next, false); public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent ev) {
return (next != null); }
}
});
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
} else
new ItemTouchHelper(touchHelper).attachToRecyclerView(rvMessage);
} else { } else {
new ItemTouchHelper(touchHelper).attachToRecyclerView(rvMessage);
selectionPredicate = new SelectionPredicateMessage(rvMessage); selectionPredicate = new SelectionPredicateMessage(rvMessage);
selectionTracker = new SelectionTracker.Builder<>( 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) { private void onActionMove(String folderType) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("account", account); args.putLong("account", account);

@ -94,7 +94,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
static String[] OPTIONS_RESTART = new String[]{ static String[] OPTIONS_RESTART = new String[]{
"unified", "date", "threading", "avatars", "identicons", "preview", "addresses", "autoimages", "actionbar", "unified", "date", "threading", "avatars", "identicons", "preview", "addresses", "autoimages", "actionbar",
"pull", "autoexpand", "autoclose", "autonext", "pull", "swipenav", "autoexpand", "autoclose", "autonext",
"debug" "debug"
}; };

Loading…
Cancel
Save