@@ -221,7 +221,6 @@ class ConverterView @JvmOverloads constructor(
221221 } else {
222222 value + = digit
223223 }
224- value = checkTemperatureLimits(value)
225224 binding.topUnitText.text = formatter.formatForDisplay(value)
226225 }
227226
@@ -230,6 +229,9 @@ class ConverterView @JvmOverloads constructor(
230229 updateBottomValue()
231230 updateUnitLabelsAndSymbols()
232231 notifyUnitsChanged()
232+ if (converter != null ) {
233+ context.config.putLastConverterUnits(converter!! , topUnit!! , bottomUnit!! )
234+ }
233235 }
234236
235237 private fun updateUnitLabelsAndSymbols () {
@@ -265,10 +267,15 @@ class ConverterView @JvmOverloads constructor(
265267
266268 private fun updateBottomValue () {
267269 converter?.apply {
270+ val rawText = binding.topUnitText.text.toString()
271+ val clampedText = checkTemperatureLimits(rawText)
272+ if (clampedText != rawText) {
273+ binding.topUnitText.text = clampedText
274+ }
275+
268276 @Suppress(" SwallowedException" )
269277 val topValue = try {
270- formatter.removeGroupingSeparator(binding.topUnitText.text.toString())
271- .toBigDecimal()
278+ formatter.removeGroupingSeparator(clampedText).toBigDecimal()
272279 } catch (_: NumberFormatException ) {
273280 // Return zero if input cannot be parsed as a valid number
274281 BigDecimal .ZERO
@@ -357,8 +364,6 @@ class ConverterView @JvmOverloads constructor(
357364 else -> " -$value "
358365 }
359366
360- value = checkTemperatureLimits(value)
361-
362367 binding.topUnitText.text = value
363368 updateBottomValue()
364369 }
0 commit comments