From 3cdd4b884204828d7d5bb1c652da121f13064aba Mon Sep 17 00:00:00 2001 From: Agnieszka C <85929121+Aga-C@users.noreply.github.com> Date: Sun, 16 Jan 2022 15:21:34 +0100 Subject: [PATCH] Fixed inserting zero after using clear --- .../calculator/helpers/CalculatorImpl.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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 c2606856..10ab86f6 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt @@ -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(',')