/*
- * 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
import android.annotation.SuppressLint;
import android.graphics.Typeface;
import android.text.Editable;
+import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.View;
private final TextView tvCurrency;
private final Observer<Boolean> showCommentsObserver;
private final TextView tvTransactionComment;
+ private final TextView tvDate;
+ private final AutoCompleteTextView tvDescription;
+ private final TextView tvDummy;
+ private final AutoCompleteTextView tvAccount;
+ private final TextView tvComment;
+ private final EditText tvAmount;
+ private final ViewGroup lHead;
+ private final ViewGroup lAccount;
+ private final FrameLayout lPadding;
+ private final MobileLedgerProfile mProfile;
+ private final Observer<SimpleDate> dateObserver;
+ private final Observer<String> descriptionObserver;
+ private final Observer<String> transactionCommentObserver;
+ private final Observer<String> hintObserver;
+ private final Observer<Integer> focusedAccountObserver;
+ private final Observer<Integer> accountCountObserver;
+ private final Observer<Boolean> editableObserver;
+ private final Observer<Currency.Position> currencyPositionObserver;
+ private final Observer<Boolean> currencyGapObserver;
+ private final Observer<Locale> localeObserver;
+ private final Observer<Currency> currencyObserver;
+ private final Observer<Boolean> showCurrencyObserver;
+ private final Observer<String> commentObserver;
+ private final Observer<Boolean> amountValidityObserver;
+ private final View tvCurrencyButton;
private String decimalSeparator;
private NewTransactionModel.Item item;
- private TextView tvDate;
- private AutoCompleteTextView tvDescription;
- private TextView tvDummy;
- private AutoCompleteTextView tvAccount;
- private TextView tvComment;
- private EditText tvAmount;
- private ViewGroup lHead;
- private ViewGroup lAccount;
- private FrameLayout lPadding;
- private MobileLedgerProfile mProfile;
private Date date;
- private Observer<SimpleDate> dateObserver;
- private Observer<String> descriptionObserver;
- private Observer<String> transactionCommentObserver;
- private Observer<String> hintObserver;
- private Observer<Integer> focusedAccountObserver;
- private Observer<Integer> accountCountObserver;
- private Observer<Boolean> editableObserver;
- private Observer<Currency.Position> currencyPositionObserver;
- private Observer<Boolean> currencyGapObserver;
- private Observer<Locale> localeObserver;
- private Observer<Currency> currencyObserver;
- private Observer<Boolean> showCurrencyObserver;
- private Observer<String> commentObserver;
- private Observer<Boolean> amountValidityObserver;
private boolean inUpdate = false;
private boolean syncingData = false;
//TODO multiple amounts with different currencies per posting
new TextViewClearHelper().attachToTextView((EditText) tvComment);
tvAmount = itemView.findViewById(R.id.account_row_acc_amounts);
tvCurrency = itemView.findViewById(R.id.currency);
+ tvCurrencyButton = lAccount.findViewById(R.id.currencyButton);
tvDate = itemView.findViewById(R.id.new_transaction_date);
tvDescription = itemView.findViewById(R.id.new_transaction_description);
tvDummy = itemView.findViewById(R.id.dummy_text);
try {
final int pos = getAdapterPosition();
adapter.updateFocusedItem(pos);
- switch (id) {
- case R.id.account_row_acc_name:
- adapter.noteFocusIsOnAccount(pos);
- break;
- case R.id.account_row_acc_amounts:
- adapter.noteFocusIsOnAmount(pos);
- break;
- case R.id.comment:
- adapter.noteFocusIsOnComment(pos);
- break;
- case R.id.transaction_comment:
- adapter.noteFocusIsOnTransactionComment(pos);
- break;
- case R.id.new_transaction_description:
- adapter.noteFocusIsOnDescription(pos);
- break;
+ if (id == R.id.account_row_acc_name) {
+ adapter.noteFocusIsOnAccount(pos);
+ }
+ else if (id == R.id.account_row_acc_amounts) {
+ adapter.noteFocusIsOnAmount(pos);
+ }
+ else if (id == R.id.comment) {
+ adapter.noteFocusIsOnComment(pos);
+ }
+ else if (id == R.id.transaction_comment) {
+ adapter.noteFocusIsOnTransactionComment(pos);
+ }
+ else if (id == R.id.new_transaction_description) {
+ adapter.noteFocusIsOnDescription(pos);
}
}
finally {
tvComment.addTextChangedListener(tw);
tvAmount.addTextChangedListener(amountWatcher);
- tvCurrency.setOnClickListener(v -> {
+ tvCurrencyButton.setOnClickListener(v -> {
CurrencySelectorFragment cpf = new CurrencySelectorFragment();
cpf.showPositionAndPadding();
cpf.setOnCurrencySelectedListener(c -> item.setCurrency(c));
final View focusedView = tvTransactionComment.findFocus();
tvTransactionComment.setTypeface(null,
(focusedView == tvTransactionComment) ? Typeface.NORMAL : Typeface.ITALIC);
- tvTransactionComment.setVisibility(((focusedView != tvTransactionComment) &&
- Misc.isEmptyOrNull(transactionComment))
- ? View.INVISIBLE : View.VISIBLE);
+ tvTransactionComment.setVisibility(
+ ((focusedView != tvTransactionComment) && TextUtils.isEmpty(transactionComment))
+ ? View.INVISIBLE : View.VISIBLE);
};
hintObserver = hint -> {
break;
case Description:
boolean focused = tvDescription.requestFocus();
- tvDescription.dismissDropDown();
+// tvDescription.dismissDropDown();
if (focused)
Misc.showSoftKeyboard(
(NewTransactionActivity) tvDescription.getContext());
showCurrencyObserver = showCurrency -> {
if (showCurrency) {
tvCurrency.setVisibility(View.VISIBLE);
+ tvCurrencyButton.setVisibility(View.VISIBLE);
+ String defaultCommodity = mProfile.getDefaultCommodity();
+ item.setCurrency(
+ (defaultCommodity == null) ? null : Currency.loadByName(defaultCommodity));
}
else {
tvCurrency.setVisibility(View.GONE);
+ tvCurrencyButton.setVisibility(View.GONE);
item.setCurrency(null);
}
};
tvComment.setTypeface(null,
(focusedView == tvComment) ? Typeface.NORMAL : Typeface.ITALIC);
tvComment.setVisibility(
- ((focusedView != tvComment) && Misc.isEmptyOrNull(comment)) ? View.INVISIBLE
- : View.VISIBLE);
+ ((focusedView != tvComment) && TextUtils.isEmpty(comment)) ? View.INVISIBLE
+ : View.VISIBLE);
};
showCommentsObserver = show -> {
textColor = (alpha << 24) | (0x00ffffff & textColor);
textView.setTypeface(null, Typeface.ITALIC);
textView.setHint("");
- if (Misc.isEmptyOrNull(textView.getText())) {
+ if (TextUtils.isEmpty(textView.getText())) {
textView.setVisibility(View.INVISIBLE);
}
}
final NewTransactionActivity activity =
(NewTransactionActivity) tvDescription.getContext();
- if (!item.isOfType(ItemType.bottomFiller)) {
+ if (!item.isBottomFiller()) {
item.observeEditableFlag(activity, editableObserver);
item.getModel()
.observeFocusedItem(activity, focusedAccountObserver);