make inputDisplayedFormulat non nullable

This commit is contained in:
tibbi 2020-11-05 21:41:22 +01:00
parent cffa735c2a
commit 8b7c26002c

View file

@ -10,7 +10,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
var displayedNumber: String? = null
var displayedFormula: String? = null
var lastKey: String? = null
private var inputDisplayedFormula: String? = null
private var inputDisplayedFormula = "0"
private var lastOperation: String? = null
private var callback: Calculator? = calculator
@ -25,7 +25,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
resetValues()
setValue("0")
setFormula("")
inputDisplayedFormula = "0"
}
private fun resetValueIfNeeded() {
@ -76,7 +75,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
fun addDigit(number: Int) {
inputDisplayedFormula += number
setValue(inputDisplayedFormula.toString())
setValue(inputDisplayedFormula)
}
private fun formatString(str: String): String {
@ -106,7 +105,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
secondValue = getDisplayedNumberAsDouble()
calculateResult()
baseValue = getDisplayedNumberAsDouble()
setValue(inputDisplayedFormula!!)
setValue(inputDisplayedFormula)
}
private fun handleRoot() {
@ -126,7 +125,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
if (operation != null) {
try {
updateResult(operation.getResult())
inputDisplayedFormula = displayedNumber
inputDisplayedFormula = displayedNumber ?: ""
} catch (e: Exception) {
context.toast(R.string.unknown_error_occurred)
}
@ -137,17 +136,18 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
fun handleOperation(operation: String) {
if (operation != ROOT) {
if (inputDisplayedFormula!!.last() == '+' || inputDisplayedFormula!!.last() == '-' || inputDisplayedFormula!!.last() == '*' || inputDisplayedFormula!!.last() == '/' || inputDisplayedFormula!!.last() == '^' || inputDisplayedFormula!!.last() == '%') {
inputDisplayedFormula = inputDisplayedFormula!!.dropLast(1)
if (inputDisplayedFormula.last() == '+' || inputDisplayedFormula.last() == '-' || inputDisplayedFormula.last() == '*' || inputDisplayedFormula.last() == '/' || inputDisplayedFormula.last() == '^' || inputDisplayedFormula.last() == '%') {
inputDisplayedFormula = inputDisplayedFormula.dropLast(1)
inputDisplayedFormula += getSign(operation)
} else {
if (!inputDisplayedFormula!!.contains('+') && !inputDisplayedFormula!!.contains('-') && !inputDisplayedFormula!!.contains('*') && !inputDisplayedFormula!!.contains('/') && !inputDisplayedFormula!!.contains('^') && !inputDisplayedFormula!!.contains('%')) {
if (!inputDisplayedFormula.contains('+') && !inputDisplayedFormula.contains('-') && !inputDisplayedFormula.contains('*') && !inputDisplayedFormula.contains('/') && !inputDisplayedFormula.contains('^') && !inputDisplayedFormula.contains('%')) {
inputDisplayedFormula += getSign(operation)
} else {
moreOperationsInRaw = true
}
}
}
if (lastKey == DIGIT && !lastOperation.isNullOrEmpty() && operation == PERCENT) {
val tempOp = lastOperation
handlePercent()
@ -160,7 +160,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
resetValue = true
lastKey = operation
lastOperation = operation
setValue(inputDisplayedFormula!!)
setValue(inputDisplayedFormula)
if (operation == ROOT) {
handleRoot()
@ -228,7 +228,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
secondValue = getDisplayedNumberAsDouble()
calculateResult()
lastKey = EQUALS
inputDisplayedFormula = displayedNumber
inputDisplayedFormula = displayedNumber ?: ""
}
private fun decimalClicked() {
@ -245,7 +245,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
inputDisplayedFormula += "."
}
}
setValue(inputDisplayedFormula!!)
setValue(inputDisplayedFormula)
}
private fun zeroClicked() {