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;
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);
}
}
}

View File

@@ -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);
}
}