From c9ba0432a04067769aa3d622730deb694574113b Mon Sep 17 00:00:00 2001 From: Cody Henthorne Date: Tue, 7 Sep 2021 13:29:52 -0400 Subject: [PATCH] Fix bug with currency localization. --- .../payments/create/AmountKeyboardGlyph.java | 11 +++++++++-- .../payments/create/CreatePaymentViewModel.java | 12 ++++++------ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/payments/create/AmountKeyboardGlyph.java b/app/src/main/java/org/thoughtcrime/securesms/payments/create/AmountKeyboardGlyph.java index 7b625ce9af..f1031b79ef 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/payments/create/AmountKeyboardGlyph.java +++ b/app/src/main/java/org/thoughtcrime/securesms/payments/create/AmountKeyboardGlyph.java @@ -1,5 +1,8 @@ package org.thoughtcrime.securesms.payments.create; +import android.content.Context; + +import androidx.annotation.NonNull; import androidx.annotation.StringRes; import org.thoughtcrime.securesms.R; @@ -25,7 +28,11 @@ enum AmountKeyboardGlyph { this.glyphRes = glyphRes; } - public int getGlyphRes() { - return glyphRes; + public String getGlyph(@NonNull Context context) { + if (this == DECIMAL) { + return "."; + } else { + return context.getString(glyphRes); + } } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/payments/create/CreatePaymentViewModel.java b/app/src/main/java/org/thoughtcrime/securesms/payments/create/CreatePaymentViewModel.java index 24f6d015f9..5425803413 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/payments/create/CreatePaymentViewModel.java +++ b/app/src/main/java/org/thoughtcrime/securesms/payments/create/CreatePaymentViewModel.java @@ -230,7 +230,7 @@ public class CreatePaymentViewModel extends ViewModel { if (!oldAmount.isEmpty()) { String newAmount = oldAmount.substring(0, oldAmount.length() - 1); if (newAmount.isEmpty()) { - return context.getString(AmountKeyboardGlyph.ZERO.getGlyphRes()); + return AmountKeyboardGlyph.ZERO.getGlyph(context); } else { return newAmount; } @@ -239,12 +239,12 @@ public class CreatePaymentViewModel extends ViewModel { return oldAmount; } - boolean oldAmountIsZero = context.getString(AmountKeyboardGlyph.ZERO.getGlyphRes()).equals(oldAmount); - int decimalIndex = oldAmount.indexOf(context.getString(AmountKeyboardGlyph.DECIMAL.getGlyphRes())); + boolean oldAmountIsZero = AmountKeyboardGlyph.ZERO.getGlyph(context).equals(oldAmount); + int decimalIndex = oldAmount.indexOf(AmountKeyboardGlyph.DECIMAL.getGlyph(context)); if (glyph == AmountKeyboardGlyph.DECIMAL) { if (oldAmountIsZero) { - return context.getString(AmountKeyboardGlyph.ZERO.getGlyphRes()) + context.getString(glyph.getGlyphRes()); + return AmountKeyboardGlyph.ZERO.getGlyph(context) + glyph.getGlyph(context); } else if (decimalIndex > -1) { return oldAmount; } @@ -255,9 +255,9 @@ public class CreatePaymentViewModel extends ViewModel { } if (oldAmountIsZero) { - return context.getString(glyph.getGlyphRes()); + return glyph.getGlyph(context); } else { - return oldAmount + context.getString(glyph.getGlyphRes()); + return oldAmount + glyph.getGlyph(context); } }