X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionAccountRowItemHolder.java;h=7039f53a9b2ea479835c729b6ceb18678d506d44;hb=1beb71114771c79b7845b821009ee9b2ed063b74;hp=870cf7eec141bbb505088802df1cf8f6f078f866;hpb=02ceb0d2ef0eed07c278330e4b9b2af366f5d17f;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionAccountRowItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionAccountRowItemHolder.java index 870cf7ee..7039f53a 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionAccountRowItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionAccountRowItemHolder.java @@ -31,6 +31,7 @@ import android.widget.TextView; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.recyclerview.widget.RecyclerView; import net.ktnx.mobileledger.R; import net.ktnx.mobileledger.databinding.NewTransactionAccountRowBinding; @@ -52,10 +53,9 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder { private String decimalSeparator; private boolean inUpdate = false; private boolean syncingData = false; - //TODO multiple amounts with different currencies per posting? NewTransactionAccountRowItemHolder(@NonNull NewTransactionAccountRowBinding b, NewTransactionItemsAdapter adapter) { - super(b.getRoot(), adapter); + super(b.getRoot()); this.b = b; new TextViewClearHelper().attachToTextView(b.comment); @@ -73,7 +73,7 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder { boolean wasSyncing = syncingData; syncingData = true; try { - final int pos = getAdapterPosition(); + final int pos = getBindingAdapterPosition(); if (id == R.id.account_row_acc_name) { adapter.noteFocusIsOnAccount(pos); } @@ -177,8 +177,8 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder { b.currencyButton.setOnClickListener(v -> { CurrencySelectorFragment cpf = new CurrencySelectorFragment(); cpf.showPositionAndPadding(); - cpf.setOnCurrencySelectedListener(c -> adapter.setItemCurrency(getAdapterPosition(), - (c == null) ? null : c.getName())); + cpf.setOnCurrencySelectedListener( + c -> adapter.setItemCurrency(getBindingAdapterPosition(), c)); cpf.show(activity.getSupportFragmentManager(), "currency-selector"); }); @@ -221,10 +221,14 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder { ignoreFocusChanges = true; try { if (((focusInfo == null) || (focusInfo.element == null) || - focusInfo.position != getAdapterPosition())) + focusInfo.position != getBindingAdapterPosition())) return; - NewTransactionModel.TransactionAccount acc = getItem().toTransactionAccount(); + final NewTransactionModel.Item item = getItem(); + if (item == null) + return; + + NewTransactionModel.TransactionAccount acc = item.toTransactionAccount(); switch (focusInfo.element) { case Amount: b.accountRowAccAmounts.requestFocus(); @@ -397,13 +401,15 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder { return false; } - if (getAdapterPosition() < 0) { + if (getBindingAdapterPosition() == RecyclerView.NO_POSITION) { // probably the row was swiped out Logger.debug("new-trans", "Ignoring request to suncData(): adapter position negative"); return false; } - NewTransactionModel.Item item = getItem(); + final NewTransactionModel.Item item = getItem(); + if (item == null) + return false; syncingData = true; @@ -519,12 +525,17 @@ class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder { acc.isAmountSet() ? String.format("%4.2f", acc.getAmount()) : null); displayAmountValidity(true); - b.comment.setText(acc.getComment()); + final String comment = acc.getComment(); + b.comment.setText(comment); + styleComment(b.comment, comment); setEditable(true); - applyFocus(mAdapter.model.getFocusInfo() - .getValue()); + NewTransactionItemsAdapter adapter = + (NewTransactionItemsAdapter) getBindingAdapter(); + if (adapter != null) + applyFocus(adapter.model.getFocusInfo() + .getValue()); } finally { syncingData = false;