]> git.ktnx.net Git - mobile-ledger.git/commitdiff
drop remnants of gradual transaction data loading, and last non-Room SQL
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 21 Apr 2021 19:44:14 +0000 (22:44 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Wed, 21 Apr 2021 20:01:58 +0000 (23:01 +0300)
app/src/main/java/net/ktnx/mobileledger/App.java
app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java
app/src/main/java/net/ktnx/mobileledger/model/LedgerTransaction.java
app/src/main/java/net/ktnx/mobileledger/model/TransactionListItem.java

index d6197c568a63a5a98e78f93c42db8c5aff3b4468..a9a416e7bb3c15a8e49c51f1aedb45f1307d0bee 100644 (file)
@@ -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);
-    }
 }
index eea0490afe59ea8cf950a6af980eca7a1ada5655..7b1b4504300c9656b083b0a21ae09a9cc7a0d014 100644 (file)
@@ -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<LedgerAccount> list = new ArrayList<>();
         HashMap<String, LedgerAccount> map = new HashMap<>();
         throwIfCancelled();
index b9c6021fd43f28be0112ce9f9c2dba557c89624b..cef83169f7a35ec21b304f08eb7c0b5b9dd25983 100644 (file)
 
 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;
index 550a84c5ed25d020ea0d488db89d3e634dd81582..82a15f36f8b61c3a3cdfb44d668f3380684d347a 100644 (file)
@@ -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() {