From f397735f4ef56cc287e3345d23eac91909e3e2f3 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 3 May 2019 19:07:06 +0300 Subject: [PATCH] properly detect when profile list hasn't loaded yet --- app/src/main/java/net/ktnx/mobileledger/model/Data.java | 5 ++--- .../net/ktnx/mobileledger/ui/activity/MainActivity.java | 8 ++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) 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 2a6f0d5f..7687d237 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -50,7 +50,7 @@ public final class Data { public static MutableLiveData lastUpdateDate = new MutableLiveData<>(); public static MutableLiveData profile = new MutableLiveData<>(); public static MutableLiveData> profiles = - new MutableLiveData<>(new ArrayList<>()); + new MutableLiveData<>(null); public static ObservableValue optShowOnlyStarred = new ObservableValue<>(); public static MutableLiveData accountFilter = new MutableLiveData<>(); private static AtomicInteger backgroundTaskCount = new AtomicInteger(0); @@ -117,8 +117,7 @@ public final class Data { MobileLedgerProfile profile; try (LockHolder readLock = profilesLocker.lockForReading()) { List prList = profiles.getValue(); - assert prList != null; - if (prList.isEmpty()) { + if ((prList == null) || prList.isEmpty()) { readLock.close(); try (LockHolder ignored = profilesLocker.lockForWriting()) { profile = MobileLedgerProfile.loadAllFromDB(profileUUID); 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 e7e534fe..484bcb01 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 @@ -342,6 +342,14 @@ public class MainActivity extends ProfileThemedActivity { sm.setDynamicShortcuts(shortcuts); } private void onProfileListChanged(List newList) { + if (newList == null) { + // profiles not yet loaded from DB + findViewById(R.id.loading_layout).setVisibility(View.VISIBLE); + findViewById(R.id.no_profiles_layout).setVisibility(View.GONE); + findViewById(R.id.pager_layout).setVisibility(View.GONE); + return; + } + if (newList.isEmpty()) { findViewById(R.id.no_profiles_layout).setVisibility(View.VISIBLE); findViewById(R.id.pager_layout).setVisibility(View.GONE); -- 2.39.2