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 60fb923..1c67956 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 d711247..3bfb2b6 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);