X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fmodel%2FMobileLedgerProfile.java;h=b8085765eb069048f78cfe5621e93ef8e5887268;hb=a063310fe70a3c451636e25d334cbdcacec677eb;hp=fcbd9203ef0852dcd3cf52d95e947ef0c3265155;hpb=a87079ed41bdc3ad89fe8bd15dfba10e37b29b76;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java index fcbd9203..b8085765 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/MobileLedgerProfile.java @@ -1,5 +1,5 @@ /* - * Copyright © 2020 Damyan Ivanov. + * 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 @@ -17,9 +17,12 @@ package net.ktnx.mobileledger.model; +import android.content.Context; +import android.content.Intent; import android.content.res.Resources; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; +import android.os.Bundle; import android.text.TextUtils; import android.util.SparseArray; @@ -28,7 +31,9 @@ import androidx.annotation.Nullable; import net.ktnx.mobileledger.App; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.async.DbOpQueue; -import net.ktnx.mobileledger.async.SendTransactionTask; +import net.ktnx.mobileledger.json.API; +import net.ktnx.mobileledger.ui.profiles.ProfileDetailActivity; +import net.ktnx.mobileledger.ui.profiles.ProfileDetailFragment; import net.ktnx.mobileledger.utils.Logger; import net.ktnx.mobileledger.utils.Misc; import net.ktnx.mobileledger.utils.SimpleDate; @@ -59,7 +64,7 @@ public final class MobileLedgerProfile { private String authPassword; private int themeHue; private int orderNo = -1; - private SendTransactionTask.API apiVersion = SendTransactionTask.API.auto; + private API apiVersion = API.auto; private FutureDates futureDates = FutureDates.None; private boolean accountsLoaded; private boolean transactionsLoaded; @@ -161,6 +166,17 @@ public final class MobileLedgerProfile { db.endTransaction(); } } + static public void startEditProfileActivity(Context context, MobileLedgerProfile profile) { + Intent intent = new Intent(context, ProfileDetailActivity.class); + Bundle args = new Bundle(); + if (profile != null) { + int index = Data.getProfileIndex(profile); + if (index != -1) + intent.putExtra(ProfileDetailFragment.ARG_ITEM_ID, index); + } + intent.putExtras(args); + context.startActivity(intent, args); + } public HledgerVersion getDetectedVersion() { return detectedVersion; } @@ -232,14 +248,14 @@ public final class MobileLedgerProfile { else this.defaultCommodity = String.valueOf(defaultCommodity); } - public SendTransactionTask.API getApiVersion() { + public API getApiVersion() { return apiVersion; } - public void setApiVersion(SendTransactionTask.API apiVersion) { + public void setApiVersion(API apiVersion) { this.apiVersion = apiVersion; } public void setApiVersion(int apiVersion) { - this.apiVersion = SendTransactionTask.API.valueOf(apiVersion); + this.apiVersion = API.valueOf(apiVersion); } public FutureDates getFutureDates() { return futureDates; @@ -613,6 +629,25 @@ public final class MobileLedgerProfile { new AccountAndTransactionListSaver(this, accounts, transactions); accountAndTransactionListSaver.start(); } + private Currency tryLoadCurrencyById(SQLiteDatabase db, int id) { + try (Cursor cursor = db.rawQuery( + "SELECT c.id, c.name, c.position, c.has_gap FROM currencies c WHERE c.id=?", + new String[]{String.valueOf(id)})) + { + if (cursor.moveToFirst()) { + return new Currency(cursor.getInt(0), cursor.getString(1), + Currency.Position.valueOf(cursor.getString(2)), cursor.getInt(3) == 1); + } + return null; + } + } + public Currency loadCurrencyById(int id) { + SQLiteDatabase db = App.getDatabase(); + Currency result = tryLoadCurrencyById(db, id); + if (result == null) + throw new RuntimeException(String.format("Unable to load currency with id '%d'", id)); + return result; + } public enum FutureDates { None(0), OneWeek(7), TwoWeeks(14), OneMonth(30), TwoMonths(60), ThreeMonths(90),