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

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(',')