From ab5c0a3522d0f45db9dc005d7378e00a6ef552a0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Fri, 6 Nov 2020 22:35:13 +0100 Subject: [PATCH] simplifying Clear, not sure why was it so complicated --- .../calculator/helpers/CalculatorImpl.kt | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt index 2b1eaba8..43a7f5f6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt @@ -167,29 +167,14 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) { } fun handleClear() { - val oldValue = displayedNumber - var newValue = "0" - val len = oldValue.length - var minLen = 1 - if (oldValue.contains("-")) - minLen++ - - if (len > minLen) { - newValue = oldValue.substring(0, len - 1) + var newValue = inputDisplayedFormula.dropLast(1) + if (newValue.isEmpty()) { + newValue = "0" } - newValue = newValue.replace("\\.$".toRegex(), "") - if (!newValue.contains('+') && - !newValue.contains('-') && - !newValue.contains('*') && - !newValue.contains('/') && - !newValue.contains('%') && - !newValue.contains('^') && - !newValue.contains('√')) { - newValue = formatString(newValue) - } + newValue = newValue.trimEnd(',') + inputDisplayedFormula = newValue showNewResult(newValue) - inputDisplayedFormula = if (newValue != "0") newValue else "" } fun handleReset() {