import android.database.SQLException;
import androidx.annotation.NonNull;
+import androidx.lifecycle.MutableLiveData;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
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)
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;
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() {
.getProfileDAO()
.getProfileCountSync();
- MobileLedgerDatabase.initComplete.postValue(true);
+ DB.initComplete.postValue(true);
}
}
}
+++ /dev/null
-/*
- * 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");
- }
-}