simplifying the zero division check a bit

This commit is contained in:
Tibor Kaputa
2020-05-19 14:38:54 +02:00
committed by GitHub
parent b430e6e7bf
commit 11933ce2e1

View File

@@ -58,18 +58,11 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
val sign = getSign(lastOperation)
when {
sign == "" -> {
setFormula(sign + first)
}
sign == "!" -> {
setFormula(first + sign)
}
sign == "" -> 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()
context.toast(context.getString(R.string.formula_divide_by_zero_error))
}
setFormula(first + sign + second)