Merge pull request #2 from ochagovdanil/feature_divide_by_zero_message

Show Toast message instead of printing division by zero error
This commit is contained in:
Danil Ochagov 2020-05-19 15:06:01 +03:00 committed by GitHub
commit b430e6e7bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 11 deletions

View File

@ -2,6 +2,7 @@ package com.simplemobiletools.calculator.helpers
import android.content.Context
import android.util.Log
import android.widget.Toast
import com.simplemobiletools.calculator.R
import com.simplemobiletools.calculator.operation.OperationFactory
@ -57,19 +58,21 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
val sign = getSign(lastOperation)
when {
baseValue == 0.0 && secondValue == 0.0 && sign == "/" -> {
setFormula(context.getString(R.string.formula_divide_by_zero_error))
sign == "" -> {
setFormula(sign + first)
}
sign == "" -> setFormula(sign + first)
sign == "!" -> setFormula(first + sign)
else -> {
if (sign.isNotEmpty()) {
val formula = first + sign + second
setFormula(formula)
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()
}
setFormula(first + sign + second)
}
}
}