Fixed inserting zero after using clear

This commit is contained in:
Agnieszka C
2022-01-16 15:21:34 +01:00
parent 0eec205912
commit 3cdd4b8842

View File

@@ -288,9 +288,26 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
} }
fun handleClear() { fun handleClear() {
val lastDeletedValue = inputDisplayedFormula.last().toString()
var newValue = inputDisplayedFormula.dropLast(1) var newValue = inputDisplayedFormula.dropLast(1)
if (newValue == "") { if (newValue == "") {
newValue = "0" newValue = "0"
} else {
if (operations.contains(lastDeletedValue) || lastKey == EQUALS) {
lastOperation = ""
}
val lastValue = newValue.last().toString()
lastKey = when {
operations.contains(lastValue) -> {
CLEAR
}
lastValue == "." -> {
DECIMAL
}
else -> {
DIGIT
}
}
} }
newValue = newValue.trimEnd(',') newValue = newValue.trimEnd(',')