Refactored swipe listener

This commit is contained in:
M66B 2019-02-06 10:59:10 +00:00
parent 0b08d00d61
commit 03c1ddd9ce
3 changed files with 37 additions and 38 deletions

View File

@ -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());

View File

@ -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);

View File

@ -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"
};