]> git.ktnx.net Git - mobile-ledger.git/commitdiff
fall back to any profile when restoring config
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 22 Aug 2021 17:14:22 +0000 (20:14 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sun, 22 Aug 2021 17:14:22 +0000 (20:14 +0300)
it would be strange to happen, because the config should always have
a current profile, but who knows… defensive programming

app/src/main/java/net/ktnx/mobileledger/async/ConfigReader.java

index 16b9ac24527608e792c00892c7ff587ccf99abae..bc95a8f8024472d2869b8b185da27db10824cc0f 100644 (file)
@@ -92,10 +92,16 @@ public class ConfigReader extends ConfigIO {
         restoreProfiles(profiles);
         restoreTemplates(templates);
 
-        if (Data.getProfile() == null && currentProfile != null) {
-            Profile p = DB.get()
-                          .getProfileDAO()
-                          .getByUuidSync(currentProfile);
+        if (Data.getProfile() == null) {
+            Profile p = null;
+            final ProfileDAO dao = DB.get()
+                                     .getProfileDAO();
+            if (currentProfile != null)
+                p = dao.getByUuidSync(currentProfile);
+
+            if (p == null)
+                dao.getAnySync();
+
             if (p != null)
                 Data.postCurrentProfile(p);
         }