From 307ffaaba0125a98b3cb867d3db79b2e7a7fb7b5 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 4 Apr 2019 14:33:21 +0300 Subject: [PATCH] central method for retrieving a profile by its UUID loads the profile list is not done before --- .../java/net/ktnx/mobileledger/model/Data.java | 14 ++++++++++++++ .../mobileledger/ui/activity/MainActivity.java | 11 +---------- 2 files changed, 15 insertions(+), 10 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 60fb9239..1c679566 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -74,4 +74,18 @@ public final class Data { return -1; } + public static MobileLedgerProfile getProfile(String profileUUID) { + MobileLedgerProfile profile; + if (profiles.isEmpty()) { + profile = MobileLedgerProfile.loadAllFromDB(profileUUID); + } + else { + try (LockHolder lh = profiles.lockForReading()) { + int i = getProfileIndex(profileUUID); + if (i == -1) i = 0; + profile = profiles.get(i); + } + } + return profile; + } } 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 d711247b..3bfb2b6e 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 @@ -416,16 +416,7 @@ public class MainActivity extends ProfileThemedActivity { String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null); MobileLedgerProfile profile; - if (Data.profiles.isEmpty()) { - profile = MobileLedgerProfile.loadAllFromDB(profileUUID); - } - else { - try (LockHolder lh = Data.profiles.lockForReading()) { - int i = Data.getProfileIndex(profileUUID); - if (i == -1) i = 0; - profile = Data.profiles.get(i); - } - } + profile = Data.getProfile(profileUUID); if (Data.profiles.isEmpty()) { findViewById(R.id.no_profiles_layout).setVisibility(View.VISIBLE); -- 2.39.5