X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionHeaderItemHolder.java;h=44464c8ffc505e511e686a2ca5b066bdf72cb5e8;hb=e01ac7879de5124d5d3548db5b7005298c4d5b0f;hp=37c55ce8aa1e4b19ec98f4b287d003683d8773c8;hpb=fcdd10b21d0e4af59f70804c63d145512b2cb918;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionHeaderItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionHeaderItemHolder.java index 37c55ce8..44464c8f 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionHeaderItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionHeaderItemHolder.java @@ -51,10 +51,9 @@ class NewTransactionHeaderItemHolder extends NewTransactionItemViewHolder private String decimalSeparator; private boolean inUpdate = false; private boolean syncingData = false; - //TODO multiple amounts with different currencies per posting? NewTransactionHeaderItemHolder(@NonNull NewTransactionHeaderRowBinding b, NewTransactionItemsAdapter adapter) { - super(b.getRoot(), adapter); + super(b.getRoot()); this.b = b; b.newTransactionDescription.setNextFocusForwardId(View.NO_ID); @@ -101,7 +100,7 @@ class NewTransactionHeaderItemHolder extends NewTransactionItemViewHolder b.newTransactionDescription.setAdapter( new TransactionDescriptionAutocompleteAdapter(activity)); b.newTransactionDescription.setOnItemClickListener( - (parent, view, position, id) -> activity.descriptionSelected( + (parent, view, position, id) -> activity.onDescriptionSelected( parent.getItemAtPosition(position) .toString())); @@ -157,7 +156,11 @@ class NewTransactionHeaderItemHolder extends NewTransactionItemViewHolder focusInfo.position != getBindingAdapterPosition())) return; - NewTransactionModel.Item head = getItem().toTransactionHead(); + final NewTransactionModel.Item item = getItem(); + if (item == null) + return; + + NewTransactionModel.Item head = item.toTransactionHead(); // bad idea - double pop-up, and not really necessary. // the user can tap the input to get the calendar //if (!tvDate.hasFocus()) tvDate.requestFocus(); @@ -252,7 +255,7 @@ class NewTransactionHeaderItemHolder extends NewTransactionItemViewHolder if (getBindingAdapterPosition() == RecyclerView.NO_POSITION) { // probably the row was swiped out - Logger.debug("new-trans", "Ignoring request to suncData(): adapter position negative"); + Logger.debug("new-trans", "Ignoring request to syncData(): adapter position negative"); return false; } @@ -261,7 +264,11 @@ class NewTransactionHeaderItemHolder extends NewTransactionItemViewHolder syncingData = true; try { - NewTransactionModel.TransactionHead head = getItem().toTransactionHead(); + final NewTransactionModel.Item item = getItem(); + if (item == null) + return false; + + NewTransactionModel.TransactionHead head = item.toTransactionHead(); head.setDate(String.valueOf(b.newTransactionDate.getText())); @@ -315,13 +322,17 @@ class NewTransactionHeaderItemHolder extends NewTransactionItemViewHolder (TransactionDescriptionAutocompleteAdapter) a); } - b.transactionComment.setText(head.getComment()); - //styleComment(b.transactionComment, head.getComment()); + final String comment = head.getComment(); + b.transactionComment.setText(comment); + styleComment(b.transactionComment, comment); // would hide or make it visible setEditable(true); - applyFocus(mAdapter.model.getFocusInfo() - .getValue()); + NewTransactionItemsAdapter adapter = + (NewTransactionItemsAdapter) getBindingAdapter(); + if (adapter != null) + applyFocus(adapter.model.getFocusInfo() + .getValue()); } finally { syncingData = false; @@ -340,7 +351,11 @@ class NewTransactionHeaderItemHolder extends NewTransactionItemViewHolder } @Override public void onDatePicked(int year, int month, int day) { - final NewTransactionModel.TransactionHead head = getItem().toTransactionHead(); + final NewTransactionModel.Item item = getItem(); + if (item == null) + return; + + final NewTransactionModel.TransactionHead head = item.toTransactionHead(); head.setDate(new SimpleDate(year, month + 1, day)); b.newTransactionDate.setText(head.getFormattedDate());