X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2FMobileLedgerListFragment.java;h=a61f44f6e2417eb2d54654827e8d731c20586ac6;hb=0de6f8a521ec0cca27d3279c631e8c617c5d716a;hp=b7cafca484a8cfb98271212ae01256046122e0f3;hpb=898bf5932a1bdb2a7b197d9e0981f722111295b6;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java index b7cafca4..a61f44f6 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java @@ -1,5 +1,5 @@ /* - * Copyright © 2019 Damyan Ivanov. + * Copyright © 2021 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -30,31 +30,34 @@ import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.DimensionUtils; public class MobileLedgerListFragment extends Fragment { - public SwipeRefreshLayout swiper; + public SwipeRefreshLayout refreshLayout; public TransactionListAdapter modelAdapter; - protected MainActivity mActivity; protected RecyclerView root; + @NonNull + public MainActivity getMainActivity() { + return (MainActivity) requireActivity(); + } protected void themeChanged(Integer counter) { - swiper.setColorSchemeColors(Colors.getSwipeCircleColors()); + refreshLayout.setColorSchemeColors(Colors.getSwipeCircleColors()); } public void onBackgroundTaskRunningChanged(Boolean isRunning) { - if (mActivity == null) + if (getActivity() == null) return; - if (swiper == null) + if (refreshLayout == null) return; - swiper.setRefreshing(isRunning); + refreshLayout.setRefreshing(isRunning); } protected void manageFabOnScroll() { - int triggerPixels = DimensionUtils.dp2px(mActivity, 30f); + final MainActivity mainActivity = getMainActivity(); + int triggerPixels = DimensionUtils.dp2px(mainActivity, 10f); 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); + lastY = upAnchor = e.getAxisValue(MotionEvent.AXIS_Y); break; case MotionEvent.ACTION_MOVE: final float currentY = e.getAxisValue(MotionEvent.AXIS_Y); @@ -62,14 +65,12 @@ public class MobileLedgerListFragment extends Fragment { // swipe down upAnchor = lastY; - mActivity.fabShouldShow(); + mainActivity.fabShouldShow(); } else { // swipe up - downAnchor = lastY; - if (currentY < upAnchor - triggerPixels) - mActivity.fabHide(); + mainActivity.fabHide(); } lastY = currentY;