Fix crash in custom boost input.
This commit is contained in:
parent
98fab95683
commit
510a295198
3 changed files with 19 additions and 2 deletions
|
@ -266,7 +266,8 @@ data class Boost(
|
|||
if (withoutSymbol != withoutLeadingZeroes) {
|
||||
text?.removeTextChangedListener(this)
|
||||
|
||||
s.replace(s.indexOf(withoutSymbol), withoutSymbol.length, withoutLeadingZeroes)
|
||||
val start = s.indexOf(withoutSymbol)
|
||||
s.replace(start, start + withoutSymbol.length, withoutLeadingZeroes)
|
||||
|
||||
text?.addTextChangedListener(this)
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ import org.thoughtcrime.securesms.keyvalue.SignalStore
|
|||
import org.thoughtcrime.securesms.util.InternetConnectionObserver
|
||||
import org.thoughtcrime.securesms.util.PlatformCurrencyUtil
|
||||
import org.thoughtcrime.securesms.util.livedata.Store
|
||||
import java.lang.NumberFormatException
|
||||
import java.math.BigDecimal
|
||||
import java.text.DecimalFormat
|
||||
import java.text.DecimalFormatSymbols
|
||||
|
@ -201,7 +202,12 @@ class BoostViewModel(
|
|||
} else {
|
||||
val decimalFormat = DecimalFormat.getInstance() as DecimalFormat
|
||||
decimalFormat.isParseBigDecimal = true
|
||||
decimalFormat.parse(amount) as BigDecimal
|
||||
|
||||
try {
|
||||
decimalFormat.parse(amount) as BigDecimal
|
||||
} catch (e: NumberFormatException) {
|
||||
BigDecimal.ZERO
|
||||
}
|
||||
}
|
||||
|
||||
store.update { it.copy(customAmount = FiatMoney(bigDecimalAmount, it.customAmount.currency)) }
|
||||
|
|
|
@ -61,6 +61,16 @@ class BoostTest__MoneyFilter {
|
|||
assertEquals("5", result)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given USD, when I enter 00005dot00, then I expect 5 from text change`() {
|
||||
val testSubject = Boost.MoneyFilter(usd)
|
||||
val editable = SpannableStringBuilder("00005.00")
|
||||
|
||||
testSubject.afterTextChanged(editable)
|
||||
|
||||
assertEquals("$5", editable.toString())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given USD, when I enter 5dot000, then I expect successful filter`() {
|
||||
val testSubject = Boost.MoneyFilter(yen)
|
||||
|
|
Loading…
Add table
Reference in a new issue