]> git.ktnx.net Git - mobile-ledger.git/commitdiff
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 8b4def9509547d89fb4c92c7bd47551167360b3d..2289635d7524551b941294f8d7a096ab8212621a 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 b44c30f270ef6c2b3c77943c6172d48d67388863..98ec7aaa524ab7bf26dfed6db181119d7f1a68c7 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 84dab3c9b7d44d6c014e0b2bef352a19ad18f143..974c979322f79ff0e2f7c74aab3dc07e8cd93d2f 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