From: Damyan Ivanov Date: Fri, 29 Mar 2019 17:49:57 +0000 (+0200) Subject: spare one activity restart when the startup profile uses a non-default color theme X-Git-Tag: v0.9~29 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=4a18f169ea73b7bf85c4c018ef047a2e873319d5;p=mobile-ledger.git spare one activity restart when the startup profile uses a non-default color theme --- diff --git a/app/src/main/java/net/ktnx/mobileledger/model/Data.java b/app/src/main/java/net/ktnx/mobileledger/model/Data.java index 48555ff0..7380d613 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/Data.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/Data.java @@ -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; + } } diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index 0e51d857..ec348098 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -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);