From: Damyan Ivanov Date: Thu, 6 May 2021 19:42:14 +0000 (+0300) Subject: add commodity support to template editor X-Git-Tag: v0.19.0~24 X-Git-Url: https://git.ktnx.net/?a=commitdiff_plain;h=fa6ed80a6ea4cfb968a60e45423980c2ab513531;p=mobile-ledger.git add commodity support to template editor --- 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