From 6e815a8613c191e76a4346f0e23b88bf50a8b02c Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Tue, 20 Apr 2021 22:55:04 +0300 Subject: [PATCH] drop now unused MLDB class along with its async db routines --- .../async/RetrieveTransactionsTask.java | 3 +- .../java/net/ktnx/mobileledger/db/Option.java | 1 + .../ui/activity/MainActivity.java | 4 +- .../net/ktnx/mobileledger/utils/MLDB.java | 124 ------------------ 4 files changed, 4 insertions(+), 128 deletions(-) delete mode 100644 app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java 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 88c3ee83..eea0490a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java +++ b/app/src/main/java/net/ktnx/mobileledger/async/RetrieveTransactionsTask.java @@ -51,7 +51,6 @@ import net.ktnx.mobileledger.model.LedgerTransaction; import net.ktnx.mobileledger.model.LedgerTransactionAccount; import net.ktnx.mobileledger.ui.MainModel; import net.ktnx.mobileledger.utils.Logger; -import net.ktnx.mobileledger.utils.MLDB; import net.ktnx.mobileledger.utils.NetworkUtil; import java.io.BufferedReader; @@ -662,7 +661,7 @@ public class RetrieveTransactionsTask extends DB.get() .getOptionDAO() - .insertSync(new Option(profile.getId(), MLDB.OPT_LAST_SCRAPE, + .insertSync(new Option(profile.getId(), Option.OPT_LAST_SCRAPE, String.valueOf((new Date()).getTime()))); } public void throwIfCancelled() { diff --git a/app/src/main/java/net/ktnx/mobileledger/db/Option.java b/app/src/main/java/net/ktnx/mobileledger/db/Option.java index dfecf56e..8fabb551 100644 --- a/app/src/main/java/net/ktnx/mobileledger/db/Option.java +++ b/app/src/main/java/net/ktnx/mobileledger/db/Option.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; @Entity(tableName = "options", primaryKeys = {"profile_id", "name"}) public class Option { + public static final String OPT_LAST_SCRAPE = "last_scrape"; @ColumnInfo(name = "profile_id") private long profileId; @NonNull diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java index c917bb9e..55392876 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/MainActivity.java @@ -53,6 +53,7 @@ import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.async.RetrieveTransactionsTask; import net.ktnx.mobileledger.databinding.ActivityMainBinding; import net.ktnx.mobileledger.db.DB; +import net.ktnx.mobileledger.db.Option; import net.ktnx.mobileledger.db.Profile; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.ui.FabManager; @@ -65,7 +66,6 @@ import net.ktnx.mobileledger.ui.templates.TemplatesActivity; import net.ktnx.mobileledger.ui.transaction_list.TransactionListFragment; import net.ktnx.mobileledger.utils.Colors; import net.ktnx.mobileledger.utils.Logger; -import net.ktnx.mobileledger.utils.MLDB; import org.jetbrains.annotations.NotNull; @@ -543,7 +543,7 @@ public class MainActivity extends ProfileThemedActivity implements FabManager.Fa DB.get() .getOptionDAO() - .load(profile.getId(), MLDB.OPT_LAST_SCRAPE) + .load(profile.getId(), Option.OPT_LAST_SCRAPE) .observe(this, opt -> { long lastUpdate = 0; if (opt != null) { diff --git a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java b/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java deleted file mode 100644 index 6521dedc..00000000 --- a/app/src/main/java/net/ktnx/mobileledger/utils/MLDB.java +++ /dev/null @@ -1,124 +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.database.Cursor; -import android.database.sqlite.SQLiteDatabase; - -import androidx.annotation.NonNull; - -import net.ktnx.mobileledger.App; -import net.ktnx.mobileledger.async.DbOpQueue; - -import org.jetbrains.annotations.NonNls; - -import static net.ktnx.mobileledger.utils.Logger.debug; - -public final class MLDB { - public static final String ACCOUNTS_TABLE = "accounts"; - public static final String DESCRIPTION_HISTORY_TABLE = "description_history"; - public static final String OPT_LAST_SCRAPE = "last_scrape"; - @NonNls - public static final String OPT_PROFILE_ID = "profile_id"; - public static final long NO_PROFILE = 0; - @SuppressWarnings("unused") - static public long getLongOption(String name, long default_value) { - String s = getOption(name, String.valueOf(default_value)); - try { - return Long.parseLong(s); - } - catch (Exception e) { - debug("db", "returning default long value of " + name, e); - return default_value; - } - } - static public String getOption(String name, String default_value) { - debug("db", "about to fetch option " + name); - SQLiteDatabase db = App.getDatabase(); - try (Cursor cursor = db.rawQuery("select value from options where profile_id=? and name=?", - new String[]{String.valueOf(NO_PROFILE), name})) - { - if (cursor.moveToFirst()) { - String result = cursor.getString(0); - - if (result == null) - result = default_value; - - debug("db", "option " + name + "=" + result); - return result; - } - else - return default_value; - } - catch (Exception e) { - debug("db", "returning default value for " + name, e); - return default_value; - } - } - static public void setOption(String name, String value) { - debug("option", String.format("%s := %s", name, value)); - DbOpQueue.add("insert or replace into options(profile_id, name, value) values(?, ?, ?);", - new String[]{String.valueOf(NO_PROFILE), name, value}); - } - @SuppressWarnings("unused") - static public void setLongOption(String name, long value) { - setOption(name, String.valueOf(value)); - } - public static void queryInBackground(@NonNull String statement, String[] params, - @NonNull final CallbackHelper callbackHelper) { - /* All callbacks are called in the new (asynchronous) thread! */ - Thread t = new Thread(() -> { - callbackHelper.onStart(); - try { - SQLiteDatabase db = App.getDatabase(); - - try (Cursor cursor = db.rawQuery(statement, params)) { - boolean gotRow = false; - while (cursor.moveToNext()) { - gotRow = true; - if (!callbackHelper.onRow(cursor)) - break; - } - if (!gotRow) { - callbackHelper.onNoRows(); - } - } - } - catch (Exception e) { - callbackHelper.onException(e); - } - finally { - callbackHelper.onDone(); - } - }); - - t.start(); - } - /* MLDB.CallbackHelper -- Abstract class for asynchronous SQL query callbacks */ - @SuppressWarnings("WeakerAccess") - abstract public static class CallbackHelper { - public void onStart() {} - public abstract boolean onRow(@NonNull Cursor cursor); - public void onNoRows() {} - public void onException(Exception exception) { - Logger.debug("MLDB", "Exception in asynchronous SQL", exception); - } - public void onDone() {} - } -} - -- 2.39.5