diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt index 3dde21c4..c363d6e4 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt @@ -43,7 +43,7 @@ class MainActivity : SimpleActivity(), Calculator { btn_root.setOnClickListener { calc.handleOperation(ROOT); checkHaptic(it) } btn_minus.setOnLongClickListener { - calc.turnToNegative(); + calc.turnToNegative() } btn_clear.setOnClickListener { calc.handleClear(); checkHaptic(it) } 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 aa972a59..fe0f4952 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt @@ -123,18 +123,19 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) { showNewResult(inputDisplayedFormula) } - fun turnToNegative() : Boolean{ + fun turnToNegative(): Boolean { // turn to negative only if there is a baseValue alone ( not 0 ) - if (!inputDisplayedFormula.trimStart('-').any { it.toString() in operations } && inputDisplayedFormula.replace(",", "").toDouble() != 0.0){ - - if(inputDisplayedFormula.first() == '-') { + if (!inputDisplayedFormula.trimStart('-').any { it.toString() in operations } && inputDisplayedFormula.replace(",", "").toDouble() != 0.0) { + if (inputDisplayedFormula.first() == '-') { inputDisplayedFormula = inputDisplayedFormula.substring(1) - }else{ + } else { inputDisplayedFormula = "-$inputDisplayedFormula" } + showNewResult(inputDisplayedFormula) return true } + return false }