import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
-import android.widget.SimpleCursorAdapter;
+import android.widget.ListAdapter;
import android.widget.TextView;
import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
import net.ktnx.mobileledger.R;
import net.ktnx.mobileledger.databinding.NewTransactionHeaderRowBinding;
+import net.ktnx.mobileledger.db.TransactionDescriptionAutocompleteAdapter;
import net.ktnx.mobileledger.model.Data;
+import net.ktnx.mobileledger.model.FutureDates;
import net.ktnx.mobileledger.ui.DatePickerFragment;
import net.ktnx.mobileledger.utils.Logger;
-import net.ktnx.mobileledger.utils.MLDB;
import net.ktnx.mobileledger.utils.Misc;
import net.ktnx.mobileledger.utils.SimpleDate;
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);
boolean wasSyncing = syncingData;
syncingData = true;
try {
- final int pos = getAdapterPosition();
+ final int pos = getBindingAdapterPosition();
if (id == R.id.transaction_comment) {
adapter.noteFocusIsOnTransactionComment(pos);
}
NewTransactionActivity activity = (NewTransactionActivity) b.getRoot()
.getContext();
- MLDB.hookAutocompletionAdapter(activity, b.newTransactionDescription,
- MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, activity, mProfile);
+ b.newTransactionDescription.setAdapter(
+ new TransactionDescriptionAutocompleteAdapter(activity));
+ b.newTransactionDescription.setOnItemClickListener(
+ (parent, view, position, id) -> activity.onDescriptionSelected(
+ parent.getItemAtPosition(position)
+ .toString()));
decimalSeparator = "";
Data.locale.observe(activity, locale -> decimalSeparator = String.valueOf(
ignoreFocusChanges = true;
try {
if (((focusInfo == null) || (focusInfo.element == null) ||
- focusInfo.position != getAdapterPosition()))
+ 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();
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");
+ Logger.debug("new-trans", "Ignoring request to syncData(): adapter position negative");
return false;
}
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()));
}
private void pickTransactionDate() {
DatePickerFragment picker = new DatePickerFragment();
- picker.setFutureDates(mProfile.getFutureDates());
+ picker.setFutureDates(FutureDates.valueOf(mProfile.getFutureDates()));
picker.setOnDatePickedListener(this);
picker.setCurrentDateFromText(b.newTransactionDate.getText());
picker.show(((NewTransactionActivity) b.getRoot()
b.newTransactionDate.setText(head.getFormattedDate());
// avoid triggering completion pop-up
- SimpleCursorAdapter a =
- (SimpleCursorAdapter) b.newTransactionDescription.getAdapter();
+ ListAdapter a = b.newTransactionDescription.getAdapter();
try {
b.newTransactionDescription.setAdapter(null);
b.newTransactionDescription.setText(head.getDescription());
}
finally {
- b.newTransactionDescription.setAdapter(a);
+ b.newTransactionDescription.setAdapter(
+ (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;
}
@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());