]> git.ktnx.net Git - mobile-ledger.git/commitdiff
spare one activity restart when the startup profile uses a non-default color theme
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 29 Mar 2019 17:49:57 +0000 (19:49 +0200)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 29 Mar 2019 17:49:57 +0000 (19:49 +0200)
app/src/main/java/net/ktnx/mobileledger/model/Data.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java

index 48555ff0102c3bf07e00d000ff9492915e730f83..7380d613db32e0bb5c2fb0b7d16267a9e7afa82d 100644 (file)
@@ -17,6 +17,9 @@
 
 package net.ktnx.mobileledger.model;
 
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+
 import net.ktnx.mobileledger.utils.LockHolder;
 import net.ktnx.mobileledger.utils.MLDB;
 import net.ktnx.mobileledger.utils.ObservableAtomicInteger;
@@ -50,4 +53,15 @@ public final class Data {
             return -1;
         }
     }
+    public static int retrieveCurrentThemeIdFromDb() {
+        String profileUUID = MLDB.getOption(MLDB.OPT_PROFILE_UUID, null);
+        if (profileUUID == null) return -1;
+
+        SQLiteDatabase db = MLDB.getDatabase();
+        try(Cursor c = db.rawQuery("SELECT theme from profiles where uuid=?", new String[]{profileUUID})) {
+            if (c.moveToNext()) return c.getInt(0);
+        }
+
+        return -1;
+    }
 }
index 0e51d8570a93aba86da9a1ef3875ba21afd77a46..ec34809819e4a9968d2ef9cc9d99d54a4fe33911 100644 (file)
@@ -131,6 +131,9 @@ public class MainActivity extends ProfileThemedActivity {
     protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         Log.d("flow", "MainActivity.onCreate()");
+        int profileColor = Data.retrieveCurrentThemeIdFromDb();
+        Colors.setupTheme(this, profileColor);
+        Colors.profileThemeId = profileColor;
         setContentView(R.layout.activity_main);
 
         fab = findViewById(R.id.btn_add_transaction);