]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/db/DB.java
asynchronous profile initialisation
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / db / DB.java
index 2e7ca655c8cf8271d5c446dba8e14b906dd2e1c0..ca2d9092bd7f693e765565980456cae9628f8c4e 100644 (file)
@@ -18,6 +18,7 @@
 package net.ktnx.mobileledger.db;
 
 import android.content.res.Resources;
+import android.database.Cursor;
 import android.database.SQLException;
 
 import androidx.annotation.NonNull;
@@ -97,6 +98,25 @@ abstract public class DB extends RoomDatabase {
                 String fileName = String.format(Locale.US, "db_%d", toVersion);
 
                 applyRevisionFile(db, fileName);
+
+                // when migrating to version 59, migrate profile/theme options to the
+                // SharedPreferences
+                if (toVersion == 59) {
+                    try (Cursor c = db.query(
+                            "SELECT p.id, p.theme_hue FROM profiles p WHERE p.id=(SELECT o.value " +
+                            "FROM options WHERE o.profile_uid IS NULL AND o.name=?",
+                            new Object[]{"profile_id"}))
+                    {
+                        if (c.moveToFirst()) {
+                            long currentProfileId = c.getLong(0);
+                            int currentTheme = c.getInt(1);
+
+                            if (currentProfileId >= 0 && currentTheme >= 0) {
+                                App.storeStartupProfileAndTheme(currentProfileId, currentTheme);
+                            }
+                        }
+                    }
+                }
             }
         };
     }