X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2FApp.java;h=b47e6d7faf14533a272517e4ac971badb0266061;hp=fb69138b8cdcdf273fe29f410daa49007d428dbf;hb=64bb8277f3c747f0ef2dcb48f898fb4ec07b64ee;hpb=208de18485b4706d133ba820101ccf04ad20e947 diff --git a/app/src/main/java/net/ktnx/mobileledger/App.java b/app/src/main/java/net/ktnx/mobileledger/App.java index fb69138b..b47e6d7f 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 © 2019 Damyan Ivanov. + * Copyright © 2020 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 @@ -29,6 +29,8 @@ import net.ktnx.mobileledger.utils.Globals; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.MobileLedgerDatabase; +import org.jetbrains.annotations.NotNull; + import java.net.Authenticator; import java.net.MalformedURLException; import java.net.PasswordAuthentication; @@ -38,6 +40,7 @@ import java.util.Locale; public class App extends Application { public static App instance; private MobileLedgerDatabase dbHelper; + private boolean monthNamesPrepared = false; public static SQLiteDatabase getDatabase() { if (instance == null) throw new RuntimeException("Application not created yet"); @@ -48,7 +51,6 @@ public class App extends Application { Logger.debug("flow", "App onCreate()"); instance = this; super.onCreate(); - updateMonthNames(); Data.refreshCurrencyData(Locale.getDefault()); Authenticator.setDefault(new Authenticator() { @Override @@ -75,26 +77,35 @@ public class App extends Application { } }); } - private void updateMonthNames() { + public static void prepareMonthNames() { + instance.prepareMonthNames(false); + } + private void prepareMonthNames(boolean force) { + if (force || monthNamesPrepared) + return; Resources rm = getResources(); Globals.monthNames = rm.getStringArray(R.array.month_names); + monthNamesPrepared = true; } @Override public void onTerminate() { Logger.debug("flow", "App onTerminate()"); - if (dbHelper != null) dbHelper.close(); + if (dbHelper != null) + dbHelper.close(); super.onTerminate(); } @Override - public void onConfigurationChanged(Configuration newConfig) { + public void onConfigurationChanged(@NotNull Configuration newConfig) { super.onConfigurationChanged(newConfig); - updateMonthNames(); + prepareMonthNames(true); + Data.refreshCurrencyData(Locale.getDefault()); + Data.locale.setValue(Locale.getDefault()); } public SQLiteDatabase getDB() { - if (dbHelper == null) initDb(); + if (dbHelper == null) + initDb(); final SQLiteDatabase db = dbHelper.getWritableDatabase(); - db.execSQL("pragma case_sensitive_like=ON;"); return db; }