]> git.ktnx.net Git - mobile-ledger.git/commitdiff
App: make the Room database handle available
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 29 Jan 2021 05:22:32 +0000 (05:22 +0000)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 29 Jan 2021 11:27:04 +0000 (11:27 +0000)
app/src/main/java/net/ktnx/mobileledger/App.java

index a492e8a418ea1cfeb0c20e0d3e514d032ae55fd9..7935beba307d7ffe4ff1eef8dcbef45a38535e2d 100644 (file)
@@ -23,6 +23,9 @@ import android.content.res.Resources;
 import android.database.sqlite.SQLiteDatabase;
 import android.util.Log;
 
+import androidx.room.Room;
+
+import net.ktnx.mobileledger.db.DB;
 import net.ktnx.mobileledger.model.Data;
 import net.ktnx.mobileledger.ui.profiles.ProfileDetailModel;
 import net.ktnx.mobileledger.utils.Globals;
@@ -42,12 +45,22 @@ public class App extends Application {
     private static ProfileDetailModel profileModel;
     private MobileLedgerDatabase dbHelper;
     private boolean monthNamesPrepared = false;
+    private DB roomDatabase;
     public static SQLiteDatabase getDatabase() {
         if (instance == null)
             throw new RuntimeException("Application not created yet");
 
         return instance.getDB();
     }
+    public static DB getRoomDB() {
+        if (instance == null)
+            throw new RuntimeException("Application not created yet");
+
+        return instance.getRoomDatabase();
+    }
+    public DB getRoomDatabase(){
+        return roomDatabase;
+    }
     public static void prepareMonthNames() {
         instance.prepareMonthNames(false);
     }
@@ -86,6 +99,8 @@ public class App extends Application {
         Logger.debug("flow", "App onCreate()");
         instance = this;
         super.onCreate();
+        roomDatabase = Room.databaseBuilder(this, DB.class, MobileLedgerDatabase.DB_NAME)
+                              .build();
         Data.refreshCurrencyData(Locale.getDefault());
         Authenticator.setDefault(new Authenticator() {
             @Override