X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionItemHolder.java;h=0e2c947517140719fa3d9934e7e5bca734ba6953;hb=45616458ebcb6f3eed1c530f9b6d2d1d598ab8e0;hp=c6232d167f7e303af4d93be2222354918727cc36;hpb=a0508ea0def0c4c6400626f26517d8e69631ff15;p=mobile-ledger.git diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java index c6232d16..0e2c9475 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/new_transaction/NewTransactionItemHolder.java @@ -124,8 +124,9 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder try { String input = String.valueOf(b.accountRowAccAmounts.getText()); input = input.replace(decimalSeparator, decimalDot); - b.accountRowAccAmounts.setText( - String.format("%4.2f", Float.parseFloat(input))); + final String newText = String.format("%4.2f", Float.parseFloat(input)); + if (!newText.equals(input)) + b.accountRowAccAmounts.setText(newText); } catch (NumberFormatException ex) { // ignored @@ -206,8 +207,8 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder b.currencyButton.setOnClickListener(v -> { CurrencySelectorFragment cpf = new CurrencySelectorFragment(); cpf.showPositionAndPadding(); - cpf.setOnCurrencySelectedListener( - c -> adapter.setItemCurrency(getAdapterPosition(), c.getName())); + cpf.setOnCurrencySelectedListener(c -> adapter.setItemCurrency(getAdapterPosition(), + (c == null) ? null : c.getName())); cpf.show(activity.getSupportFragmentManager(), "currency-selector"); }); @@ -230,12 +231,12 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder if (showCurrency) { b.currency.setVisibility(View.VISIBLE); b.currencyButton.setVisibility(View.VISIBLE); - b.currency.setText(mProfile.getDefaultCommodity()); + setCurrencyString(mProfile.getDefaultCommodity()); } else { b.currency.setVisibility(View.GONE); b.currencyButton.setVisibility(View.GONE); - b.currency.setText(null); + setCurrencyString(null); } }); @@ -436,7 +437,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder private void setCurrencyString(String currency) { @ColorInt int textColor = b.dummyText.getTextColors() .getDefaultColor(); - if ((currency == null) || currency.isEmpty()) { + if (TextUtils.isEmpty(currency)) { b.currency.setText(R.string.currency_symbol); int alpha = (textColor >> 24) & 0xff; alpha = alpha * 3 / 4; @@ -479,6 +480,12 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder 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; @@ -626,9 +633,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder try { b.accountRowAccName.setAdapter(null); b.accountRowAccName.setText(incomingAccountName); - if (b.accountRowAccName.hasFocus()) - b.accountRowAccName.setSelection( - acc.getAccountNameCursorPosition()); + b.accountRowAccName.setSelection(acc.getAccountNameCursorPosition()); } finally { b.accountRowAccName.setAdapter(a);