fixing a crash at long pressing C, then long pressing minus

This commit is contained in:
Tibor Kaputa 2021-11-03 23:05:18 +01:00 committed by GitHub
parent 97b9e4ab2c
commit fb22d7ba31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -124,12 +124,15 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
} }
fun turnToNegative(): Boolean { fun turnToNegative(): Boolean {
// turn to negative only if there is a baseValue alone ( not 0 ) if (inputDisplayedFormula.isEmpty()) {
return false
}
if (!inputDisplayedFormula.trimStart('-').any { it.toString() in operations } && inputDisplayedFormula.replace(",", "").toDouble() != 0.0) { if (!inputDisplayedFormula.trimStart('-').any { it.toString() in operations } && inputDisplayedFormula.replace(",", "").toDouble() != 0.0) {
if (inputDisplayedFormula.first() == '-') { inputDisplayedFormula = if (inputDisplayedFormula.first() == '-') {
inputDisplayedFormula = inputDisplayedFormula.substring(1) inputDisplayedFormula.substring(1)
} else { } else {
inputDisplayedFormula = "-$inputDisplayedFormula" "-$inputDisplayedFormula"
} }
showNewResult(inputDisplayedFormula) showNewResult(inputDisplayedFormula)