Fix bug with currency localization.

This commit is contained in:
Cody Henthorne
2021-09-07 13:29:52 -04:00
committed by Greyson Parrelli
parent e3b7fe7509
commit c9ba0432a0
2 changed files with 15 additions and 8 deletions

View File

@@ -1,5 +1,8 @@
package org.thoughtcrime.securesms.payments.create; package org.thoughtcrime.securesms.payments.create;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
@@ -25,7 +28,11 @@ enum AmountKeyboardGlyph {
this.glyphRes = glyphRes; this.glyphRes = glyphRes;
} }
public int getGlyphRes() { public String getGlyph(@NonNull Context context) {
return glyphRes; if (this == DECIMAL) {
return ".";
} else {
return context.getString(glyphRes);
}
} }
} }

View File

@@ -230,7 +230,7 @@ public class CreatePaymentViewModel extends ViewModel {
if (!oldAmount.isEmpty()) { if (!oldAmount.isEmpty()) {
String newAmount = oldAmount.substring(0, oldAmount.length() - 1); String newAmount = oldAmount.substring(0, oldAmount.length() - 1);
if (newAmount.isEmpty()) { if (newAmount.isEmpty()) {
return context.getString(AmountKeyboardGlyph.ZERO.getGlyphRes()); return AmountKeyboardGlyph.ZERO.getGlyph(context);
} else { } else {
return newAmount; return newAmount;
} }
@@ -239,12 +239,12 @@ public class CreatePaymentViewModel extends ViewModel {
return oldAmount; return oldAmount;
} }
boolean oldAmountIsZero = context.getString(AmountKeyboardGlyph.ZERO.getGlyphRes()).equals(oldAmount); boolean oldAmountIsZero = AmountKeyboardGlyph.ZERO.getGlyph(context).equals(oldAmount);
int decimalIndex = oldAmount.indexOf(context.getString(AmountKeyboardGlyph.DECIMAL.getGlyphRes())); int decimalIndex = oldAmount.indexOf(AmountKeyboardGlyph.DECIMAL.getGlyph(context));
if (glyph == AmountKeyboardGlyph.DECIMAL) { if (glyph == AmountKeyboardGlyph.DECIMAL) {
if (oldAmountIsZero) { if (oldAmountIsZero) {
return context.getString(AmountKeyboardGlyph.ZERO.getGlyphRes()) + context.getString(glyph.getGlyphRes()); return AmountKeyboardGlyph.ZERO.getGlyph(context) + glyph.getGlyph(context);
} else if (decimalIndex > -1) { } else if (decimalIndex > -1) {
return oldAmount; return oldAmount;
} }
@@ -255,9 +255,9 @@ public class CreatePaymentViewModel extends ViewModel {
} }
if (oldAmountIsZero) { if (oldAmountIsZero) {
return context.getString(glyph.getGlyphRes()); return glyph.getGlyph(context);
} else { } else {
return oldAmount + context.getString(glyph.getGlyphRes()); return oldAmount + glyph.getGlyph(context);
} }
} }