package net.ktnx.mobileledger.ui;
+import android.view.MotionEvent;
+
import net.ktnx.mobileledger.ui.activity.MainActivity;
import net.ktnx.mobileledger.ui.transaction_list.TransactionListAdapter;
import net.ktnx.mobileledger.utils.Colors;
+import net.ktnx.mobileledger.utils.DimensionUtils;
+import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
public class MobileLedgerListFragment extends Fragment {
- protected MainActivity mActivity;
public SwipeRefreshLayout swiper;
- protected RecyclerView root;
public TransactionListAdapter modelAdapter;
+ protected MainActivity mActivity;
+ protected RecyclerView root;
protected void themeChanged(Integer counter) {
swiper.setColorSchemeColors(Colors.primary);
}
if (swiper == null) return;
swiper.setRefreshing(isRunning);
}
+ protected void manageFabOnScroll() {
+ int triggerPixels = DimensionUtils.dp2px(mActivity, 30f);
+ root.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
+ private float upAnchor = -1;
+ private float downAnchor = -1;
+ private float lastY;
+ @Override
+ public boolean onInterceptTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
+ switch (e.getActionMasked()) {
+ case MotionEvent.ACTION_DOWN:
+ lastY = upAnchor = downAnchor = e.getAxisValue(MotionEvent.AXIS_Y);
+ break;
+ case MotionEvent.ACTION_MOVE:
+ final float currentY = e.getAxisValue(MotionEvent.AXIS_Y);
+ if (currentY > lastY) {
+ // swipe down
+ upAnchor = lastY;
+
+ mActivity.fabShouldShow();
+ }
+ else {
+ // swipe up
+ downAnchor = lastY;
+
+ if (currentY < upAnchor - triggerPixels) mActivity.fabHide();
+ }
+
+ lastY = currentY;
+
+ break;
+ }
+ return false;
+ }
+ @Override
+ public void onTouchEvent(@NonNull RecyclerView rv, @NonNull MotionEvent e) {
+ }
+ @Override
+ public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
+ }
+ });
+ }
}
// }));
mActivity.fabShouldShow();
- root.addOnScrollListener(new RecyclerView.OnScrollListener() {
- @Override
- public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
- if (fab != null) {
- if (dy < 0) mActivity.fabShouldShow();
- if (dy > 0) fab.hide();
- }
- }
- });
+
+ manageFabOnScroll();
+
swiper = mActivity.findViewById(R.id.account_swiper);
Colors.themeWatch.observe(this, this::themeChanged);
swiper.setOnRefreshListener(() -> {
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
import static android.content.Context.INPUT_METHOD_SERVICE;
import static net.ktnx.mobileledger.utils.Logger.debug;
FloatingActionButton fab = mActivity.findViewById(R.id.btn_add_transaction);
mActivity.fabShouldShow();
- root.addOnScrollListener(new RecyclerView.OnScrollListener() {
- @Override
- public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
- if (dy < 0) mActivity.fabShouldShow();
- if (dy > 0) fab.hide();
- }
- });
+
+ manageFabOnScroll();
LinearLayoutManager llm = new LinearLayoutManager(mActivity);