]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/ui/MobileLedgerListFragment.java
drop unused/unneeded variables
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / ui / MobileLedgerListFragment.java
index 13c4fe04bd1d61d41045f841831a35e6625c3c23..74247189649883fbb1be0c7012cf0f5980b8c804 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2019 Damyan Ivanov.
+ * Copyright © 2020 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.getColors());
+        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, 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);
+                        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;