Set proper money separator when presenting custom amount string to user in MoneyView.

fork-5.53.8
Alex Hart 2021-09-02 17:05:29 -03:00 zatwierdzone przez Greyson Parrelli
rodzic 664d6475d9
commit 7d994b2ae1
2 zmienionych plików z 13 dodań i 2 usunięć

Wyświetl plik

@ -19,6 +19,7 @@ import org.whispersystems.signalservice.api.payments.Currency;
import org.whispersystems.signalservice.api.payments.FormatterOptions;
import org.whispersystems.signalservice.api.payments.Money;
import java.text.DecimalFormatSymbols;
import java.text.NumberFormat;
import java.util.Locale;
@ -65,8 +66,15 @@ public final class MoneyView extends AppCompatTextView {
styledAttributes.recycle();
}
public @NonNull String localizeAmountString(@NonNull String amount) {
String decimalSeparator = String.valueOf(DecimalFormatSymbols.getInstance().getDecimalSeparator());
String groupingSeparator = String.valueOf(DecimalFormatSymbols.getInstance().getGroupingSeparator());
return amount.replace(".", "__D__").replace(",", "__G__").replace("__D__", decimalSeparator).replace("__G__", groupingSeparator);
}
public void setMoney(@NonNull String amount, @NonNull Currency currency) {
SpannableString balanceSpan = new SpannableString(amount + currency.getCurrencyCode());
SpannableString balanceSpan = new SpannableString(localizeAmountString(amount) + currency.getCurrencyCode());
int currencyIndex = balanceSpan.length() - currency.getCurrencyCode().length();
balanceSpan.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.payment_currency_code_foreground_color)), currencyIndex, currencyIndex + currency.getCurrencyCode().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
setText(balanceSpan);

Wyświetl plik

@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.payments.create;
import android.app.AlertDialog;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;
@ -33,6 +32,7 @@ import org.thoughtcrime.securesms.util.ViewUtil;
import org.whispersystems.signalservice.api.payments.FormatterOptions;
import org.whispersystems.signalservice.api.payments.Money;
import java.text.DecimalFormatSymbols;
import java.util.Currency;
import java.util.HashMap;
import java.util.Map;
@ -94,6 +94,9 @@ public class CreatePaymentFragment extends LoggingFragment {
addNote = view.findViewById(R.id.create_payment_fragment_add_note);
toggle = view.findViewById(R.id.create_payment_fragment_toggle);
TextView decimal = view.findViewById(R.id.create_payment_fragment_keyboard_decimal);
decimal.setText(String.valueOf(DecimalFormatSymbols.getInstance().getDecimalSeparator()));
View infoTapTarget = view.findViewById(R.id.create_payment_fragment_info_tap_region);
//noinspection CodeBlock2Expr