public boolean hasLiteralAccountComment() {
return accountComment.hasLiteralValue();
}
+ public boolean hasLiteralCurrency() { return currency.hasLiteralValue(); }
public boolean equalContents(AccountRow o) {
if (position != o.position) {
Logger.debug("cmpAcc",
public void switchToLiteralAmount() {
amount.switchToLiteral();
}
+ public void switchToLiteralCurrency() {
+ currency.switchToLiteral();
+ }
public void switchToLiteralAccountName() {
accountName.switchToLiteral();
}
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() {
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;
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;
private enum HeaderDetail {DESCRIPTION, COMMENT, DATE_YEAR, DATE_MONTH, DATE_DAY}
- private enum AccDetail {ACCOUNT, COMMENT, AMOUNT}
+ private enum AccDetail {ACCOUNT, COMMENT, AMOUNT, CURRENCY}
public abstract static class ViewHolder extends RecyclerView.ViewHolder {
ViewHolder(@NonNull View itemView) {
b.templateDetailsNegateAmountText.setVisibility(View.VISIBLE);
}
- // TODO: currency
+ if (accRow.hasLiteralCurrency()) {
+ b.templateDetailsAccountCurrencySource.setText(
+ R.string.template_details_source_literal);
+ net.ktnx.mobileledger.db.Currency c = accRow.getCurrency();
+ if (c == null)
+ b.templateDetailsAccountCurrency.setText(R.string.btn_no_currency);
+ else
+ b.templateDetailsAccountCurrency.setText(c.getName());
+ b.templateDetailsAccountCurrency.setVisibility(View.VISIBLE);
+ }
+ else {
+ b.templateDetailsAccountCurrencySource.setText(
+ String.format(Locale.US, groupNoText, accRow.getCurrencyMatchGroup(),
+ getMatchGroupText(accRow.getCurrencyMatchGroup())));
+ b.templateDetailsAccountCurrency.setVisibility(View.GONE);
+ }
b.templateAccountNameSourceLabel.setOnClickListener(
v -> selectAccountRowDetailSource(v, AccDetail.ACCOUNT));
v -> 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();
case AMOUNT:
accRow.switchToLiteralAmount();
break;
+ case CURRENCY:
+ accRow.switchToLiteralCurrency();
+ break;
default:
throw new IllegalStateException("Unexpected detail " + detail);
}
case AMOUNT:
accRow.setAmountMatchGroup(group);
break;
+ case CURRENCY:
+ accRow.setCurrencyMatchGroup(group);
+ break;
default:
throw new IllegalStateException("Unexpected detail " + detail);
}
android:selectAllOnFocus="true"
/>
</com.google.android.material.textfield.TextInputLayout>
+
<TextView
android:id="@+id/template_details_negate_amount_label"
android:layout_width="0dp"
app:layout_constraintTop_toTopOf="@id/template_details_negate_amount_label"
/>
+ <TextView
+ android:id="@+id/template_account_currency_source_label"
+ android:layout_width="0dp"
+ android:layout_height="match_parent"
+ android:layout_marginTop="@dimen/text_margin"
+ android:text="@string/account_currency_source_label"
+ android:textAppearance="?attr/textAppearanceListItem"
+ app:layout_constraintBottom_toTopOf="@+id/template_details_account_currency_source"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/negate_amount_switch"
+ />
+ <TextView
+ android:id="@+id/template_details_account_currency_source"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:textAppearance="?attr/textAppearanceListItemSecondary"
+ app:layout_constraintBottom_toTopOf="@+id/template_details_account_currency"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/template_account_currency_source_label"
+ />
+ <TextView
+ android:id="@+id/template_details_account_currency"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_marginVertical="@dimen/half_text_margin"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/template_details_account_currency_source"
+ />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file