code reformat
This commit is contained in:
parent
a7cb74eb70
commit
97b9e4ab2c
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue