From 062d4edbcf358be32ef08d4ebbf85fddf272e82e Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 30 Apr 2021 09:34:12 +0300 Subject: [PATCH] work around trans. list menu items visible with setOffscreenPageLimit(1) with that call the transaction list fragment is loaded nicely off-screen, but also it menu items get in the action bar. of the fragment is navigated to and away they hide as before, but the initial load is still a problem --- .../TransactionListFragment.java | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java index e1534980..c9fd0bf3 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java @@ -59,9 +59,11 @@ import static net.ktnx.mobileledger.utils.Logger.debug; public class TransactionListFragment extends MobileLedgerListFragment implements DatePickerFragment.DatePickedListener { private MenuItem menuTransactionListFilter; + private MenuItem menuGoToDate; private View vAccountFilter; private AutoCompleteTextView accNameFilter; private MainModel model; + private boolean fragmentActive = false; @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -76,16 +78,31 @@ public class TransactionListFragment extends MobileLedgerListFragment @Override 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 = vAccountFilter.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 @@ -172,7 +189,7 @@ public class TransactionListFragment extends MobileLedgerListFragment private void onAccountNameFilterChanged(String accName) { accNameFilter.setText(accName, false); - final boolean filterActive = (accName != null) && !accName.isEmpty(); + boolean filterActive = (accName != null) && !accName.isEmpty(); if (vAccountFilter != null) { vAccountFilter.setVisibility(filterActive ? View.VISIBLE : View.GONE); } @@ -186,6 +203,9 @@ public class TransactionListFragment extends MobileLedgerListFragment menuTransactionListFilter = menu.findItem(R.id.menu_transaction_list_filter); if ((menuTransactionListFilter == null)) throw new AssertionError(); + menuGoToDate = menu.findItem(R.id.menu_go_to_date); + if ((menuGoToDate == null)) + throw new AssertionError(); model.getAccountFilter() .observe(this, v -> menuTransactionListFilter.setVisible(v == null)); @@ -203,15 +223,15 @@ public class TransactionListFragment extends MobileLedgerListFragment return true; }); - menu.findItem(R.id.menu_go_to_date) - .setOnMenuItemClickListener(item -> { - DatePickerFragment picker = new DatePickerFragment(); - picker.setOnDatePickedListener(this); - picker.setDateRange(model.getFirstTransactionDate(), - model.getLastTransactionDate()); - picker.show(requireActivity().getSupportFragmentManager(), null); - return true; - }); + menuGoToDate.setOnMenuItemClickListener(item -> { + DatePickerFragment picker = new DatePickerFragment(); + picker.setOnDatePickedListener(this); + picker.setDateRange(model.getFirstTransactionDate(), model.getLastTransactionDate()); + picker.show(requireActivity().getSupportFragmentManager(), null); + return true; + }); + + toggleMenuItems(); } @Override public void onDatePicked(int year, int month, int day) { -- 2.39.5