Merge pull request #241 from Aga-C/fix-clear-zero

Fixed inserting zero after using clear
This commit is contained in:
Tibor Kaputa 2022-01-18 15:35:21 +01:00 committed by GitHub
commit 9b9fb93f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -288,9 +288,26 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
}
fun handleClear() {
val lastDeletedValue = inputDisplayedFormula.last().toString()
var newValue = inputDisplayedFormula.dropLast(1)
if (newValue == "") {
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(',')