Skip to content

Commit 2d63b7a

Browse files
authored
fix: check temperature limits on swap (#113)
* fix: save last converter units on swap * fix: clamp temperature limits on swap
1 parent 4b83b9c commit 2d63b7a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

app/src/main/kotlin/org/fossify/math/views/ConverterView.kt

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)