From fa6ed80a6ea4cfb968a60e45423980c2ab513531 Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Thu, 6 May 2021 22:42:14 +0300 Subject: [PATCH] add commodity support to template editor --- .../model/TemplateDetailsItem.java | 12 +++++ .../ui/templates/TemplateDetailsAdapter.java | 54 ++++++++++++++++++- .../res/layout/template_details_account.xml | 33 ++++++++++++ app/src/main/res/values-bg/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 99 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java index 67d6a4f3..9a8f04ce 100644 --- a/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java +++ b/app/src/main/java/net/ktnx/mobileledger/model/TemplateDetailsItem.java @@ -384,6 +384,7 @@ abstract public class TemplateDetailsItem { public boolean hasLiteralAccountComment() { return accountComment.hasLiteralValue(); } + public boolean hasLiteralCurrency() { return currency.hasLiteralValue(); } public boolean equalContents(AccountRow o) { if (position != o.position) { Logger.debug("cmpAcc", @@ -398,6 +399,9 @@ abstract public class TemplateDetailsItem { public void switchToLiteralAmount() { amount.switchToLiteral(); } + public void switchToLiteralCurrency() { + currency.switchToLiteral(); + } public void switchToLiteralAccountName() { accountName.switchToLiteral(); } @@ -426,6 +430,14 @@ abstract public class TemplateDetailsItem { result.setNegateAmount(negateAmount ? true : null); } + if (currency.hasLiteralValue()) { + net.ktnx.mobileledger.db.Currency c = currency.getValue(); + result.setCurrency((c == null) ? null : c.getId()); + } + else { + result.setCurrencyMatchGroup(currency.getMatchGroup()); + } + return result; } public boolean isEmpty() { diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java index eae2ba33..ccf1b813 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/templates/TemplateDetailsAdapter.java @@ -30,6 +30,7 @@ import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.lifecycle.LifecycleOwner; import androidx.recyclerview.widget.AsyncListDiffer; import androidx.recyclerview.widget.DiffUtil; import androidx.recyclerview.widget.ItemTouchHelper; @@ -40,8 +41,10 @@ import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.databinding.TemplateDetailsAccountBinding; import net.ktnx.mobileledger.databinding.TemplateDetailsHeaderBinding; import net.ktnx.mobileledger.db.AccountAutocompleteAdapter; +import net.ktnx.mobileledger.db.DB; import net.ktnx.mobileledger.model.Data; import net.ktnx.mobileledger.model.TemplateDetailsItem; +import net.ktnx.mobileledger.ui.CurrencySelectorFragment; import net.ktnx.mobileledger.ui.HelpDialog; import net.ktnx.mobileledger.ui.QR; import net.ktnx.mobileledger.ui.TemplateDetailSourceSelectorFragment; @@ -277,7 +280,7 @@ class TemplateDetailsAdapter extends RecyclerView.Adapter selectAccountRowDetailSource(v, AccDetail.ACCOUNT)); @@ -832,6 +850,32 @@ class TemplateDetailsAdapter extends RecyclerView.Adapter selectAccountRowDetailSource(v, AccDetail.AMOUNT)); b.templateDetailsAccountAmountSource.setOnClickListener( v -> selectAccountRowDetailSource(v, AccDetail.AMOUNT)); + b.templateDetailsAccountCurrencySource.setOnClickListener( + v -> selectAccountRowDetailSource(v, AccDetail.CURRENCY)); + b.templateAccountCurrencySourceLabel.setOnClickListener( + v -> selectAccountRowDetailSource(v, AccDetail.CURRENCY)); + if (accRow.hasLiteralCurrency()) + b.templateDetailsAccountCurrency.setOnClickListener(v -> { + CurrencySelectorFragment cpf = CurrencySelectorFragment.newInstance( + CurrencySelectorFragment.DEFAULT_COLUMN_COUNT, false); + cpf.setOnCurrencySelectedListener(text -> { + if (text == null) { + b.templateDetailsAccountCurrency.setText(R.string.btn_no_currency); + accRow.setCurrency(null); + } + else { + b.templateDetailsAccountCurrency.setText(text); + DB.get() + .getCurrencyDAO() + .getByName(text) + .observe((LifecycleOwner) b.getRoot() + .getContext(), accRow::setCurrency); + } + }); + cpf.show( + ((TemplatesActivity) b.templateDetailsAccountCurrency.getContext()).getSupportFragmentManager(), + "currency-selector"); + }); } finally { enableUpdatePropagation(); @@ -861,6 +905,9 @@ class TemplateDetailsAdapter extends RecyclerView.Adapter + + + + \ No newline at end of file diff --git a/app/src/main/res/values-bg/strings.xml b/app/src/main/res/values-bg/strings.xml index af958a08..9b49a7fe 100644 --- a/app/src/main/res/values-bg/strings.xml +++ b/app/src/main/res/values-bg/strings.xml @@ -188,4 +188,5 @@ Макети Параметри на макета Помощна информация за пааметрите на макета + Източник на валутата diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4e928c7f..49b483a0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -197,4 +197,5 @@ Templates Template parameters Show help on template parameters + Commodity source -- 2.39.5