]> git.ktnx.net Git - mobile-ledger.git/commitdiff
work around trans. list menu items visible with setOffscreenPageLimit(1)
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 30 Apr 2021 06:34:12 +0000 (09:34 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 30 Apr 2021 19:20:20 +0000 (19:20 +0000)
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

app/src/main/java/net/ktnx/mobileledger/ui/transaction_list/TransactionListFragment.java

index e15349803dc1bee40f94c6a3003d42830c8b56d9..c9fd0bf33f51a75b0af907dd504eb07985cba65c 100644 (file)
@@ -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) {