X-Git-Url: https://git.ktnx.net/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Fnew_transaction%2FNewTransactionItemHolder.java;h=6df1b5406cac95c88d9f25565f4374b4764cf2b6;hb=70324bceb28a00b4a339fbb5a12eb657094f6f22;hp=247f40eb748006c83477c59433661037e31919e6;hpb=4b70b2a7f456447dfe56468e09fe30bf9dbebd56;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 247f40eb..6df1b540 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;