]> git.ktnx.net Git - mobile-ledger.git/commitdiff
also restore the current profile from the cloud backup
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 3 Sep 2022 15:47:56 +0000 (15:47 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Sat, 3 Sep 2022 15:47:56 +0000 (15:47 +0000)
app/src/main/java/net/ktnx/mobileledger/backup/RawConfigReader.java

index 45a593d7add390a4898f191d1a1b49d15de62232..95b27b32ed85a2975799b64e11855e8f17ead7ed 100644 (file)
@@ -20,6 +20,7 @@ package net.ktnx.mobileledger.backup;
 import android.util.JsonReader;
 import android.util.JsonToken;
 
+import net.ktnx.mobileledger.App;
 import net.ktnx.mobileledger.backup.ConfigIO.Keys;
 import net.ktnx.mobileledger.dao.CurrencyDAO;
 import net.ktnx.mobileledger.dao.ProfileDAO;
@@ -30,6 +31,8 @@ import net.ktnx.mobileledger.db.Profile;
 import net.ktnx.mobileledger.db.TemplateAccount;
 import net.ktnx.mobileledger.db.TemplateHeader;
 import net.ktnx.mobileledger.db.TemplateWithAccounts;
+import net.ktnx.mobileledger.model.Data;
+import net.ktnx.mobileledger.utils.Logger;
 
 import java.io.BufferedReader;
 import java.io.IOException;
@@ -337,6 +340,7 @@ public class RawConfigReader {
         restoreCommodities();
         restoreProfiles();
         restoreTemplates();
+        restoreCurrentProfile();
     }
     private void restoreTemplates() {
         if (templates == null)
@@ -374,4 +378,24 @@ public class RawConfigReader {
                 dao.insert(c);
         }
     }
+    private void restoreCurrentProfile() {
+        if (currentProfile == null) {
+            Logger.debug("backup", "Not restoring current profile (not present in backup)");
+            return;
+        }
+
+        ProfileDAO dao = DB.get()
+                           .getProfileDAO();
+
+        Profile p = dao.getByUuidSync(currentProfile);
+
+        if (p != null) {
+            Logger.debug("backup", "Restoring current profile "+p.getName());
+            Data.postCurrentProfile(p);
+            App.storeStartupProfileAndTheme(p.getId(), p.getTheme());
+        }
+        else {
+            Logger.debug("backup", "Not restoring profile "+currentProfile+": not found in DB");
+        }
+    }
 }