From: Damyan Ivanov Date: Thu, 4 Apr 2019 11:33:21 +0000 (+0300) Subject: central method for retrieving a profile by its UUID X-Git-Tag: v0.9~8 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=307ffaaba0125a98b3cb867d3db79b2e7a7fb7b5;p=mobile-ledger.git central method for retrieving a profile by its UUID loads the profile list is not done before --- 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);