import android.widget.TextView;
import androidx.annotation.NonNull;
-import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.lifecycle.Observer;
import androidx.recyclerview.widget.RecyclerView;
import net.ktnx.mobileledger.model.Data;
import net.ktnx.mobileledger.model.LedgerTransactionAccount;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
+import net.ktnx.mobileledger.ui.AutoCompleteTextViewWithClear;
import net.ktnx.mobileledger.ui.DatePickerFragment;
import net.ktnx.mobileledger.utils.Logger;
import net.ktnx.mobileledger.utils.MLDB;
private AutoCompleteTextView tvDescription;
private AutoCompleteTextView tvAccount;
private TextView tvAmount;
- private ConstraintLayout lHead;
+ private LinearLayout lHead;
private LinearLayout lAccount;
private FrameLayout lPadding;
private MobileLedgerProfile mProfile;
tvAccount.setNextFocusForwardId(View.NO_ID);
tvAmount.setNextFocusForwardId(View.NO_ID); // magic!
- tvDate.setOnFocusChangeListener((v, hasFocus) -> {
- if (hasFocus)
- pickTransactionDate();
- });
tvDate.setOnClickListener(v -> pickTransactionDate());
mProfile = Data.profile.getValue();
if (mProfile == null)
throw new AssertionError();
+ View.OnFocusChangeListener focusMonitor = (v, hasFocus) -> {
+ if (hasFocus) {
+ boolean wasSyncing = syncingData;
+ syncingData = true;
+ try {
+ final int pos = getAdapterPosition();
+ adapter.updateFocusedItem(pos);
+ if (v instanceof AutoCompleteTextViewWithClear) {
+ adapter.noteFocusIsOnAccount(pos);
+ }
+ else {
+ adapter.noteFocusIsOnAmount(pos);
+ }
+ }
+ finally {
+ syncingData = wasSyncing;
+ }
+ }
+ };
+
+ tvDescription.setOnFocusChangeListener(focusMonitor);
+ tvAccount.setOnFocusChangeListener(focusMonitor);
+ tvAmount.setOnFocusChangeListener(focusMonitor);
+
MLDB.hookAutocompletionAdapter(tvDescription.getContext(), tvDescription,
MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, adapter, mProfile);
MLDB.hookAutocompletionAdapter(tvAccount.getContext(), tvAccount, MLDB.ACCOUNTS_TABLE,
syncingData = true;
try {
if (hint == null)
- hint = tvAmount.getResources()
- .getString(R.string.zero_amount);
- tvAmount.setHint(hint);
+ tvAmount.setHint(R.string.zero_amount);
+ else
+ tvAmount.setHint(hint);
}
finally {
syncingData = false;
(NewTransactionActivity) tvDescription.getContext());
break;
case transactionRow:
- focused = tvAccount.requestFocus();
- tvAccount.dismissDropDown();
- if (focused)
- Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
+ // do nothing if a row element already has the focus
+ if (!itemView.hasFocus()) {
+ if (item.focusIsOnAmount()) {
+ tvAmount.requestFocus();
+ }
+ else {
+ focused = tvAccount.requestFocus();
+ tvAccount.dismissDropDown();
+ if (focused)
+ Misc.showSoftKeyboard((NewTransactionActivity) tvAccount.getContext());
+ }
+ }
break;
}
catch (NumberFormatException e) {
Logger.debug("new-trans", String.format(
"assuming amount is not set due to number format exception. " +
- "input was '%s'",
- amount));
+ "input was '%s'", amount));
item.getAccount()
.resetAmount();
}
case transactionRow:
LedgerTransactionAccount acc = item.getAccount();
tvAccount.setText(acc.getAccountName());
- tvAmount.setText(
- acc.isAmountSet() ? String.format("%1.2f", acc.getAmount()) : "");
+ if (acc.isAmountSet()) {
+ tvAmount.setText(String.format("%1.2f", acc.getAmount()));
+ }
+ else {
+ tvAmount.setText("");
+// tvAmount.setHint(R.string.zero_amount);
+ }
+ tvAmount.setHint(item.getAmountHint());
lHead.setVisibility(View.GONE);
lAccount.setVisibility(View.VISIBLE);
lPadding.setVisibility(View.GONE);