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 48555ff..7380d61 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 0e51d85..ec34809 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);