--- /dev/null
+/*
+ * Copyright © 2021 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.ui.new_transaction;
+
+import android.annotation.SuppressLint;
+import android.graphics.Typeface;
+import android.text.Editable;
+import android.text.TextUtils;
+import android.text.TextWatcher;
+import android.view.Gravity;
+import android.view.View;
+import android.view.inputmethod.EditorInfo;
+import android.widget.EditText;
+import android.widget.TextView;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.NonNull;
+import androidx.constraintlayout.widget.ConstraintLayout;
+
+import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.databinding.NewTransactionAccountRowBinding;
+import net.ktnx.mobileledger.db.AccountAutocompleteAdapter;
+import net.ktnx.mobileledger.model.Currency;
+import net.ktnx.mobileledger.model.Data;
+import net.ktnx.mobileledger.ui.CurrencySelectorFragment;
+import net.ktnx.mobileledger.ui.TextViewClearHelper;
+import net.ktnx.mobileledger.utils.DimensionUtils;
+import net.ktnx.mobileledger.utils.Logger;
+import net.ktnx.mobileledger.utils.Misc;
+
+import java.text.DecimalFormatSymbols;
+
+class NewTransactionAccountRowItemHolder extends NewTransactionItemViewHolder {
+ private final String decimalDot = ".";
+ private final NewTransactionAccountRowBinding b;
+ private boolean ignoreFocusChanges = false;
+ 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);
+ this.b = b;
+ new TextViewClearHelper().attachToTextView(b.comment);
+
+ b.accountRowAccName.setNextFocusForwardId(View.NO_ID);
+ b.accountRowAccAmounts.setNextFocusForwardId(View.NO_ID); // magic!
+
+ b.accountCommentButton.setOnClickListener(v -> {
+ b.comment.setVisibility(View.VISIBLE);
+ b.comment.requestFocus();
+ });
+
+ @SuppressLint("DefaultLocale") View.OnFocusChangeListener focusMonitor = (v, hasFocus) -> {
+ final int id = v.getId();
+ if (hasFocus) {
+ boolean wasSyncing = syncingData;
+ syncingData = true;
+ try {
+ final int pos = getAdapterPosition();
+ if (id == R.id.account_row_acc_name) {
+ adapter.noteFocusIsOnAccount(pos);
+ }
+ else if (id == R.id.account_row_acc_amounts) {
+ adapter.noteFocusIsOnAmount(pos);
+ }
+ else if (id == R.id.comment) {
+ adapter.noteFocusIsOnComment(pos);
+ }
+ else
+ throw new IllegalStateException("Where is the focus? " + id);
+ }
+ finally {
+ syncingData = wasSyncing;
+ }
+ }
+ else { // lost focus
+ if (id == R.id.account_row_acc_amounts) {
+ try {
+ String input = String.valueOf(b.accountRowAccAmounts.getText());
+ input = input.replace(decimalSeparator, decimalDot);
+ final String newText = String.format("%4.2f", Float.parseFloat(input));
+ if (!newText.equals(input)) {
+ boolean wasSyncingData = syncingData;
+ syncingData = true;
+ try {
+ b.accountRowAccAmounts.setText(newText);
+ }
+ finally {
+ syncingData = wasSyncingData;
+ }
+ }
+ }
+ catch (NumberFormatException ex) {
+ // ignored
+ }
+ }
+ }
+
+ if (id == R.id.comment) {
+ commentFocusChanged(b.comment, hasFocus);
+ }
+ };
+
+ b.accountRowAccName.setOnFocusChangeListener(focusMonitor);
+ b.accountRowAccAmounts.setOnFocusChangeListener(focusMonitor);
+ b.comment.setOnFocusChangeListener(focusMonitor);
+
+ NewTransactionActivity activity = (NewTransactionActivity) b.getRoot()
+ .getContext();
+
+ b.accountRowAccName.setAdapter(new AccountAutocompleteAdapter(b.getRoot()
+ .getContext(), mProfile));
+
+ decimalSeparator = "";
+ Data.locale.observe(activity, locale -> decimalSeparator = String.valueOf(
+ DecimalFormatSymbols.getInstance(locale)
+ .getMonetaryDecimalSeparator()));
+
+ final TextWatcher tw = new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+// debug("input", "text changed");
+ if (inUpdate)
+ return;
+
+ Logger.debug("textWatcher", "calling syncData()");
+ if (syncData()) {
+ Logger.debug("textWatcher",
+ "syncData() returned, checking if transaction is submittable");
+ adapter.model.checkTransactionSubmittable(null);
+ }
+ Logger.debug("textWatcher", "done");
+ }
+ };
+ final TextWatcher amountWatcher = new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {}
+ @Override
+ public void afterTextChanged(Editable s) {
+ checkAmountValid(s.toString());
+
+ if (syncData())
+ adapter.model.checkTransactionSubmittable(null);
+ }
+ };
+ b.accountRowAccName.addTextChangedListener(tw);
+ monitorComment(b.comment);
+ b.accountRowAccAmounts.addTextChangedListener(amountWatcher);
+
+ b.currencyButton.setOnClickListener(v -> {
+ CurrencySelectorFragment cpf = new CurrencySelectorFragment();
+ cpf.showPositionAndPadding();
+ cpf.setOnCurrencySelectedListener(c -> adapter.setItemCurrency(getAdapterPosition(),
+ (c == null) ? null : c.getName()));
+ cpf.show(activity.getSupportFragmentManager(), "currency-selector");
+ });
+
+ commentFocusChanged(b.comment, false);
+
+ adapter.model.getFocusInfo()
+ .observe(activity, this::applyFocus);
+
+ Data.currencyGap.observe(activity,
+ hasGap -> updateCurrencyPositionAndPadding(Data.currencySymbolPosition.getValue(),
+ hasGap));
+
+ Data.currencySymbolPosition.observe(activity,
+ position -> updateCurrencyPositionAndPadding(position,
+ Data.currencyGap.getValue()));
+
+ adapter.model.getShowCurrency()
+ .observe(activity, showCurrency -> {
+ if (showCurrency) {
+ b.currency.setVisibility(View.VISIBLE);
+ b.currencyButton.setVisibility(View.VISIBLE);
+ setCurrencyString(mProfile.getDefaultCommodity());
+ }
+ else {
+ b.currency.setVisibility(View.GONE);
+ b.currencyButton.setVisibility(View.GONE);
+ setCurrencyString(null);
+ }
+ });
+
+ adapter.model.getShowComments()
+ .observe(activity, show -> b.commentLayout.setVisibility(
+ show ? View.VISIBLE : View.GONE));
+ }
+ private void applyFocus(NewTransactionModel.FocusInfo focusInfo) {
+ if (ignoreFocusChanges) {
+ Logger.debug("new-trans", "Ignoring focus change");
+ return;
+ }
+ ignoreFocusChanges = true;
+ try {
+ if (((focusInfo == null) || (focusInfo.element == null) ||
+ focusInfo.position != getAdapterPosition()))
+ return;
+
+ NewTransactionModel.TransactionAccount acc = getItem().toTransactionAccount();
+ switch (focusInfo.element) {
+ case Amount:
+ b.accountRowAccAmounts.requestFocus();
+ break;
+ case Comment:
+ b.comment.setVisibility(View.VISIBLE);
+ b.comment.requestFocus();
+ break;
+ case Account:
+ boolean focused = b.accountRowAccName.requestFocus();
+// b.accountRowAccName.dismissDropDown();
+ if (focused)
+ Misc.showSoftKeyboard((NewTransactionActivity) b.getRoot()
+ .getContext());
+ break;
+ }
+ }
+ finally {
+ ignoreFocusChanges = false;
+ }
+ }
+ public void checkAmountValid(String s) {
+ boolean valid = true;
+ try {
+ if (s.length() > 0) {
+ float ignored = Float.parseFloat(s.replace(decimalSeparator, decimalDot));
+ }
+ }
+ catch (NumberFormatException ex) {
+ valid = false;
+ }
+
+ displayAmountValidity(valid);
+ }
+ private void displayAmountValidity(boolean valid) {
+ b.accountRowAccAmounts.setCompoundDrawablesRelativeWithIntrinsicBounds(
+ valid ? 0 : R.drawable.ic_error_outline_black_24dp, 0, 0, 0);
+ b.accountRowAccAmounts.setMinEms(valid ? 4 : 5);
+ }
+ private void monitorComment(EditText editText) {
+ editText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ }
+ @Override
+ public void afterTextChanged(Editable s) {
+// debug("input", "text changed");
+ if (inUpdate)
+ return;
+
+ Logger.debug("textWatcher", "calling syncData()");
+ syncData();
+ Logger.debug("textWatcher",
+ "syncData() returned, checking if transaction is submittable");
+ styleComment(editText, s.toString());
+ Logger.debug("textWatcher", "done");
+ }
+ });
+ }
+ private void commentFocusChanged(TextView textView, boolean hasFocus) {
+ @ColorInt int textColor;
+ textColor = b.dummyText.getTextColors()
+ .getDefaultColor();
+ if (hasFocus) {
+ textView.setTypeface(null, Typeface.NORMAL);
+ textView.setHint(R.string.transaction_account_comment_hint);
+ }
+ else {
+ int alpha = (textColor >> 24 & 0xff);
+ alpha = 3 * alpha / 4;
+ textColor = (alpha << 24) | (0x00ffffff & textColor);
+ textView.setTypeface(null, Typeface.ITALIC);
+ textView.setHint("");
+ if (TextUtils.isEmpty(textView.getText())) {
+ textView.setVisibility(View.INVISIBLE);
+ }
+ }
+ textView.setTextColor(textColor);
+
+ }
+ private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
+ ConstraintLayout.LayoutParams amountLP =
+ (ConstraintLayout.LayoutParams) b.accountRowAccAmounts.getLayoutParams();
+ ConstraintLayout.LayoutParams currencyLP =
+ (ConstraintLayout.LayoutParams) b.currency.getLayoutParams();
+
+ if (position == Currency.Position.before) {
+ currencyLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
+ currencyLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
+
+ amountLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
+ amountLP.endToStart = ConstraintLayout.LayoutParams.UNSET;
+ amountLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
+ amountLP.startToEnd = b.currency.getId();
+
+ b.currency.setGravity(Gravity.END);
+ }
+ else {
+ currencyLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
+ currencyLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
+
+ amountLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
+ amountLP.startToEnd = ConstraintLayout.LayoutParams.UNSET;
+ amountLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
+ amountLP.endToStart = b.currency.getId();
+
+ b.currency.setGravity(Gravity.START);
+ }
+
+ amountLP.resolveLayoutDirection(b.accountRowAccAmounts.getLayoutDirection());
+ currencyLP.resolveLayoutDirection(b.currency.getLayoutDirection());
+
+ b.accountRowAccAmounts.setLayoutParams(amountLP);
+ b.currency.setLayoutParams(currencyLP);
+
+ // distance between the amount and the currency symbol
+ int gapSize = DimensionUtils.sp2px(b.currency.getContext(), 5);
+
+ if (position == Currency.Position.before) {
+ b.currency.setPaddingRelative(0, 0, hasGap ? gapSize : 0, 0);
+ }
+ else {
+ b.currency.setPaddingRelative(hasGap ? gapSize : 0, 0, 0, 0);
+ }
+ }
+ private void setCurrencyString(String currency) {
+ @ColorInt int textColor = b.dummyText.getTextColors()
+ .getDefaultColor();
+ if (TextUtils.isEmpty(currency)) {
+ b.currency.setText(R.string.currency_symbol);
+ int alpha = (textColor >> 24) & 0xff;
+ alpha = alpha * 3 / 4;
+ b.currency.setTextColor((alpha << 24) | (0x00ffffff & textColor));
+ }
+ else {
+ b.currency.setText(currency);
+ b.currency.setTextColor(textColor);
+ }
+ }
+ private void setCurrency(Currency currency) {
+ setCurrencyString((currency == null) ? null : currency.getName());
+ }
+ private void setEditable(Boolean editable) {
+ b.accountRowAccName.setEnabled(editable);
+ b.accountRowAccAmounts.setEnabled(editable);
+ }
+ private void beginUpdates() {
+ if (inUpdate)
+ throw new RuntimeException("Already in update mode");
+ inUpdate = true;
+ }
+ private void endUpdates() {
+ if (!inUpdate)
+ throw new RuntimeException("Not in update mode");
+ inUpdate = false;
+ }
+ /**
+ * syncData()
+ * <p>
+ * Stores the data from the UI elements into the model item
+ * Returns true if there were changes made that suggest transaction has to be
+ * checked for being submittable
+ */
+ private boolean syncData() {
+ if (syncingData) {
+ Logger.debug("new-trans", "skipping syncData() loop");
+ return false;
+ }
+
+ if (getAdapterPosition() < 0) {
+ // probably the row was swiped out
+ Logger.debug("new-trans", "Ignoring request to suncData(): adapter position negative");
+ return false;
+ }
+
+ NewTransactionModel.Item item = getItem();
+
+ syncingData = true;
+
+ boolean significantChange = false;
+
+ try {
+ NewTransactionModel.TransactionAccount acc = item.toTransactionAccount();
+
+ // having account name is important
+ final Editable incomingAccountName = b.accountRowAccName.getText();
+ if (TextUtils.isEmpty(acc.getAccountName()) != TextUtils.isEmpty(incomingAccountName))
+ significantChange = true;
+
+ acc.setAccountName(String.valueOf(incomingAccountName));
+ final int accNameSelEnd = b.accountRowAccName.getSelectionEnd();
+ final int accNameSelStart = b.accountRowAccName.getSelectionStart();
+ acc.setAccountNameCursorPosition(accNameSelEnd);
+
+ acc.setComment(String.valueOf(b.comment.getText()));
+
+ String amount = String.valueOf(b.accountRowAccAmounts.getText());
+ amount = amount.trim();
+
+ if (amount.isEmpty()) {
+ if (acc.isAmountSet())
+ significantChange = true;
+ acc.resetAmount();
+ acc.setAmountValid(true);
+ }
+ else {
+ try {
+ amount = amount.replace(decimalSeparator, decimalDot);
+ final float parsedAmount = Float.parseFloat(amount);
+ if (!acc.isAmountSet() || !Misc.equalFloats(parsedAmount, acc.getAmount()))
+ significantChange = true;
+ acc.setAmount(parsedAmount);
+ acc.setAmountValid(true);
+ }
+ catch (NumberFormatException e) {
+ Logger.debug("new-trans", String.format(
+ "assuming amount is not set due to number format exception. " +
+ "input was '%s'", amount));
+ if (acc.isAmountValid())
+ significantChange = true;
+ acc.setAmountValid(false);
+ }
+ final String curr = String.valueOf(b.currency.getText());
+ final String currValue;
+ if (curr.equals(b.currency.getContext()
+ .getResources()
+ .getString(R.string.currency_symbol)) || curr.isEmpty())
+ currValue = null;
+ else
+ currValue = curr;
+
+ if (!significantChange && !Misc.equalStrings(acc.getCurrency(), currValue))
+ significantChange = true;
+ acc.setCurrency(currValue);
+ }
+
+ return significantChange;
+ }
+ finally {
+ syncingData = false;
+ }
+ }
+ /**
+ * bind
+ *
+ * @param item updates the UI elements with the data from the model item
+ */
+ @SuppressLint("DefaultLocale")
+ public void bind(@NonNull NewTransactionModel.Item item) {
+ beginUpdates();
+ try {
+ syncingData = true;
+ try {
+ NewTransactionModel.TransactionAccount acc = item.toTransactionAccount();
+
+ final String incomingAccountName = acc.getAccountName();
+ final String presentAccountName = String.valueOf(b.accountRowAccName.getText());
+ if (!Misc.equalStrings(incomingAccountName, presentAccountName)) {
+ Logger.debug("bind",
+ String.format("Setting account name from '%s' to '%s' (| @ %d)",
+ presentAccountName, incomingAccountName,
+ acc.getAccountNameCursorPosition()));
+ // avoid triggering completion pop-up
+ AccountAutocompleteAdapter a =
+ (AccountAutocompleteAdapter) b.accountRowAccName.getAdapter();
+ try {
+ b.accountRowAccName.setAdapter(null);
+ b.accountRowAccName.setText(incomingAccountName);
+ b.accountRowAccName.setSelection(acc.getAccountNameCursorPosition());
+ }
+ finally {
+ b.accountRowAccName.setAdapter(a);
+ }
+ }
+
+ final String amountHint = acc.getAmountHint();
+ if (amountHint == null) {
+ b.accountRowAccAmounts.setHint(R.string.zero_amount);
+ }
+ else {
+ b.accountRowAccAmounts.setHint(amountHint);
+ }
+
+ b.accountRowAccAmounts.setImeOptions(
+ acc.isLast() ? EditorInfo.IME_ACTION_DONE : EditorInfo.IME_ACTION_NEXT);
+
+ setCurrencyString(acc.getCurrency());
+ b.accountRowAccAmounts.setText(
+ acc.isAmountSet() ? String.format("%4.2f", acc.getAmount()) : null);
+ displayAmountValidity(true);
+
+ b.comment.setText(acc.getComment());
+
+ setEditable(true);
+
+ applyFocus(mAdapter.model.getFocusInfo()
+ .getValue());
+ }
+ finally {
+ syncingData = false;
+ }
+ }
+ finally {
+ endUpdates();
+ }
+ }
+ private void styleComment(EditText editText, String comment) {
+ final View focusedView = editText.findFocus();
+ editText.setTypeface(null, (focusedView == editText) ? Typeface.NORMAL : Typeface.ITALIC);
+ editText.setVisibility(
+ ((focusedView != editText) && TextUtils.isEmpty(comment)) ? View.INVISIBLE
+ : View.VISIBLE);
+ }
+}
--- /dev/null
+/*
+ * Copyright © 2021 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.ui.new_transaction;
+
+import android.annotation.SuppressLint;
+import android.graphics.Typeface;
+import android.text.Editable;
+import android.text.TextUtils;
+import android.text.TextWatcher;
+import android.view.View;
+import android.widget.EditText;
+import android.widget.SimpleCursorAdapter;
+import android.widget.TextView;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.NonNull;
+
+import net.ktnx.mobileledger.R;
+import net.ktnx.mobileledger.databinding.NewTransactionHeaderRowBinding;
+import net.ktnx.mobileledger.model.Data;
+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;
+
+import java.text.DecimalFormatSymbols;
+import java.text.ParseException;
+
+class NewTransactionHeaderItemHolder extends NewTransactionItemViewHolder
+ implements DatePickerFragment.DatePickedListener {
+ private final NewTransactionHeaderRowBinding b;
+ private boolean ignoreFocusChanges = false;
+ 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);
+ this.b = b;
+
+ b.newTransactionDescription.setNextFocusForwardId(View.NO_ID);
+
+ b.newTransactionDate.setOnClickListener(v -> pickTransactionDate());
+
+ b.transactionCommentButton.setOnClickListener(v -> {
+ b.transactionComment.setVisibility(View.VISIBLE);
+ b.transactionComment.requestFocus();
+ });
+
+ @SuppressLint("DefaultLocale") View.OnFocusChangeListener focusMonitor = (v, hasFocus) -> {
+ final int id = v.getId();
+ if (hasFocus) {
+ boolean wasSyncing = syncingData;
+ syncingData = true;
+ try {
+ final int pos = getAdapterPosition();
+ if (id == R.id.transaction_comment) {
+ adapter.noteFocusIsOnTransactionComment(pos);
+ }
+ else if (id == R.id.new_transaction_description) {
+ adapter.noteFocusIsOnDescription(pos);
+ }
+ else
+ throw new IllegalStateException("Where is the focus? " + id);
+ }
+ finally {
+ syncingData = wasSyncing;
+ }
+ }
+
+ if (id == R.id.transaction_comment) {
+ commentFocusChanged(b.transactionComment, hasFocus);
+ }
+ };
+
+ b.newTransactionDescription.setOnFocusChangeListener(focusMonitor);
+ b.transactionComment.setOnFocusChangeListener(focusMonitor);
+
+ NewTransactionActivity activity = (NewTransactionActivity) b.getRoot()
+ .getContext();
+
+ MLDB.hookAutocompletionAdapter(activity, b.newTransactionDescription,
+ MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, activity, mProfile);
+
+ decimalSeparator = "";
+ Data.locale.observe(activity, locale -> decimalSeparator = String.valueOf(
+ DecimalFormatSymbols.getInstance(locale)
+ .getMonetaryDecimalSeparator()));
+
+ final TextWatcher tw = new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ }
+
+ @Override
+ public void afterTextChanged(Editable s) {
+// debug("input", "text changed");
+ if (inUpdate)
+ return;
+
+ Logger.debug("textWatcher", "calling syncData()");
+ if (syncData()) {
+ Logger.debug("textWatcher",
+ "syncData() returned, checking if transaction is submittable");
+ adapter.model.checkTransactionSubmittable(null);
+ }
+ Logger.debug("textWatcher", "done");
+ }
+ };
+ b.newTransactionDescription.addTextChangedListener(tw);
+ monitorComment(b.transactionComment);
+
+ commentFocusChanged(b.transactionComment, false);
+
+ adapter.model.getFocusInfo()
+ .observe(activity, this::applyFocus);
+
+ adapter.model.getShowComments()
+ .observe(activity, show -> b.transactionCommentLayout.setVisibility(
+ show ? View.VISIBLE : View.GONE));
+ }
+ private void applyFocus(NewTransactionModel.FocusInfo focusInfo) {
+ if (ignoreFocusChanges) {
+ Logger.debug("new-trans", "Ignoring focus change");
+ return;
+ }
+ ignoreFocusChanges = true;
+ try {
+ if (((focusInfo == null) || (focusInfo.element == null) ||
+ focusInfo.position != getAdapterPosition()))
+ return;
+
+ NewTransactionModel.Item head = getItem().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();
+ switch (focusInfo.element) {
+ case TransactionComment:
+ b.transactionComment.setVisibility(View.VISIBLE);
+ b.transactionComment.requestFocus();
+ break;
+ case Description:
+ boolean focused = b.newTransactionDescription.requestFocus();
+// tvDescription.dismissDropDown();
+ if (focused)
+ Misc.showSoftKeyboard((NewTransactionActivity) b.getRoot()
+ .getContext());
+ break;
+ }
+ }
+ finally {
+ ignoreFocusChanges = false;
+ }
+ }
+ private void monitorComment(EditText editText) {
+ editText.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int count, int after) {
+ }
+ @Override
+ public void onTextChanged(CharSequence s, int start, int before, int count) {
+ }
+ @Override
+ public void afterTextChanged(Editable s) {
+// debug("input", "text changed");
+ if (inUpdate)
+ return;
+
+ Logger.debug("textWatcher", "calling syncData()");
+ syncData();
+ Logger.debug("textWatcher",
+ "syncData() returned, checking if transaction is submittable");
+ styleComment(editText, s.toString());
+ Logger.debug("textWatcher", "done");
+ }
+ });
+ }
+ private void commentFocusChanged(TextView textView, boolean hasFocus) {
+ @ColorInt int textColor;
+ textColor = b.dummyText.getTextColors()
+ .getDefaultColor();
+ if (hasFocus) {
+ textView.setTypeface(null, Typeface.NORMAL);
+ textView.setHint(R.string.transaction_account_comment_hint);
+ }
+ else {
+ int alpha = (textColor >> 24 & 0xff);
+ alpha = 3 * alpha / 4;
+ textColor = (alpha << 24) | (0x00ffffff & textColor);
+ textView.setTypeface(null, Typeface.ITALIC);
+ textView.setHint("");
+ if (TextUtils.isEmpty(textView.getText())) {
+ textView.setVisibility(View.INVISIBLE);
+ }
+ }
+ textView.setTextColor(textColor);
+
+ }
+ private void setEditable(Boolean editable) {
+ b.newTransactionDate.setEnabled(editable);
+ b.newTransactionDescription.setEnabled(editable);
+ }
+ private void beginUpdates() {
+ if (inUpdate)
+ throw new RuntimeException("Already in update mode");
+ inUpdate = true;
+ }
+ private void endUpdates() {
+ if (!inUpdate)
+ throw new RuntimeException("Not in update mode");
+ inUpdate = false;
+ }
+ /**
+ * syncData()
+ * <p>
+ * Stores the data from the UI elements into the model item
+ * Returns true if there were changes made that suggest transaction has to be
+ * checked for being submittable
+ */
+ private boolean syncData() {
+ if (syncingData) {
+ Logger.debug("new-trans", "skipping syncData() loop");
+ return false;
+ }
+
+ if (getAdapterPosition() < 0) {
+ // probably the row was swiped out
+ Logger.debug("new-trans", "Ignoring request to suncData(): adapter position negative");
+ return false;
+ }
+
+
+ boolean significantChange = false;
+
+ syncingData = true;
+ try {
+ NewTransactionModel.TransactionHead head = getItem().toTransactionHead();
+
+ head.setDate(String.valueOf(b.newTransactionDate.getText()));
+
+ // transaction description is required
+ if (TextUtils.isEmpty(head.getDescription()) !=
+ TextUtils.isEmpty(b.newTransactionDescription.getText()))
+ significantChange = true;
+
+ head.setDescription(String.valueOf(b.newTransactionDescription.getText()));
+ head.setComment(String.valueOf(b.transactionComment.getText()));
+
+ return significantChange;
+ }
+ catch (ParseException e) {
+ throw new RuntimeException("Should not happen", e);
+ }
+ finally {
+ syncingData = false;
+ }
+ }
+ private void pickTransactionDate() {
+ DatePickerFragment picker = new DatePickerFragment();
+ picker.setFutureDates(mProfile.getFutureDates());
+ picker.setOnDatePickedListener(this);
+ picker.setCurrentDateFromText(b.newTransactionDate.getText());
+ picker.show(((NewTransactionActivity) b.getRoot()
+ .getContext()).getSupportFragmentManager(), null);
+ }
+ /**
+ * bind
+ *
+ * @param item updates the UI elements with the data from the model item
+ */
+ @SuppressLint("DefaultLocale")
+ public void bind(@NonNull NewTransactionModel.Item item) {
+ beginUpdates();
+ try {
+ syncingData = true;
+ try {
+ NewTransactionModel.TransactionHead head = item.toTransactionHead();
+ b.newTransactionDate.setText(head.getFormattedDate());
+
+ // avoid triggering completion pop-up
+ SimpleCursorAdapter a =
+ (SimpleCursorAdapter) b.newTransactionDescription.getAdapter();
+ try {
+ b.newTransactionDescription.setAdapter(null);
+ b.newTransactionDescription.setText(head.getDescription());
+ }
+ finally {
+ b.newTransactionDescription.setAdapter(a);
+ }
+
+ b.transactionComment.setText(head.getComment());
+ //styleComment(b.transactionComment, head.getComment());
+
+ setEditable(true);
+
+ applyFocus(mAdapter.model.getFocusInfo()
+ .getValue());
+ }
+ finally {
+ syncingData = false;
+ }
+ }
+ finally {
+ endUpdates();
+ }
+ }
+ private void styleComment(EditText editText, String comment) {
+ final View focusedView = editText.findFocus();
+ editText.setTypeface(null, (focusedView == editText) ? Typeface.NORMAL : Typeface.ITALIC);
+ editText.setVisibility(
+ ((focusedView != editText) && TextUtils.isEmpty(comment)) ? View.INVISIBLE
+ : View.VISIBLE);
+ }
+ @Override
+ public void onDatePicked(int year, int month, int day) {
+ final NewTransactionModel.TransactionHead head = getItem().toTransactionHead();
+ head.setDate(new SimpleDate(year, month + 1, day));
+ b.newTransactionDate.setText(head.getFormattedDate());
+
+ boolean focused = b.newTransactionDescription.requestFocus();
+ if (focused)
+ Misc.showSoftKeyboard((NewTransactionActivity) b.getRoot()
+ .getContext());
+
+ }
+}
+++ /dev/null
-/*
- * Copyright © 2021 Damyan Ivanov.
- * This file is part of MoLe.
- * MoLe is free software: you can distribute it and/or modify it
- * under the term of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your opinion), any later version.
- *
- * MoLe is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License terms for details.
- *
- * You should have received a copy of the GNU General Public License
- * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- */
-
-package net.ktnx.mobileledger.ui.new_transaction;
-
-import android.annotation.SuppressLint;
-import android.graphics.Typeface;
-import android.text.Editable;
-import android.text.TextUtils;
-import android.text.TextWatcher;
-import android.view.Gravity;
-import android.view.View;
-import android.view.inputmethod.EditorInfo;
-import android.widget.EditText;
-import android.widget.SimpleCursorAdapter;
-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.async.DescriptionSelectedCallback;
-import net.ktnx.mobileledger.databinding.NewTransactionRowBinding;
-import net.ktnx.mobileledger.db.AccountAutocompleteAdapter;
-import net.ktnx.mobileledger.model.Currency;
-import net.ktnx.mobileledger.model.Data;
-import net.ktnx.mobileledger.model.MobileLedgerProfile;
-import net.ktnx.mobileledger.ui.CurrencySelectorFragment;
-import net.ktnx.mobileledger.ui.DatePickerFragment;
-import net.ktnx.mobileledger.ui.TextViewClearHelper;
-import net.ktnx.mobileledger.utils.DimensionUtils;
-import net.ktnx.mobileledger.utils.Logger;
-import net.ktnx.mobileledger.utils.MLDB;
-import net.ktnx.mobileledger.utils.Misc;
-import net.ktnx.mobileledger.utils.SimpleDate;
-
-import java.text.DecimalFormatSymbols;
-import java.text.ParseException;
-import java.util.Objects;
-
-class NewTransactionItemHolder extends RecyclerView.ViewHolder
- implements DatePickerFragment.DatePickedListener, DescriptionSelectedCallback {
- private final String decimalDot = ".";
- private final MobileLedgerProfile mProfile;
- private final NewTransactionRowBinding b;
- private final NewTransactionItemsAdapter mAdapter;
- private boolean ignoreFocusChanges = false;
- private String decimalSeparator;
- private boolean inUpdate = false;
- private boolean syncingData = false;
- //TODO multiple amounts with different currencies per posting?
- NewTransactionItemHolder(@NonNull NewTransactionRowBinding b,
- NewTransactionItemsAdapter adapter) {
- super(b.getRoot());
- this.b = b;
- this.mAdapter = adapter;
- new TextViewClearHelper().attachToTextView(b.comment);
-
- b.newTransactionDescription.setNextFocusForwardId(View.NO_ID);
- b.accountRowAccName.setNextFocusForwardId(View.NO_ID);
- b.accountRowAccAmounts.setNextFocusForwardId(View.NO_ID); // magic!
-
- b.newTransactionDate.setOnClickListener(v -> pickTransactionDate());
-
- b.accountCommentButton.setOnClickListener(v -> {
- b.comment.setVisibility(View.VISIBLE);
- b.comment.requestFocus();
- });
-
- b.transactionCommentButton.setOnClickListener(v -> {
- b.transactionComment.setVisibility(View.VISIBLE);
- b.transactionComment.requestFocus();
- });
-
- mProfile = Data.getProfile();
-
- @SuppressLint("DefaultLocale") View.OnFocusChangeListener focusMonitor = (v, hasFocus) -> {
- final int id = v.getId();
- if (hasFocus) {
- boolean wasSyncing = syncingData;
- syncingData = true;
- try {
- final int pos = getAdapterPosition();
- if (id == R.id.account_row_acc_name) {
- adapter.noteFocusIsOnAccount(pos);
- }
- else if (id == R.id.account_row_acc_amounts) {
- adapter.noteFocusIsOnAmount(pos);
- }
- else if (id == R.id.comment) {
- adapter.noteFocusIsOnComment(pos);
- }
- else if (id == R.id.transaction_comment) {
- adapter.noteFocusIsOnTransactionComment(pos);
- }
- else if (id == R.id.new_transaction_description) {
- adapter.noteFocusIsOnDescription(pos);
- }
- else
- throw new IllegalStateException("Where is the focus?");
- }
- finally {
- syncingData = wasSyncing;
- }
- }
- else { // lost focus
- if (id == R.id.account_row_acc_amounts) {
- try {
- String input = String.valueOf(b.accountRowAccAmounts.getText());
- input = input.replace(decimalSeparator, decimalDot);
- final String newText = String.format("%4.2f", Float.parseFloat(input));
- if (!newText.equals(input)) {
- boolean wasSyncingData = syncingData;
- syncingData = true;
- try {
- b.accountRowAccAmounts.setText(newText);
- }
- finally {
- syncingData = wasSyncingData;
- }
- }
- }
- catch (NumberFormatException ex) {
- // ignored
- }
- }
- }
-
- if (id == R.id.comment) {
- commentFocusChanged(b.comment, hasFocus);
- }
- else if (id == R.id.transaction_comment) {
- commentFocusChanged(b.transactionComment, hasFocus);
- }
- };
-
- b.newTransactionDescription.setOnFocusChangeListener(focusMonitor);
- b.accountRowAccName.setOnFocusChangeListener(focusMonitor);
- b.accountRowAccAmounts.setOnFocusChangeListener(focusMonitor);
- b.comment.setOnFocusChangeListener(focusMonitor);
- b.transactionComment.setOnFocusChangeListener(focusMonitor);
-
- NewTransactionActivity activity = (NewTransactionActivity) b.getRoot()
- .getContext();
-
- MLDB.hookAutocompletionAdapter(activity, b.newTransactionDescription,
- MLDB.DESCRIPTION_HISTORY_TABLE, "description", false, activity, mProfile);
- b.accountRowAccName.setAdapter(new AccountAutocompleteAdapter(b.getRoot()
- .getContext(), mProfile));
-
- decimalSeparator = "";
- Data.locale.observe(activity, locale -> decimalSeparator = String.valueOf(
- DecimalFormatSymbols.getInstance(locale)
- .getMonetaryDecimalSeparator()));
-
- final TextWatcher tw = new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
-
- @Override
- public void afterTextChanged(Editable s) {
-// debug("input", "text changed");
- if (inUpdate)
- return;
-
- Logger.debug("textWatcher", "calling syncData()");
- if (syncData()) {
- Logger.debug("textWatcher",
- "syncData() returned, checking if transaction is submittable");
- adapter.model.checkTransactionSubmittable(null);
- }
- Logger.debug("textWatcher", "done");
- }
- };
- final TextWatcher amountWatcher = new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {}
- @Override
- public void afterTextChanged(Editable s) {
- checkAmountValid(s.toString());
-
- if (syncData())
- adapter.model.checkTransactionSubmittable(null);
- }
- };
- b.newTransactionDescription.addTextChangedListener(tw);
- monitorComment(b.transactionComment);
- b.accountRowAccName.addTextChangedListener(tw);
- monitorComment(b.comment);
- b.accountRowAccAmounts.addTextChangedListener(amountWatcher);
-
- b.currencyButton.setOnClickListener(v -> {
- CurrencySelectorFragment cpf = new CurrencySelectorFragment();
- cpf.showPositionAndPadding();
- cpf.setOnCurrencySelectedListener(c -> adapter.setItemCurrency(getAdapterPosition(),
- (c == null) ? null : c.getName()));
- cpf.show(activity.getSupportFragmentManager(), "currency-selector");
- });
-
- commentFocusChanged(b.transactionComment, false);
- commentFocusChanged(b.comment, false);
-
- adapter.model.getFocusInfo()
- .observe(activity, this::applyFocus);
-
- Data.currencyGap.observe(activity,
- hasGap -> updateCurrencyPositionAndPadding(Data.currencySymbolPosition.getValue(),
- hasGap));
-
- Data.currencySymbolPosition.observe(activity,
- position -> updateCurrencyPositionAndPadding(position,
- Data.currencyGap.getValue()));
-
- adapter.model.getShowCurrency()
- .observe(activity, showCurrency -> {
- if (showCurrency) {
- b.currency.setVisibility(View.VISIBLE);
- b.currencyButton.setVisibility(View.VISIBLE);
- setCurrencyString(mProfile.getDefaultCommodity());
- }
- else {
- b.currency.setVisibility(View.GONE);
- b.currencyButton.setVisibility(View.GONE);
- setCurrencyString(null);
- }
- });
-
- adapter.model.getShowComments()
- .observe(activity, show -> {
- ConstraintLayout.LayoutParams amountLayoutParams =
- (ConstraintLayout.LayoutParams) b.amountLayout.getLayoutParams();
- ConstraintLayout.LayoutParams accountParams =
- (ConstraintLayout.LayoutParams) b.accountRowAccName.getLayoutParams();
-
- if (show) {
- accountParams.endToStart = ConstraintLayout.LayoutParams.UNSET;
- accountParams.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
-
- amountLayoutParams.topToTop = ConstraintLayout.LayoutParams.UNSET;
- amountLayoutParams.topToBottom = b.accountRowAccName.getId();
-
- b.commentLayout.setVisibility(View.VISIBLE);
- }
- else {
- accountParams.endToStart = b.amountLayout.getId();
- accountParams.endToEnd = ConstraintLayout.LayoutParams.UNSET;
-
- amountLayoutParams.topToBottom = ConstraintLayout.LayoutParams.UNSET;
- amountLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID;
-
- b.commentLayout.setVisibility(View.GONE);
- }
-
- b.accountRowAccName.setLayoutParams(accountParams);
- b.amountLayout.setLayoutParams(amountLayoutParams);
-
- b.transactionCommentLayout.setVisibility(show ? View.VISIBLE : View.GONE);
- });
- }
- private void applyFocus(NewTransactionModel.FocusInfo focusInfo) {
- if (ignoreFocusChanges) {
- Logger.debug("new-trans", "Ignoring focus change");
- return;
- }
- ignoreFocusChanges = true;
- try {
- if (((focusInfo == null) || (focusInfo.element == null) ||
- focusInfo.position != getAdapterPosition()))
- return;
-
- NewTransactionModel.Item item = getItem();
- if (item instanceof NewTransactionModel.TransactionHead) {
- NewTransactionModel.TransactionHead 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();
- switch (focusInfo.element) {
- case TransactionComment:
- b.transactionComment.setVisibility(View.VISIBLE);
- b.transactionComment.requestFocus();
- break;
- case Description:
- boolean focused = b.newTransactionDescription.requestFocus();
-// tvDescription.dismissDropDown();
- if (focused)
- Misc.showSoftKeyboard((NewTransactionActivity) b.getRoot()
- .getContext());
- break;
- }
- }
- else if (item instanceof NewTransactionModel.TransactionAccount) {
- NewTransactionModel.TransactionAccount acc = item.toTransactionAccount();
- switch (focusInfo.element) {
- case Amount:
- b.accountRowAccAmounts.requestFocus();
- break;
- case Comment:
- b.comment.setVisibility(View.VISIBLE);
- b.comment.requestFocus();
- break;
- case Account:
- boolean focused = b.accountRowAccName.requestFocus();
-// b.accountRowAccName.dismissDropDown();
- if (focused)
- Misc.showSoftKeyboard((NewTransactionActivity) b.getRoot()
- .getContext());
- break;
- }
- }
- }
- finally {
- ignoreFocusChanges = false;
- }
- }
- public void checkAmountValid(String s) {
- boolean valid = true;
- try {
- if (s.length() > 0) {
- float ignored = Float.parseFloat(s.replace(decimalSeparator, decimalDot));
- }
- }
- catch (NumberFormatException ex) {
- valid = false;
- }
-
- displayAmountValidity(valid);
- }
- private void displayAmountValidity(boolean valid) {
- b.accountRowAccAmounts.setCompoundDrawablesRelativeWithIntrinsicBounds(
- valid ? 0 : R.drawable.ic_error_outline_black_24dp, 0, 0, 0);
- b.accountRowAccAmounts.setMinEms(valid ? 4 : 5);
- }
- private void monitorComment(EditText editText) {
- editText.addTextChangedListener(new TextWatcher() {
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
- @Override
- public void afterTextChanged(Editable s) {
-// debug("input", "text changed");
- if (inUpdate)
- return;
-
- Logger.debug("textWatcher", "calling syncData()");
- syncData();
- Logger.debug("textWatcher",
- "syncData() returned, checking if transaction is submittable");
- styleComment(editText, s.toString());
- Logger.debug("textWatcher", "done");
- }
- });
- }
- private void commentFocusChanged(TextView textView, boolean hasFocus) {
- @ColorInt int textColor;
- textColor = b.dummyText.getTextColors()
- .getDefaultColor();
- if (hasFocus) {
- textView.setTypeface(null, Typeface.NORMAL);
- textView.setHint(R.string.transaction_account_comment_hint);
- }
- else {
- int alpha = (textColor >> 24 & 0xff);
- alpha = 3 * alpha / 4;
- textColor = (alpha << 24) | (0x00ffffff & textColor);
- textView.setTypeface(null, Typeface.ITALIC);
- textView.setHint("");
- if (TextUtils.isEmpty(textView.getText())) {
- textView.setVisibility(View.INVISIBLE);
- }
- }
- textView.setTextColor(textColor);
-
- }
- private void updateCurrencyPositionAndPadding(Currency.Position position, boolean hasGap) {
- ConstraintLayout.LayoutParams amountLP =
- (ConstraintLayout.LayoutParams) b.accountRowAccAmounts.getLayoutParams();
- ConstraintLayout.LayoutParams currencyLP =
- (ConstraintLayout.LayoutParams) b.currency.getLayoutParams();
-
- if (position == Currency.Position.before) {
- currencyLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
- currencyLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
-
- amountLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
- amountLP.endToStart = ConstraintLayout.LayoutParams.UNSET;
- amountLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
- amountLP.startToEnd = b.currency.getId();
-
- b.currency.setGravity(Gravity.END);
- }
- else {
- currencyLP.startToStart = ConstraintLayout.LayoutParams.UNSET;
- currencyLP.endToEnd = ConstraintLayout.LayoutParams.PARENT_ID;
-
- amountLP.startToStart = ConstraintLayout.LayoutParams.PARENT_ID;
- amountLP.startToEnd = ConstraintLayout.LayoutParams.UNSET;
- amountLP.endToEnd = ConstraintLayout.LayoutParams.UNSET;
- amountLP.endToStart = b.currency.getId();
-
- b.currency.setGravity(Gravity.START);
- }
-
- amountLP.resolveLayoutDirection(b.accountRowAccAmounts.getLayoutDirection());
- currencyLP.resolveLayoutDirection(b.currency.getLayoutDirection());
-
- b.accountRowAccAmounts.setLayoutParams(amountLP);
- b.currency.setLayoutParams(currencyLP);
-
- // distance between the amount and the currency symbol
- int gapSize = DimensionUtils.sp2px(b.currency.getContext(), 5);
-
- if (position == Currency.Position.before) {
- b.currency.setPaddingRelative(0, 0, hasGap ? gapSize : 0, 0);
- }
- else {
- b.currency.setPaddingRelative(hasGap ? gapSize : 0, 0, 0, 0);
- }
- }
- private void setCurrencyString(String currency) {
- @ColorInt int textColor = b.dummyText.getTextColors()
- .getDefaultColor();
- if (TextUtils.isEmpty(currency)) {
- b.currency.setText(R.string.currency_symbol);
- int alpha = (textColor >> 24) & 0xff;
- alpha = alpha * 3 / 4;
- b.currency.setTextColor((alpha << 24) | (0x00ffffff & textColor));
- }
- else {
- b.currency.setText(currency);
- b.currency.setTextColor(textColor);
- }
- }
- private void setCurrency(Currency currency) {
- setCurrencyString((currency == null) ? null : currency.getName());
- }
- private void setEditable(Boolean editable) {
- b.newTransactionDate.setEnabled(editable);
- b.newTransactionDescription.setEnabled(editable);
- b.accountRowAccName.setEnabled(editable);
- b.accountRowAccAmounts.setEnabled(editable);
- }
- private void beginUpdates() {
- if (inUpdate)
- throw new RuntimeException("Already in update mode");
- inUpdate = true;
- }
- private void endUpdates() {
- if (!inUpdate)
- throw new RuntimeException("Not in update mode");
- inUpdate = false;
- }
- /**
- * syncData()
- * <p>
- * Stores the data from the UI elements into the model item
- * Returns true if there were changes made that suggest transaction has to be
- * checked for being submittable
- */
- private boolean syncData() {
- if (syncingData) {
- Logger.debug("new-trans", "skipping syncData() loop");
- return false;
- }
-
- if (getAdapterPosition() < 0) {
- // probably the row was swiped out
- Logger.debug("new-trans", "Ignoring request to suncData(): adapter position negative");
- return false;
- }
-
- NewTransactionModel.Item item = getItem();
-
- syncingData = true;
-
- boolean significantChange = false;
-
- try {
- if (item instanceof NewTransactionModel.TransactionHead) {
- NewTransactionModel.TransactionHead head = item.toTransactionHead();
-
- head.setDate(String.valueOf(b.newTransactionDate.getText()));
-
- // transaction description is required
- if (TextUtils.isEmpty(head.getDescription()) !=
- TextUtils.isEmpty(b.newTransactionDescription.getText()))
- significantChange = true;
-
- head.setDescription(String.valueOf(b.newTransactionDescription.getText()));
- head.setComment(String.valueOf(b.transactionComment.getText()));
- }
- else if (item instanceof NewTransactionModel.TransactionAccount) {
- NewTransactionModel.TransactionAccount acc = item.toTransactionAccount();
-
- // having account name is important
- final Editable incomingAccountName = b.accountRowAccName.getText();
- if (TextUtils.isEmpty(acc.getAccountName()) !=
- TextUtils.isEmpty(incomingAccountName))
- significantChange = true;
-
- acc.setAccountName(String.valueOf(incomingAccountName));
- final int accNameSelEnd = b.accountRowAccName.getSelectionEnd();
- final int accNameSelStart = b.accountRowAccName.getSelectionStart();
- acc.setAccountNameCursorPosition(accNameSelEnd);
-
- acc.setComment(String.valueOf(b.comment.getText()));
-
- String amount = String.valueOf(b.accountRowAccAmounts.getText());
- amount = amount.trim();
-
- if (amount.isEmpty()) {
- if (acc.isAmountSet())
- significantChange = true;
- acc.resetAmount();
- acc.setAmountValid(true);
- }
- else {
- try {
- amount = amount.replace(decimalSeparator, decimalDot);
- final float parsedAmount = Float.parseFloat(amount);
- if (!acc.isAmountSet() || !Misc.equalFloats(parsedAmount, acc.getAmount()))
- significantChange = true;
- acc.setAmount(parsedAmount);
- acc.setAmountValid(true);
- }
- catch (NumberFormatException e) {
- Logger.debug("new-trans", String.format(
- "assuming amount is not set due to number format exception. " +
- "input was '%s'", amount));
- if (acc.isAmountValid())
- significantChange = true;
- acc.setAmountValid(false);
- }
- final String curr = String.valueOf(b.currency.getText());
- final String currValue;
- if (curr.equals(b.currency.getContext()
- .getResources()
- .getString(R.string.currency_symbol)) ||
- curr.isEmpty())
- currValue = null;
- else
- currValue = curr;
-
- if (!significantChange && !Misc.equalStrings(acc.getCurrency(), currValue))
- significantChange = true;
- acc.setCurrency(currValue);
- }
- }
- else {
- throw new RuntimeException("Should not happen");
- }
-
- return significantChange;
- }
- catch (ParseException e) {
- throw new RuntimeException("Should not happen", e);
- }
- finally {
- syncingData = false;
- }
- }
- private void pickTransactionDate() {
- DatePickerFragment picker = new DatePickerFragment();
- picker.setFutureDates(mProfile.getFutureDates());
- picker.setOnDatePickedListener(this);
- picker.setCurrentDateFromText(b.newTransactionDate.getText());
- picker.show(((NewTransactionActivity) b.getRoot()
- .getContext()).getSupportFragmentManager(), null);
- }
- /**
- * bind
- *
- * @param item updates the UI elements with the data from the model item
- */
- @SuppressLint("DefaultLocale")
- public void bind(@NonNull NewTransactionModel.Item item) {
- beginUpdates();
- try {
- syncingData = true;
- try {
- if (item instanceof NewTransactionModel.TransactionHead) {
- NewTransactionModel.TransactionHead head = item.toTransactionHead();
- b.newTransactionDate.setText(head.getFormattedDate());
-
- // avoid triggering completion pop-up
- SimpleCursorAdapter a =
- (SimpleCursorAdapter) b.newTransactionDescription.getAdapter();
- try {
- b.newTransactionDescription.setAdapter(null);
- b.newTransactionDescription.setText(head.getDescription());
- }
- finally {
- b.newTransactionDescription.setAdapter(a);
- }
-
- b.transactionComment.setText(head.getComment());
- //styleComment(b.transactionComment, head.getComment());
-
- b.ntrData.setVisibility(View.VISIBLE);
- b.ntrAccount.setVisibility(View.GONE);
- setEditable(true);
- }
- else if (item instanceof NewTransactionModel.TransactionAccount) {
- NewTransactionModel.TransactionAccount acc = item.toTransactionAccount();
-
- final String incomingAccountName = acc.getAccountName();
- final String presentAccountName = String.valueOf(b.accountRowAccName.getText());
- if (!Misc.equalStrings(incomingAccountName, presentAccountName)) {
- Logger.debug("bind",
- String.format("Setting account name from '%s' to '%s' (| @ %d)",
- presentAccountName, incomingAccountName,
- acc.getAccountNameCursorPosition()));
- // avoid triggering completion pop-up
- AccountAutocompleteAdapter a =
- (AccountAutocompleteAdapter) b.accountRowAccName.getAdapter();
- try {
- b.accountRowAccName.setAdapter(null);
- b.accountRowAccName.setText(incomingAccountName);
- b.accountRowAccName.setSelection(acc.getAccountNameCursorPosition());
- }
- finally {
- b.accountRowAccName.setAdapter(a);
- }
- }
-
- final String amountHint = acc.getAmountHint();
- if (amountHint == null) {
- b.accountRowAccAmounts.setHint(R.string.zero_amount);
- }
- else {
- b.accountRowAccAmounts.setHint(amountHint);
- }
-
- b.accountRowAccAmounts.setImeOptions(
- acc.isLast() ? EditorInfo.IME_ACTION_DONE : EditorInfo.IME_ACTION_NEXT);
-
- setCurrencyString(acc.getCurrency());
- b.accountRowAccAmounts.setText(
- acc.isAmountSet() ? String.format("%4.2f", acc.getAmount()) : null);
- displayAmountValidity(true);
-
- b.comment.setText(acc.getComment());
-
- b.ntrData.setVisibility(View.GONE);
- b.ntrAccount.setVisibility(View.VISIBLE);
-
- setEditable(true);
- }
- else {
- throw new RuntimeException("Don't know how to handle " + item);
- }
-
- applyFocus(mAdapter.model.getFocusInfo()
- .getValue());
- }
- finally {
- syncingData = false;
- }
- }
- finally {
- endUpdates();
- }
- }
- private void styleComment(EditText editText, String comment) {
- final View focusedView = editText.findFocus();
- editText.setTypeface(null, (focusedView == editText) ? Typeface.NORMAL : Typeface.ITALIC);
- editText.setVisibility(
- ((focusedView != editText) && TextUtils.isEmpty(comment)) ? View.INVISIBLE
- : View.VISIBLE);
- }
- @Override
- public void onDatePicked(int year, int month, int day) {
- final NewTransactionModel.TransactionHead head = getItem().toTransactionHead();
- head.setDate(new SimpleDate(year, month + 1, day));
- b.newTransactionDate.setText(head.getFormattedDate());
-
- boolean focused = b.newTransactionDescription.requestFocus();
- if (focused)
- Misc.showSoftKeyboard((NewTransactionActivity) b.getRoot()
- .getContext());
-
- }
- private NewTransactionModel.Item getItem() {
- return Objects.requireNonNull(mAdapter.model.getItems()
- .getValue())
- .get(getAdapterPosition());
- }
- @Override
- public void descriptionSelected(String description) {
- b.accountRowAccName.setText(description);
- b.accountRowAccAmounts.requestFocus(View.FOCUS_FORWARD);
- }
-}
--- /dev/null
+/*
+ * Copyright © 2021 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.ui.new_transaction;
+
+import android.view.View;
+
+import androidx.annotation.NonNull;
+import androidx.recyclerview.widget.RecyclerView;
+
+import net.ktnx.mobileledger.model.Data;
+import net.ktnx.mobileledger.model.MobileLedgerProfile;
+
+abstract class NewTransactionItemViewHolder extends RecyclerView.ViewHolder {
+ final NewTransactionItemsAdapter mAdapter;
+ final MobileLedgerProfile mProfile;
+ public NewTransactionItemViewHolder(@NonNull View itemView,
+ NewTransactionItemsAdapter adapter) {
+ super(itemView);
+ mAdapter = adapter;
+ mProfile = Data.getProfile();
+ }
+ NewTransactionModel.Item getItem() {
+ return mAdapter.getItem(getAdapterPosition());
+// return Objects.requireNonNull(mAdapter.model.getItems()
+// .getValue())
+// .get(getAdapterPosition());
+ }
+ abstract public void bind(NewTransactionModel.Item item);
+}
import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView;
-import net.ktnx.mobileledger.databinding.NewTransactionRowBinding;
+import net.ktnx.mobileledger.databinding.NewTransactionAccountRowBinding;
+import net.ktnx.mobileledger.databinding.NewTransactionHeaderRowBinding;
import net.ktnx.mobileledger.model.MobileLedgerProfile;
import net.ktnx.mobileledger.utils.Logger;
import java.util.Locale;
import java.util.Objects;
-class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItemHolder> {
+class NewTransactionItemsAdapter extends RecyclerView.Adapter<NewTransactionItemViewHolder> {
+ private static final int ITEM_VIEW_TYPE_HEADER = 1;
+ private static final int ITEM_VIEW_TYPE_ACCOUNT = 2;
final NewTransactionModel model;
private final ItemTouchHelper touchHelper;
private final AsyncListDiffer<NewTransactionModel.Item> differ =
});
}
@Override
+ public int getItemViewType(int position) {
+ final ItemType type = differ.getCurrentList()
+ .get(position)
+ .getType();
+ switch (type) {
+ case generalData:
+ return ITEM_VIEW_TYPE_HEADER;
+ case transactionRow:
+ return ITEM_VIEW_TYPE_ACCOUNT;
+ default:
+ throw new RuntimeException("Can't handle " + type);
+ }
+ }
+ @Override
public long getItemId(int position) {
return differ.getCurrentList()
.get(position)
}
@NonNull
@Override
- public NewTransactionItemHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- NewTransactionRowBinding b =
- NewTransactionRowBinding.inflate(LayoutInflater.from(parent.getContext()), parent,
- false);
-
- final NewTransactionItemHolder newHolder = new NewTransactionItemHolder(b, this);
- Logger.debug("new-trans",
- "Creating new ViewHolder " + Integer.toHexString(newHolder.hashCode()));
- return newHolder;
+ public NewTransactionItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent,
+ int viewType) {
+ switch (viewType) {
+ case ITEM_VIEW_TYPE_HEADER:
+ NewTransactionHeaderRowBinding headerBinding =
+ NewTransactionHeaderRowBinding.inflate(
+ LayoutInflater.from(parent.getContext()), parent, false);
+ final NewTransactionHeaderItemHolder headerHolder =
+ new NewTransactionHeaderItemHolder(headerBinding, this);
+ Logger.debug("new-trans", "Creating new Header ViewHolder " +
+ Integer.toHexString(headerHolder.hashCode()));
+ return headerHolder;
+ case ITEM_VIEW_TYPE_ACCOUNT:
+ NewTransactionAccountRowBinding accBinding =
+ NewTransactionAccountRowBinding.inflate(
+ LayoutInflater.from(parent.getContext()), parent, false);
+ final NewTransactionAccountRowItemHolder accHolder =
+ new NewTransactionAccountRowItemHolder(accBinding, this);
+ Logger.debug("new-trans", "Creating new AccountRow ViewHolder " +
+ Integer.toHexString(accHolder.hashCode()));
+ return accHolder;
+ default:
+ throw new RuntimeException("Cant handle view type " + viewType);
+ }
}
@Override
- public void onBindViewHolder(@NonNull NewTransactionItemHolder holder, int position) {
+ public void onBindViewHolder(@NonNull NewTransactionItemViewHolder holder, int position) {
Logger.debug("bind",
String.format(Locale.US, "Binding item at position %d, holder %s", position,
Integer.toHexString(holder.hashCode())));
Logger.debug("new-trans", "adapter: submitting new item list");
differ.submitList(newList);
}
+ public NewTransactionModel.Item getItem(int position) {
+ return differ.getCurrentList()
+ .get(position);
+ }
}
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ Copyright © 2021 Damyan Ivanov.
+ ~ This file is part of MoLe.
+ ~ MoLe is free software: you can distribute it and/or modify it
+ ~ under the term of the GNU General Public License as published by
+ ~ the Free Software Foundation, either version 3 of the License, or
+ ~ (at your opinion), any later version.
+ ~
+ ~ MoLe is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License terms for details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ -->
+
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:animateLayoutChanges="true"
+ >
+
+ <TextView
+ android:id="@+id/dummy_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:visibility="gone"
+ tools:ignore="MissingConstraints"
+ />
+ <net.ktnx.mobileledger.ui.AutoCompleteTextViewWithClear
+ android:id="@+id/account_row_acc_name"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_weight="9"
+ android:width="0dp"
+ android:hint="@string/new_transaction_account_hint"
+ android:imeOptions="actionNext"
+ android:inputType="text"
+ android:selectAllOnFocus="false"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ />
+
+ <androidx.constraintlayout.widget.ConstraintLayout
+ android:id="@+id/comment_layout"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ app:layout_constraintEnd_toStartOf="@id/amount_layout"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/account_row_acc_name"
+ >
+
+ <TextView
+ android:id="@+id/account_comment_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/ic_comment_gray_24dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ />
+
+ <net.ktnx.mobileledger.ui.EditTextWithClear
+ android:id="@+id/comment"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:imeOptions="actionNext"
+ android:inputType="text"
+ android:visibility="invisible"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toEndOf="@id/account_comment_button"
+ app:layout_constraintTop_toTopOf="parent"
+ />
+ </androidx.constraintlayout.widget.ConstraintLayout>
+
+ <androidx.constraintlayout.widget.ConstraintLayout
+ android:id="@+id/amount_layout"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/account_row_acc_name"
+ >
+
+ <TextView
+ android:id="@+id/currencyButton"
+ android:layout_width="wrap_content"
+ android:layout_height="0dp"
+ android:minWidth="30dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintEnd_toEndOf="@id/currency"
+ app:layout_constraintStart_toStartOf="@id/currency"
+ app:layout_constraintTop_toTopOf="parent"
+ />
+ <EditText
+ android:id="@+id/account_row_acc_amounts"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom|end"
+ android:layout_weight="0"
+ android:width="0dp"
+ android:foregroundGravity="bottom"
+ android:gravity="bottom|end"
+ android:hint="@string/zero_amount"
+ android:imeOptions="actionNext"
+ android:inputType="number|numberSigned|numberDecimal"
+ android:minEms="4"
+ android:selectAllOnFocus="true"
+ android:textAlignment="viewEnd"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintLeft_toLeftOf="parent"
+ app:layout_constraintRight_toLeftOf="@id/currency"
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintWidth_min="@dimen/text_margin"
+ />
+
+ <TextView
+ android:id="@+id/currency"
+ style="@style/TextAppearance.AppCompat.Widget.Button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:gravity="center_horizontal"
+ android:minWidth="30dp"
+ android:text="@string/currency_symbol"
+ android:textAllCaps="false"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintRight_toRightOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ />
+ </androidx.constraintlayout.widget.ConstraintLayout>
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="utf-8"?><!--
+ ~ Copyright © 2021 Damyan Ivanov.
+ ~ This file is part of MoLe.
+ ~ MoLe is free software: you can distribute it and/or modify it
+ ~ under the term of the GNU General Public License as published by
+ ~ the Free Software Foundation, either version 3 of the License, or
+ ~ (at your opinion), any later version.
+ ~
+ ~ MoLe is distributed in the hope that it will be useful,
+ ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ ~ GNU General Public License terms for details.
+ ~
+ ~ You should have received a copy of the GNU General Public License
+ ~ along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ -->
+
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:app="http://schemas.android.com/apk/res-auto"
+ xmlns:tools="http://schemas.android.com/tools"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:animateLayoutChanges="true"
+ android:orientation="horizontal"
+ >
+
+ <TextView
+ android:id="@+id/dummy_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:visibility="gone"
+ tools:ignore="MissingConstraints"
+ />
+ <EditText
+ android:id="@+id/new_transaction_date"
+ android:layout_width="94dp"
+ android:layout_height="wrap_content"
+ android:accessibilityTraversalBefore="@+id/new_transaction_description"
+ android:drawableStart="@drawable/ic_event_gray_24dp"
+ android:enabled="true"
+ android:focusable="false"
+ android:gravity="bottom|center"
+ android:hint="@string/new_transaction_date_hint"
+ android:inputType="none"
+ android:nextFocusDown="@+id/new_transaction_acc_1"
+ android:nextFocusForward="@+id/new_transaction_description"
+ android:textAlignment="gravity"
+ android:textCursorDrawable="@android:color/transparent"
+ app:layout_constrainedHeight="true"
+ app:layout_constraintHorizontal_weight="8"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ tools:ignore="TextFields"
+ />
+
+ <net.ktnx.mobileledger.ui.AutoCompleteTextViewWithClear
+ android:id="@+id/new_transaction_description"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="bottom"
+ android:layout_marginStart="8dp"
+ android:accessibilityTraversalAfter="@+id/new_transaction_date"
+ android:foregroundGravity="bottom"
+ android:gravity="bottom"
+ android:hint="@string/new_transaction_description_hint"
+ android:imeOptions="actionNext"
+ android:inputType="text"
+ android:nextFocusLeft="@+id/new_transaction_date"
+ android:nextFocusUp="@+id/new_transaction_date"
+ android:selectAllOnFocus="false"
+ android:singleLine="true"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintHorizontal_weight="30"
+ app:layout_constraintStart_toEndOf="@id/new_transaction_date"
+ app:layout_constraintTop_toTopOf="parent"
+ />
+
+ <androidx.constraintlayout.widget.ConstraintLayout
+ android:id="@+id/transaction_comment_layout"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toBottomOf="@id/new_transaction_description"
+ >
+
+ <TextView
+ android:id="@+id/transaction_comment_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/ic_comment_gray_24dp"
+ app:layout_constraintBottom_toBottomOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent"
+ />
+
+ <net.ktnx.mobileledger.ui.EditTextWithClear
+ android:id="@+id/transaction_comment"
+ android:layout_width="0dp"
+ android:layout_height="wrap_content"
+ android:imeOptions="actionNext"
+ android:inputType="text"
+ android:visibility="invisible"
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toEndOf="@id/transaction_comment_button"
+ app:layout_constraintTop_toTopOf="parent"
+ />
+ </androidx.constraintlayout.widget.ConstraintLayout>
+
+</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?><!--
- ~ Copyright © 2021 Damyan Ivanov.
- ~ This file is part of MoLe.
- ~ MoLe is free software: you can distribute it and/or modify it
- ~ under the term of the GNU General Public License as published by
- ~ the Free Software Foundation, either version 3 of the License, or
- ~ (at your opinion), any later version.
- ~
- ~ MoLe is distributed in the hope that it will be useful,
- ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
- ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ~ GNU General Public License terms for details.
- ~
- ~ You should have received a copy of the GNU General Public License
- ~ along with MoLe. If not, see <https://www.gnu.org/licenses/>.
- -->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:animateLayoutChanges="true"
- android:orientation="vertical"
- >
-
- <androidx.constraintlayout.widget.ConstraintLayout
- android:id="@+id/ntr_data"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:animateLayoutChanges="true"
- android:orientation="horizontal"
- >
-
- <TextView
- android:id="@+id/dummy_text"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:visibility="gone"
- tools:ignore="MissingConstraints"
- />
- <EditText
- android:id="@+id/new_transaction_date"
- android:layout_width="94dp"
- android:layout_height="wrap_content"
- android:accessibilityTraversalBefore="@+id/new_transaction_description"
- android:drawableStart="@drawable/ic_event_gray_24dp"
- android:enabled="true"
- android:focusable="false"
- android:gravity="bottom|center"
- android:hint="@string/new_transaction_date_hint"
- android:inputType="none"
- android:nextFocusDown="@+id/new_transaction_acc_1"
- android:nextFocusForward="@+id/new_transaction_description"
- android:textAlignment="gravity"
- android:textCursorDrawable="@android:color/transparent"
- app:layout_constrainedHeight="true"
- app:layout_constraintHorizontal_weight="8"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- tools:ignore="TextFields"
- />
-
- <net.ktnx.mobileledger.ui.AutoCompleteTextViewWithClear
- android:id="@+id/new_transaction_description"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom"
- android:layout_marginStart="8dp"
- android:accessibilityTraversalAfter="@+id/new_transaction_date"
- android:foregroundGravity="bottom"
- android:gravity="bottom"
- android:hint="@string/new_transaction_description_hint"
- android:imeOptions="actionNext"
- android:inputType="text"
- android:nextFocusLeft="@+id/new_transaction_date"
- android:nextFocusUp="@+id/new_transaction_date"
- android:selectAllOnFocus="false"
- android:singleLine="true"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_weight="30"
- app:layout_constraintStart_toEndOf="@id/new_transaction_date"
- app:layout_constraintTop_toTopOf="parent"
- />
-
- <androidx.constraintlayout.widget.ConstraintLayout
- android:id="@+id/transaction_comment_layout"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:animateLayoutChanges="true"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@id/new_transaction_description"
- >
-
- <TextView
- android:id="@+id/transaction_comment_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/ic_comment_gray_24dp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- />
-
- <net.ktnx.mobileledger.ui.EditTextWithClear
- android:id="@+id/transaction_comment"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:imeOptions="actionNext"
- android:inputType="text"
- android:visibility="invisible"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toEndOf="@id/transaction_comment_button"
- app:layout_constraintTop_toTopOf="parent"
- />
- </androidx.constraintlayout.widget.ConstraintLayout>
-
- </androidx.constraintlayout.widget.ConstraintLayout>
-
- <androidx.constraintlayout.widget.ConstraintLayout
- android:id="@+id/ntr_account"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:animateLayoutChanges="true"
- >
-
- <net.ktnx.mobileledger.ui.AutoCompleteTextViewWithClear
- android:id="@+id/account_row_acc_name"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="9"
- android:width="0dp"
- android:hint="@string/new_transaction_account_hint"
- android:imeOptions="actionNext"
- android:inputType="text"
- android:selectAllOnFocus="false"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- />
-
- <androidx.constraintlayout.widget.ConstraintLayout
- android:id="@+id/comment_layout"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:animateLayoutChanges="true"
- app:layout_constraintEnd_toStartOf="@id/amount_layout"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@id/account_row_acc_name"
- >
-
- <TextView
- android:id="@+id/account_comment_button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/ic_comment_gray_24dp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- />
-
- <net.ktnx.mobileledger.ui.EditTextWithClear
- android:id="@+id/comment"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:imeOptions="actionNext"
- android:inputType="text"
- android:visibility="invisible"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toEndOf="@id/account_comment_button"
- app:layout_constraintTop_toTopOf="parent"
- />
- </androidx.constraintlayout.widget.ConstraintLayout>
-
- <androidx.constraintlayout.widget.ConstraintLayout
- android:id="@+id/amount_layout"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:animateLayoutChanges="true"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintTop_toBottomOf="@id/account_row_acc_name"
- >
-
- <TextView
- android:id="@+id/currencyButton"
- android:layout_width="wrap_content"
- android:layout_height="0dp"
- android:minWidth="30dp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="@id/currency"
- app:layout_constraintStart_toStartOf="@id/currency"
- app:layout_constraintTop_toTopOf="parent"
- />
- <EditText
- android:id="@+id/account_row_acc_amounts"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="bottom|end"
- android:layout_weight="0"
- android:width="0dp"
- android:foregroundGravity="bottom"
- android:gravity="bottom|end"
- android:hint="@string/zero_amount"
- android:imeOptions="actionNext"
- android:inputType="number|numberSigned|numberDecimal"
- android:minEms="4"
- android:selectAllOnFocus="true"
- android:textAlignment="viewEnd"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintLeft_toLeftOf="parent"
- app:layout_constraintRight_toLeftOf="@id/currency"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintWidth_min="@dimen/text_margin"
- />
-
- <TextView
- android:id="@+id/currency"
- style="@style/TextAppearance.AppCompat.Widget.Button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:gravity="center_horizontal"
- android:minWidth="30dp"
- android:text="@string/currency_symbol"
- android:textAllCaps="false"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintRight_toRightOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- />
- </androidx.constraintlayout.widget.ConstraintLayout>
-
- </androidx.constraintlayout.widget.ConstraintLayout>
-
-</LinearLayout>
\ No newline at end of file