From b668c61f3c8968c51033e7d82a08993b57b098e0 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Wed, 21 Apr 2021 23:09:28 +0300 Subject: [PATCH] drop MobileLedgerDatabase, move initComplete to DB --- .../java/net/ktnx/mobileledger/db/DB.java | 2 + .../ui/activity/SplashActivity.java | 7 +-- .../utils/MobileLedgerDatabase.java | 55 ------------------- 3 files changed, 5 insertions(+), 59 deletions(-) delete mode 100644 app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java diff --git a/app/src/main/java/net/ktnx/mobileledger/db/DB.java b/app/src/main/java/net/ktnx/mobileledger/db/DB.java index 41b6f7c0..cff1d9c1 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/DB.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/DB.java @@ -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 initComplete = new MutableLiveData<>(false); private static DB instance; public static DB get() { if (instance != null) diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java index b868366b..a31e7d4c 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/SplashActivity.java @@ -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 index 911c2034..00000000 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MobileLedgerDatabase.java +++ /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 . - */ - -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 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"); - } -} -- 2.39.2