control/save state of drawer being open via a MutableLiveData instance
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 10 Jun 2020 19:47:01 +0000 (19:47 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 10 Jun 2020 19:47:01 +0000 (19:47 +0000)
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java
app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java

index 8b4def9..2289635 100644 (file)
@@ -59,6 +59,7 @@ public final class Data {
     private static AtomicInteger backgroundTaskCount = new AtomicInteger(0);
     private static Locker profilesLocker = new Locker();
     private static RetrieveTransactionsTask retrieveTransactionsTask;
+    public static MutableLiveData<Boolean> drawerOpen = new MutableLiveData<>(false);
     public static void backgroundTaskStarted() {
         int cnt = backgroundTaskCount.incrementAndGet();
         debug("data",
index b44c30f..98ec7aa 100644 (file)
@@ -317,6 +317,13 @@ public class MainActivity extends ProfileThemedActivity {
             };
             drawer.addDrawerListener(drawerListener);
         }
+
+        Data.drawerOpen.observe(this, open -> {
+            if (open)
+                drawer.open();
+            else
+                drawer.close();
+        });
     }
     private void scheduleDataRetrievalIfStale(Date lastUpdate) {
         long now = new Date().getTime();
@@ -425,8 +432,6 @@ public class MainActivity extends ProfileThemedActivity {
 
         mProfileListAdapter.notifyDataSetChanged();
 
-        drawer.closeDrawers();
-
         Data.transactions.clear();
         debug("transactions", "requesting list reload");
         TransactionListViewModel.scheduleTransactionListReload();
index 84dab3c..974c979 100644 (file)
@@ -136,6 +136,8 @@ public class ProfilesRecyclerViewAdapter
         if (profile == null)
             throw new IllegalStateException("Profile row without associated profile");
         debug("profiles", "Setting profile to " + profile.getName());
+        if (Data.profile.getValue() != profile )
+            Data.drawerOpen.setValue(false);
         Data.setCurrentProfile(profile);
     }
     @NonNull