/*
- * 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
public class MobileLedgerListFragment extends Fragment {
public SwipeRefreshLayout swiper;
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());
}
public void onBackgroundTaskRunningChanged(Boolean isRunning) {
- if (mActivity == null)
+ if (getActivity() == null)
return;
if (swiper == null)
return;
swiper.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;
// swipe down
upAnchor = lastY;
- mActivity.fabShouldShow();
+ mainActivity.fabShouldShow();
}
else {
// swipe up
downAnchor = lastY;
if (currentY < upAnchor - triggerPixels)
- mActivity.fabHide();
+ mainActivity.fabHide();
}
lastY = currentY;
public void onAttach(@NotNull Context context) {
super.onAttach(context);
debug("flow", "AccountSummaryFragment.onAttach()");
- mActivity = (MainActivity) context;
}
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
this::onBackgroundTaskRunningChanged);
modelAdapter = new AccountSummaryAdapter();
+ MainActivity mainActivity = getMainActivity();
- root = mActivity.findViewById(R.id.account_root);
- LinearLayoutManager llm = new LinearLayoutManager(mActivity);
+ root = mainActivity.findViewById(R.id.account_root);
+ LinearLayoutManager llm = new LinearLayoutManager(mainActivity);
llm.setOrientation(RecyclerView.VERTICAL);
root.setLayoutManager(llm);
root.setAdapter(modelAdapter);
DividerItemDecoration did =
- new DividerItemDecoration(mActivity, DividerItemDecoration.VERTICAL);
+ new DividerItemDecoration(mainActivity, DividerItemDecoration.VERTICAL);
root.addItemDecoration(did);
- mActivity.fabShouldShow();
+ mainActivity.fabShouldShow();
manageFabOnScroll();
- swiper = mActivity.findViewById(R.id.account_swiper);
+ swiper = mainActivity.findViewById(R.id.account_swiper);
Colors.themeWatch.observe(getViewLifecycleOwner(), this::themeChanged);
swiper.setOnRefreshListener(() -> {
debug("ui", "refreshing accounts via swipe");
- Data.scheduleTransactionListRetrieval(mActivity);
+ Data.scheduleTransactionListRetrieval(mainActivity);
});
Data.accounts.addObserver(
- (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
+ (o, arg) -> mainActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
}
}
package net.ktnx.mobileledger.ui.transaction_list;
-import android.content.Context;
import android.database.Cursor;
import android.os.AsyncTask;
import android.os.Bundle;
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
}
- @Override
- public void onAttach(@NotNull Context context) {
- super.onAttach(context);
- mActivity = (MainActivity) context;
- }
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
Data.backgroundTasksRunning.observe(getViewLifecycleOwner(),
this::onBackgroundTaskRunningChanged);
- swiper = mActivity.findViewById(R.id.transaction_swipe);
+ MainActivity mainActivity = getMainActivity();
+
+ swiper = mainActivity.findViewById(R.id.transaction_swipe);
if (swiper == null)
throw new RuntimeException("Can't get hold on the swipe layout");
- root = mActivity.findViewById(R.id.transaction_root);
+ root = mainActivity.findViewById(R.id.transaction_root);
if (root == null)
throw new RuntimeException("Can't get hold on the transaction value view");
modelAdapter = new TransactionListAdapter();
root.setAdapter(modelAdapter);
- mActivity.fabShouldShow();
+ mainActivity.fabShouldShow();
manageFabOnScroll();
- LinearLayoutManager llm = new LinearLayoutManager(mActivity);
+ LinearLayoutManager llm = new LinearLayoutManager(mainActivity);
llm.setOrientation(RecyclerView.VERTICAL);
root.setLayoutManager(llm);
swiper.setOnRefreshListener(() -> {
debug("ui", "refreshing transactions via swipe");
- Data.scheduleTransactionListRetrieval(mActivity);
+ Data.scheduleTransactionListRetrieval(mainActivity);
});
Colors.themeWatch.observe(getViewLifecycleOwner(), this::themeChanged);
- vAccountFilter = mActivity.findViewById(R.id.transaction_list_account_name_filter);
- accNameFilter = mActivity.findViewById(R.id.transaction_filter_account_name);
+ vAccountFilter = mainActivity.findViewById(R.id.transaction_list_account_name_filter);
+ accNameFilter = mainActivity.findViewById(R.id.transaction_filter_account_name);
- MLDB.hookAutocompletionAdapter(mActivity, accNameFilter, "accounts", "name");
+ MLDB.hookAutocompletionAdapter(mainActivity, accNameFilter, "accounts", "name");
accNameFilter.setOnItemClickListener((parent, view, position, id) -> {
// debug("tmp", "direct onItemClick");
Cursor c = (Cursor) parent.getItemAtPosition(position);
Data.accountFilter.setValue(c.getString(1));
- Globals.hideSoftKeyboard(mActivity);
+ Globals.hideSoftKeyboard(mainActivity);
});
Data.accountFilter.observe(getViewLifecycleOwner(), this::onAccountNameFilterChanged);
TransactionListViewModel.updateError.set(null);
});
Data.transactions.addObserver(
- (o, arg) -> mActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
+ (o, arg) -> mainActivity.runOnUiThread(() -> modelAdapter.notifyDataSetChanged()));
- mActivity.findViewById(R.id.clearAccountNameFilter)
- .setOnClickListener(v -> {
- Data.accountFilter.setValue(null);
- vAccountFilter.setVisibility(View.GONE);
- menuTransactionListFilter.setVisible(true);
- Globals.hideSoftKeyboard(mActivity);
- });
+ mainActivity.findViewById(R.id.clearAccountNameFilter)
+ .setOnClickListener(v -> {
+ Data.accountFilter.setValue(null);
+ vAccountFilter.setVisibility(View.GONE);
+ menuTransactionListFilter.setVisible(true);
+ Globals.hideSoftKeyboard(mainActivity);
+ });
Data.foundTransactionItemIndex.observe(getViewLifecycleOwner(), pos -> {
Logger.debug("go-to-date", String.format(Locale.US, "Found pos %d", pos));
menuTransactionListFilter.setVisible(false);
accNameFilter.requestFocus();
InputMethodManager imm =
- (InputMethodManager) mActivity.getSystemService(INPUT_METHOD_SERVICE);
+ (InputMethodManager) getMainActivity().getSystemService(INPUT_METHOD_SERVICE);
imm.showSoftInput(accNameFilter, 0);
return true;