//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);
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();
return false;
}
- NewTransactionModel.Item item = getItem();
+ final NewTransactionModel.Item item = getItem();
+ if (item == null)
+ return false;
syncingData = true;
setEditable(true);
- applyFocus(mAdapter.model.getFocusInfo()
- .getValue());
+ NewTransactionItemsAdapter adapter =
+ (NewTransactionItemsAdapter) getBindingAdapter();
+ if (adapter != null)
+ applyFocus(adapter.model.getFocusInfo()
+ .getValue());
}
finally {
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);
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();
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()));
setEditable(true);
- applyFocus(mAdapter.model.getFocusInfo()
- .getValue());
+ NewTransactionItemsAdapter adapter =
+ (NewTransactionItemsAdapter) getBindingAdapter();
+ if (adapter != null)
+ applyFocus(adapter.model.getFocusInfo()
+ .getValue());
}
finally {
syncingData = false;
}
@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());
import android.view.View;
import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import net.ktnx.mobileledger.db.Profile;
import net.ktnx.mobileledger.model.Data;
abstract class NewTransactionItemViewHolder extends RecyclerView.ViewHolder {
- final NewTransactionItemsAdapter mAdapter;
final Profile mProfile;
- public NewTransactionItemViewHolder(@NonNull View itemView,
- NewTransactionItemsAdapter adapter) {
+ public NewTransactionItemViewHolder(@NonNull View itemView) {
super(itemView);
- mAdapter = adapter;
mProfile = Data.getProfile();
}
+ @Nullable
NewTransactionModel.Item getItem() {
- return mAdapter.getItem(getBindingAdapterPosition());
-// return Objects.requireNonNull(mAdapter.model.getItems()
-// .getValue())
-// .get(getBindingAdapterPosition());
+ NewTransactionItemsAdapter adapter = (NewTransactionItemsAdapter) getBindingAdapter();
+ if (adapter == null)
+ return null;
+ return adapter.getItem(getBindingAdapterPosition());
}
abstract public void bind(NewTransactionModel.Item item);
}