From: Damyan Ivanov Date: Wed, 10 Jun 2020 19:47:01 +0000 (+0000) Subject: control/save state of drawer being open via a MutableLiveData instance X-Git-Tag: v0.14.0~41 X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=commitdiff_plain;h=5fb830346325e20be596a09118d377b26f09779b control/save state of drawer being open via a MutableLiveData instance --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Data.java b/app/src/main/java/net/ktnx/mobileledger/model/Data.java index 8b4def95..2289635d 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -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 drawerOpen = new MutableLiveData<>(false); public static void backgroundTaskStarted() { int cnt = backgroundTaskCount.incrementAndGet(); debug("data", diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index b44c30f2..98ec7aaa 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -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(); diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java index 84dab3c9..974c9793 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/profiles/ProfilesRecyclerViewAdapter.java @@ -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