X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionItemHolder.java;h=5757c72a249073360e5a2a20a4c3d8eb7fb7b67a;hb=a3e134a982b377a6b27ac409048d84bac6195814;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..5757c72a 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,17 @@ 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)) { + boolean wasSyncingData = syncingData; + syncingData = true; + try { + b.accountRowAccAmounts.setText(newText); + } + finally { + syncingData = wasSyncingData; + } + } } catch (NumberFormatException ex) { // ignored @@ -206,8 +215,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 +239,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 +445,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 +488,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; @@ -551,7 +566,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder else currValue = curr; - if (!significantChange && !TextUtils.equals(acc.getCurrency(), currValue)) + if (!significantChange && !Misc.equalStrings(acc.getCurrency(), currValue)) significantChange = true; acc.setCurrency(currValue); } @@ -615,7 +630,7 @@ class NewTransactionItemHolder extends RecyclerView.ViewHolder final String incomingAccountName = acc.getAccountName(); final String presentAccountName = String.valueOf(b.accountRowAccName.getText()); - if (!TextUtils.equals(incomingAccountName, presentAccountName)) { + if (!Misc.equalStrings(incomingAccountName, presentAccountName)) { Logger.debug("bind", String.format("Setting account name from '%s' to '%s' (| @ %d)", presentAccountName, incomingAccountName, @@ -626,9 +641,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);