From 63ea6894b7553608858bb794bc4d2581794d3ced Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Sat, 3 Sep 2022 15:47:56 +0000 Subject: [PATCH] also restore the current profile from the cloud backup --- .../mobileledger/backup/RawConfigReader.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/app/src/main/java/net/ktnx/mobileledger/backup/RawConfigReader.java b/app/src/main/java/net/ktnx/mobileledger/backup/RawConfigReader.java index 45a593d7..95b27b32 100644 --- a/app/src/main/java/net/ktnx/mobileledger/backup/RawConfigReader.java +++ b/app/src/main/java/net/ktnx/mobileledger/backup/RawConfigReader.java @@ -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"); + } + } } -- 2.39.5