]> git.ktnx.net Git - mobile-ledger.git/commitdiff
drop MobileLedgerDatabase, move initComplete to DB
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 21 Apr 2021 20:09:28 +0000 (23:09 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 21 Apr 2021 20:09:28 +0000 (23:09 +0300)
app/src/main/java/net/ktnx/mobileledger/db/DB.java
app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java
app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java [deleted file]

index 41b6f7c0ba2110af2d41c1b3b40b71bf6b6e82b2..cff1d9c14f62452ad80c0af679e81099477a1263 100644 (file)
@@ -22,6 +22,7 @@ import android.database.Cursor;
 import android.database.SQLException;
 
 import androidx.annotation.NonNull;
+import androidx.lifecycle.MutableLiveData;
 import androidx.room.Database;
 import androidx.room.Room;
 import androidx.room.RoomDatabase;
@@ -59,6 +60,7 @@ import static net.ktnx.mobileledger.utils.Logger.debug;
 abstract public class DB extends RoomDatabase {
     public static final int REVISION = 59;
     public static final String DB_NAME = "MoLe.db";
+    public static final MutableLiveData<Boolean> initComplete = new MutableLiveData<>(false);
     private static DB instance;
     public static DB get() {
         if (instance != null)
index b868366b9d94bdf1529a428cd0d5fe2147c1de90..a31e7d4cce726f651f853ed3e50d9b56fcdec16f 100644 (file)
@@ -26,7 +26,6 @@ import androidx.annotation.Nullable;
 import net.ktnx.mobileledger.R;
 import net.ktnx.mobileledger.db.DB;
 import net.ktnx.mobileledger.utils.Logger;
-import net.ktnx.mobileledger.utils.MobileLedgerDatabase;
 
 import java.util.Locale;
 
@@ -41,8 +40,8 @@ public class SplashActivity extends CrashReportingActivity {
         setContentView(R.layout.splash_activity_layout);
         Logger.debug("splash", "onCreate()");
 
-        MobileLedgerDatabase.initComplete.setValue(false);
-        MobileLedgerDatabase.initComplete.observe(this, this::onDbInitDoneChanged);
+        DB.initComplete.setValue(false);
+        DB.initComplete.observe(this, this::onDbInitDoneChanged);
     }
     @Override
     protected void onStart() {
@@ -107,7 +106,7 @@ public class SplashActivity extends CrashReportingActivity {
                              .getProfileDAO()
                              .getProfileCountSync();
 
-            MobileLedgerDatabase.initComplete.postValue(true);
+            DB.initComplete.postValue(true);
         }
     }
 }
diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java b/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java
deleted file mode 100644 (file)
index 911c203..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.utils;
-
-import android.app.Application;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-
-import androidx.lifecycle.MutableLiveData;
-
-import net.ktnx.mobileledger.db.DB;
-
-import static net.ktnx.mobileledger.utils.Logger.debug;
-
-public class MobileLedgerDatabase extends SQLiteOpenHelper {
-    public static final MutableLiveData<Boolean> initComplete = new MutableLiveData<>(false);
-    public MobileLedgerDatabase(Application context) {
-        super(context, DB.DB_NAME, null, DB.REVISION);
-        debug("db", "creating helper instance");
-        super.setWriteAheadLoggingEnabled(true);
-    }
-
-    @Override
-    public void onCreate(SQLiteDatabase db) {
-        throw new IllegalStateException("Should not happen. Where's Room!?");
-    }
-    @Override
-    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
-        throw new IllegalStateException("Should not happen. Where's Room!?");
-    }
-
-    @Override
-    public void onConfigure(SQLiteDatabase db) {
-        super.onConfigure(db);
-        // force a check by Room to ensure everything is OK
-        // TODO: remove when all DB access is via Room
-        DB.get()
-          .compileStatement("SELECT COUNT(*) FROM profiles");
-    }
-}