X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2FApp.java;h=a781ccf105bebc377117bd8d5744ce79e2f8c00d;hb=fac0809065787fb473646db5770f4f2fae0d1e8f;hp=a492e8a418ea1cfeb0c20e0d3e514d032ae55fd9;hpb=9662c07481ca878f4e4ff23c2923737241a3f3b4;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/App.java b/app/src/main/java/net/ktnx/mobileledger/App.java index a492e8a4..a781ccf1 100644 --- a/app/src/main/java/net/ktnx/mobileledger/App.java +++ b/app/src/main/java/net/ktnx/mobileledger/App.java @@ -1,5 +1,5 @@ /* - * Copyright © 2020 Damyan Ivanov. + * Copyright © 2021 Damyan Ivanov. * This file is part of MoLe. * MoLe is free software: you can distribute it and/or modify it * under the term of the GNU General Public License as published by @@ -18,13 +18,16 @@ package net.ktnx.mobileledger; import android.app.Application; +import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; import android.database.sqlite.SQLiteDatabase; import android.util.Log; +import net.ktnx.mobileledger.db.DB; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.ui.profiles.ProfileDetailModel; +import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.Globals; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.MobileLedgerDatabase; @@ -38,6 +41,9 @@ import java.net.URL; import java.util.Locale; public class App extends Application { + public static final String PREF_NAME = "MoLe"; + public static final String PREF_THEME_HUE = "theme-hue"; + public static final String PREF_PROFILE_ID = "profile-id"; public static App instance; private static ProfileDetailModel profileModel; private MobileLedgerDatabase dbHelper; @@ -57,6 +63,23 @@ public class App extends Application { public static void resetAuthenticationData() { profileModel = null; } + public static void storeStartupProfileAndTheme(long currentProfileId, int currentTheme) { + SharedPreferences prefs = + instance.getSharedPreferences(PREF_NAME, MODE_PRIVATE); + SharedPreferences.Editor editor = prefs.edit(); + editor.putLong(PREF_PROFILE_ID, + currentProfileId); + editor.putInt(PREF_THEME_HUE, currentTheme); + editor.apply(); + } + public static long getStartupProfile() { + SharedPreferences prefs = instance.getSharedPreferences(PREF_NAME, MODE_PRIVATE); + return prefs.getLong(PREF_PROFILE_ID, -1); + } + public static int getStartupTheme() { + SharedPreferences prefs = instance.getSharedPreferences(PREF_NAME, MODE_PRIVATE); + return prefs.getInt(PREF_THEME_HUE, Colors.DEFAULT_HUE_DEG); + } private String getAuthURL() { if (profileModel != null) return profileModel.getUrl(); @@ -143,6 +166,10 @@ public class App extends Application { if (dbHelper != null) return; + // Let Room do any possible migrations + // this method may be removed when all DB access is made via Room + DB.get() + .compileStatement("select count(*) from profiles"); dbHelper = new MobileLedgerDatabase(this); } }