/*
- * 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
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);
// swipe down
upAnchor = lastY;
- mActivity.fabShouldShow();
+ mainActivity.fabShouldShow();
}
else {
// swipe up
- downAnchor = lastY;
-
if (currentY < upAnchor - triggerPixels)
- mActivity.fabHide();
+ mainActivity.fabHide();
}
lastY = currentY;