]> git.ktnx.net Git - mobile-ledger.git/commitdiff
central method for retrieving a profile by its UUID
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 4 Apr 2019 11:33:21 +0000 (14:33 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Thu, 4 Apr 2019 11:34:35 +0000 (14:34 +0300)
loads the profile list is not done before

app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java

index 60fb9239898e41daa9252c496acbd62d8e8089bf..1c67956677188a1f86bfbc02f456134478cdc7ee 100644 (file)
@@ -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;
+    }
 }
index d711247b5b5cdca63faa36dada771761b6b0ca16..3bfb2b6e4517274aadc1be501e4a10c13eebd3bd 100644 (file)
@@ -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);