- public void onActivityCreated(@Nullable Bundle savedInstanceState) {
- Log.d("flow", "TransactionListFragment.onActivityCreated called");
- super.onActivityCreated(savedInstanceState);
-
- mActivity.markDrawerItemCurrent(R.id.nav_latest_transactions);
-
- swiper = mActivity.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);
- if (root == null) throw new RuntimeException("Can't get hold on the transaction list view");
- progressBar = mActivity.findViewById(R.id.transaction_list_progress_bar);
- if (progressBar == null)
- throw new RuntimeException("Can't get hold on the transaction list progress bar");
- progressLayout = mActivity.findViewById(R.id.transaction_progress_layout);
- if (progressLayout == null) throw new RuntimeException(
- "Can't get hold on the transaction list progress bar layout");
- tvLastUpdate = mActivity.findViewById(R.id.transactions_last_update);
- updateLastUpdateText();
- model = ViewModelProviders.of(this).get(TransactionListViewModel.class);
- modelAdapter = new TransactionListAdapter(model);
-
- modelAdapter.setBoldAccountName(mShowOnlyAccountName);
-
- FloatingActionButton fab = mActivity.findViewById(R.id.btn_add_transaction);
-
- RecyclerView root = mActivity.findViewById(R.id.transaction_root);
- root.setAdapter(modelAdapter);
-
- fab.show();
- root.addOnScrollListener(new RecyclerView.OnScrollListener() {
- @Override
- public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
- if (fab != null) {
- if (dy < 0) fab.show();
- if (dy > 0) fab.hide();
- }
- }
+ public void onResume() {
+ super.onResume();
+ fragmentActive = true;
+ toggleMenuItems();
+ debug("flow", "TransactionListFragment.onResume()");
+ }
+ private void toggleMenuItems() {
+ if (menuGoToDate != null)
+ menuGoToDate.setVisible(fragmentActive);
+ if (menuTransactionListFilter != null) {
+ final int filterVisibility = b.transactionListAccountNameFilter.getVisibility();
+ menuTransactionListFilter.setVisible(
+ fragmentActive && filterVisibility != View.VISIBLE);
+ }
+ }
+ @Override
+ public void onStop() {
+ super.onStop();
+ fragmentActive = false;
+ toggleMenuItems();
+ debug("flow", "TransactionListFragment.onStop()");
+ }
+ @Override
+ public void onPause() {
+ super.onPause();
+ fragmentActive = false;
+ toggleMenuItems();
+ debug("flow", "TransactionListFragment.onPause()");
+ }
+ @Override
+ public SwipeRefreshLayout getRefreshLayout() {
+ return b.transactionSwipe;
+ }
+ @Override
+ public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
+ debug("flow", "TransactionListFragment.onActivityCreated called");
+ super.onViewCreated(view, savedInstanceState);
+ Data.backgroundTasksRunning.observe(getViewLifecycleOwner(),
+ this::onBackgroundTaskRunningChanged);
+
+ MainActivity mainActivity = getMainActivity();
+
+ model = new ViewModelProvider(requireActivity()).get(MainModel.class);
+
+ modelAdapter = new TransactionListAdapter();
+ b.transactionRoot.setAdapter(modelAdapter);
+
+ mainActivity.fabShouldShow();
+
+ if (mainActivity instanceof FabManager.FabHandler)
+ FabManager.handle(mainActivity, b.transactionRoot);
+
+ LinearLayoutManager llm = new LinearLayoutManager(mainActivity);
+
+ llm.setOrientation(RecyclerView.VERTICAL);
+ b.transactionRoot.setLayoutManager(llm);
+
+ b.transactionSwipe.setOnRefreshListener(() -> {
+ debug("ui", "refreshing transactions via swipe");
+ model.scheduleTransactionListRetrieval();