mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-04-27 16:28:42 +02:00
bit more cleanup
This commit is contained in:
parent
3e5c4cc616
commit
de1bf98bcf
@ -9,13 +9,12 @@ import net.objecthunter.exp4j.ExpressionBuilder
|
|||||||
|
|
||||||
class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||||
private var displayedNumber: String? = null
|
private var displayedNumber: String? = null
|
||||||
private var lastKey: String? = null
|
|
||||||
private var inputDisplayedFormula = "0"
|
private var inputDisplayedFormula = "0"
|
||||||
private var callback: Calculator? = calculator
|
private var callback: Calculator? = calculator
|
||||||
|
|
||||||
private var isFirstOperation = false
|
|
||||||
private var baseValue = 0.0
|
private var baseValue = 0.0
|
||||||
private var secondValue = 0.0
|
private var secondValue = 0.0
|
||||||
|
private var lastKey = ""
|
||||||
private var lastOperation = ""
|
private var lastOperation = ""
|
||||||
private val operations = listOf("+", "-", "*", "/", "^", "%", "√")
|
private val operations = listOf("+", "-", "*", "/", "^", "%", "√")
|
||||||
private val operationsRegex = "[-+*/^%√]".toPattern()
|
private val operationsRegex = "[-+*/^%√]".toPattern()
|
||||||
@ -28,9 +27,9 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
|||||||
private fun resetValues() {
|
private fun resetValues() {
|
||||||
baseValue = 0.0
|
baseValue = 0.0
|
||||||
secondValue = 0.0
|
secondValue = 0.0
|
||||||
lastOperation = ""
|
|
||||||
displayedNumber = ""
|
displayedNumber = ""
|
||||||
lastKey = ""
|
lastKey = ""
|
||||||
|
lastOperation = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setValue(value: String) {
|
fun setValue(value: String) {
|
||||||
@ -38,22 +37,6 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
|||||||
displayedNumber = value
|
displayedNumber = value
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateFormula() {
|
|
||||||
var first = baseValue.format()
|
|
||||||
val second = secondValue.format()
|
|
||||||
val sign = getSign(lastOperation)
|
|
||||||
|
|
||||||
if (sign.isNotEmpty()) {
|
|
||||||
if (secondValue == 0.0 && sign == "/") {
|
|
||||||
context.toast(context.getString(R.string.formula_divide_by_zero_error))
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sign == "√" && first == "0") {
|
|
||||||
first = ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun addDigit(number: Int) {
|
private fun addDigit(number: Int) {
|
||||||
if (inputDisplayedFormula == "0" && number.toString().areDigitsOnly()) {
|
if (inputDisplayedFormula == "0" && number.toString().areDigitsOnly()) {
|
||||||
inputDisplayedFormula = ""
|
inputDisplayedFormula = ""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user