mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-02-02 08:56:51 +01:00
bit more cleanup
This commit is contained in:
parent
de1bf98bcf
commit
606fad63ef
@ -8,19 +8,18 @@ import com.simplemobiletools.commons.extensions.toast
|
||||
import net.objecthunter.exp4j.ExpressionBuilder
|
||||
|
||||
class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||
private var displayedNumber: String? = null
|
||||
private var inputDisplayedFormula = "0"
|
||||
private var callback: Calculator? = calculator
|
||||
|
||||
private var baseValue = 0.0
|
||||
private var secondValue = 0.0
|
||||
private var inputDisplayedFormula = "0"
|
||||
private var displayedNumber = ""
|
||||
private var lastKey = ""
|
||||
private var lastOperation = ""
|
||||
private val operations = listOf("+", "-", "*", "/", "^", "%", "√")
|
||||
private val operationsRegex = "[-+*/^%√]".toPattern()
|
||||
|
||||
init {
|
||||
resetValues()
|
||||
setValue("0")
|
||||
}
|
||||
|
||||
@ -65,7 +64,7 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||
baseValue = value
|
||||
}
|
||||
|
||||
private fun getDisplayedNumberAsDouble() = Formatter.stringToDouble(displayedNumber!!)
|
||||
private fun getDisplayedNumberAsDouble() = Formatter.stringToDouble(displayedNumber)
|
||||
|
||||
private fun handleResult() {
|
||||
secondValue = getSecondValue()
|
||||
@ -172,12 +171,9 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||
}
|
||||
|
||||
fun handleClear() {
|
||||
if (displayedNumber.equals(NAN)) {
|
||||
handleReset()
|
||||
} else {
|
||||
val oldValue = displayedNumber
|
||||
var newValue = "0"
|
||||
val len = oldValue!!.length
|
||||
val len = oldValue.length
|
||||
var minLen = 1
|
||||
if (oldValue.contains("-"))
|
||||
minLen++
|
||||
@ -199,7 +195,6 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||
setValue(newValue)
|
||||
inputDisplayedFormula = if (newValue != "0") newValue else ""
|
||||
}
|
||||
}
|
||||
|
||||
fun handleReset() {
|
||||
resetValues()
|
||||
@ -221,7 +216,7 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||
displayedNumber = secondValue.toString()
|
||||
calculateResult()
|
||||
lastKey = EQUALS
|
||||
inputDisplayedFormula = displayedNumber ?: "0"
|
||||
inputDisplayedFormula = displayedNumber
|
||||
baseValue = getDisplayedNumberAsDouble()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user