mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-02-15 11:00:49 +01:00
Show Toast message instead of printing division by zero error
This commit is contained in:
parent
f13b72d04b
commit
95feb32d0f
@ -2,6 +2,7 @@ package com.simplemobiletools.calculator.helpers
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.widget.Toast
|
||||||
import com.simplemobiletools.calculator.R
|
import com.simplemobiletools.calculator.R
|
||||||
import com.simplemobiletools.calculator.operation.OperationFactory
|
import com.simplemobiletools.calculator.operation.OperationFactory
|
||||||
|
|
||||||
@ -57,19 +58,21 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
val sign = getSign(lastOperation)
|
val sign = getSign(lastOperation)
|
||||||
|
|
||||||
when {
|
when {
|
||||||
baseValue == 0.0 && secondValue == 0.0 && sign == "/" -> {
|
sign == "√" -> {
|
||||||
setFormula(context.getString(R.string.formula_divide_by_zero_error))
|
setFormula(sign + first)
|
||||||
|
}
|
||||||
|
sign == "!" -> {
|
||||||
|
setFormula(first + sign)
|
||||||
|
}
|
||||||
|
sign.isNotEmpty() -> {
|
||||||
|
if (secondValue == 0.0 && sign == "/") {
|
||||||
|
Toast.makeText(
|
||||||
|
context,
|
||||||
|
context.getString(R.string.formula_divide_by_zero_error),
|
||||||
|
Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
sign == "√" -> setFormula(sign + first)
|
setFormula(first + sign + second)
|
||||||
|
|
||||||
sign == "!" -> setFormula(first + sign)
|
|
||||||
|
|
||||||
else -> {
|
|
||||||
if (sign.isNotEmpty()) {
|
|
||||||
val formula = first + sign + second
|
|
||||||
setFormula(formula)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user