simplifying Clear, not sure why was it so complicated

This commit is contained in:
tibbi 2020-11-06 22:35:13 +01:00
parent f527d8d954
commit ab5c0a3522
1 changed files with 5 additions and 20 deletions

View File

@ -167,29 +167,14 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
} }
fun handleClear() { fun handleClear() {
val oldValue = displayedNumber var newValue = inputDisplayedFormula.dropLast(1)
var newValue = "0" if (newValue.isEmpty()) {
val len = oldValue.length newValue = "0"
var minLen = 1
if (oldValue.contains("-"))
minLen++
if (len > minLen) {
newValue = oldValue.substring(0, len - 1)
} }
newValue = newValue.replace("\\.$".toRegex(), "") newValue = newValue.trimEnd(',')
if (!newValue.contains('+') && inputDisplayedFormula = newValue
!newValue.contains('-') &&
!newValue.contains('*') &&
!newValue.contains('/') &&
!newValue.contains('%') &&
!newValue.contains('^') &&
!newValue.contains('√')) {
newValue = formatString(newValue)
}
showNewResult(newValue) showNewResult(newValue)
inputDisplayedFormula = if (newValue != "0") newValue else ""
} }
fun handleReset() { fun handleReset() {