From: Damyan Ivanov Date: Wed, 21 Apr 2021 19:44:14 +0000 (+0300) Subject: drop remnants of gradual transaction data loading, and last non-Room SQL X-Git-Tag: v0.18.0~63 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=1fe7c92ffb82a8d6e4dd354154c46b26d8afe48b;p=mobile-ledger.git drop remnants of gradual transaction data loading, and last non-Room SQL --- diff --git a/app/src/main/java/net/ktnx/mobileledger/App.java b/app/src/main/java/net/ktnx/mobileledger/App.java index d6197c56..a9a416e7 100644 --- a/app/src/main/java/net/ktnx/mobileledger/App.java +++ b/app/src/main/java/net/ktnx/mobileledger/App.java @@ -21,16 +21,13 @@ import android.app.Application; import android.content.SharedPreferences; import android.content.res.Configuration; import android.content.res.Resources; -import android.database.sqlite.SQLiteDatabase; import android.util.Log; -import net.ktnx.mobileledger.db.DB; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.ui.profiles.ProfileDetailModel; import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.Globals; import net.ktnx.mobileledger.utils.Logger; -import net.ktnx.mobileledger.utils.MobileLedgerDatabase; import org.jetbrains.annotations.NotNull; @@ -46,14 +43,7 @@ public class App extends Application { public static final String PREF_PROFILE_ID = "profile-id"; public static App instance; private static ProfileDetailModel profileModel; - private MobileLedgerDatabase dbHelper; private boolean monthNamesPrepared = false; - public static SQLiteDatabase getDatabase() { - if (instance == null) - throw new RuntimeException("Application not created yet"); - - return instance.getDB(); - } public static void prepareMonthNames() { instance.prepareMonthNames(false); } @@ -141,33 +131,10 @@ public class App extends Application { monthNamesPrepared = true; } @Override - public void onTerminate() { - Logger.debug("flow", "App onTerminate()"); - if (dbHelper != null) - dbHelper.close(); - super.onTerminate(); - } - @Override public void onConfigurationChanged(@NotNull Configuration newConfig) { super.onConfigurationChanged(newConfig); prepareMonthNames(true); Data.refreshCurrencyData(Locale.getDefault()); Data.locale.setValue(Locale.getDefault()); } - public SQLiteDatabase getDB() { - if (dbHelper == null) - initDb(); - - return dbHelper.getWritableDatabase(); - } - private synchronized void initDb() { - if (dbHelper != null) - return; - - // Let Room do any possible migrations - // this method may be removed when all DB access is made via Room - DB.get() - .compileStatement("select count(*) from profiles"); - dbHelper = new MobileLedgerDatabase(this); - } } diff --git a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java index eea0490a..7b1b4504 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -18,7 +18,6 @@ package net.ktnx.mobileledger.async; import android.annotation.SuppressLint; -import android.database.sqlite.SQLiteDatabase; import android.os.AsyncTask; import android.os.OperationCanceledException; @@ -28,7 +27,6 @@ import androidx.room.Transaction; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.RuntimeJsonMappingException; -import net.ktnx.mobileledger.App; import net.ktnx.mobileledger.dao.AccountDAO; import net.ktnx.mobileledger.dao.AccountValueDAO; import net.ktnx.mobileledger.dao.TransactionAccountDAO; @@ -436,7 +434,6 @@ public class RetrieveTransactionsTask extends throw new HTTPException(http.getResponseCode(), http.getResponseMessage()); } publishProgress(Progress.indeterminate()); - SQLiteDatabase db = App.getDatabase(); ArrayList list = new ArrayList<>(); HashMap map = new HashMap<>(); throwIfCancelled(); diff --git a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java index b9c6021f..cef83169 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java @@ -17,13 +17,9 @@ package net.ktnx.mobileledger.model; -import android.database.Cursor; -import android.database.sqlite.SQLiteDatabase; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import net.ktnx.mobileledger.App; import net.ktnx.mobileledger.db.Profile; import net.ktnx.mobileledger.db.Transaction; import net.ktnx.mobileledger.db.TransactionAccount; @@ -172,7 +168,6 @@ public class LedgerTransaction { return ledgerId; } protected void fillDataHash() { - loadData(App.getDatabase()); if (dataHash != null) return; try { @@ -206,40 +201,6 @@ public class LedgerTransaction { String.format("Unable to get instance of %s digest", DIGEST_TYPE), e); } } - public synchronized void loadData(SQLiteDatabase db) { - if (dataLoaded) - return; - - try (Cursor cTr = db.rawQuery( - "SELECT year, month, day, description, comment from transactions WHERE id=?", - new String[]{String.valueOf(ledgerId)})) - { - if (cTr.moveToFirst()) { - date = new SimpleDate(cTr.getInt(0), cTr.getInt(1), cTr.getInt(2)); - description = cTr.getString(3); - comment = cTr.getString(4); - - accounts.clear(); - - try (Cursor cAcc = db.rawQuery( - "SELECT account_name, amount, currency, comment FROM " + - "transaction_accounts WHERE transaction_id = ?", - new String[]{String.valueOf(ledgerId)})) - { - while (cAcc.moveToNext()) { -// debug("transactions", -// String.format("Loaded %d: %s %1.2f %s", id, cAcc.getString(0), -// cAcc.getFloat(1), cAcc.getString(2))); - addAccount(new LedgerTransactionAccount(cAcc.getString(0), cAcc.getFloat(1), - cAcc.getString(2), cAcc.getString(3))); - } - - finishLoading(); - } - } - } - - } public String getDataHash() { fillDataHash(); return dataHash; diff --git a/app/src/main/java/net/ktnx/mobileledger/model/TransactionListItem.java b/app/src/main/java/net/ktnx/mobileledger/model/TransactionListItem.java index 550a84c5..82a15f36 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/TransactionListItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/TransactionListItem.java @@ -20,7 +20,6 @@ package net.ktnx.mobileledger.model; import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import net.ktnx.mobileledger.App; import net.ktnx.mobileledger.utils.SimpleDate; import org.jetbrains.annotations.NotNull; @@ -53,9 +52,8 @@ public class TransactionListItem { public SimpleDate getDate() { if (date != null) return date; - if (type == Type.HEADER) - throw new IllegalStateException("Header item has no date"); - transaction.loadData(App.getDatabase()); + if (type != Type.TRANSACTION) + throw new IllegalStateException("Only transaction items have a date"); return transaction.getDate(); } public boolean isMonthShown() {