mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-06-05 21:49:13 +02:00
make inputDisplayedFormulat non nullable
This commit is contained in:
@@ -10,7 +10,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
var displayedNumber: String? = null
|
var displayedNumber: String? = null
|
||||||
var displayedFormula: String? = null
|
var displayedFormula: String? = null
|
||||||
var lastKey: String? = null
|
var lastKey: String? = null
|
||||||
private var inputDisplayedFormula: String? = null
|
private var inputDisplayedFormula = "0"
|
||||||
private var lastOperation: String? = null
|
private var lastOperation: String? = null
|
||||||
private var callback: Calculator? = calculator
|
private var callback: Calculator? = calculator
|
||||||
|
|
||||||
@@ -25,7 +25,6 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
resetValues()
|
resetValues()
|
||||||
setValue("0")
|
setValue("0")
|
||||||
setFormula("")
|
setFormula("")
|
||||||
inputDisplayedFormula = "0"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resetValueIfNeeded() {
|
private fun resetValueIfNeeded() {
|
||||||
@@ -76,7 +75,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
|
|
||||||
fun addDigit(number: Int) {
|
fun addDigit(number: Int) {
|
||||||
inputDisplayedFormula += number
|
inputDisplayedFormula += number
|
||||||
setValue(inputDisplayedFormula.toString())
|
setValue(inputDisplayedFormula)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun formatString(str: String): String {
|
private fun formatString(str: String): String {
|
||||||
@@ -106,7 +105,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
secondValue = getDisplayedNumberAsDouble()
|
secondValue = getDisplayedNumberAsDouble()
|
||||||
calculateResult()
|
calculateResult()
|
||||||
baseValue = getDisplayedNumberAsDouble()
|
baseValue = getDisplayedNumberAsDouble()
|
||||||
setValue(inputDisplayedFormula!!)
|
setValue(inputDisplayedFormula)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun handleRoot() {
|
private fun handleRoot() {
|
||||||
@@ -126,7 +125,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
if (operation != null) {
|
if (operation != null) {
|
||||||
try {
|
try {
|
||||||
updateResult(operation.getResult())
|
updateResult(operation.getResult())
|
||||||
inputDisplayedFormula = displayedNumber
|
inputDisplayedFormula = displayedNumber ?: ""
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
context.toast(R.string.unknown_error_occurred)
|
context.toast(R.string.unknown_error_occurred)
|
||||||
}
|
}
|
||||||
@@ -137,17 +136,18 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
|
|
||||||
fun handleOperation(operation: String) {
|
fun handleOperation(operation: String) {
|
||||||
if (operation != ROOT) {
|
if (operation != ROOT) {
|
||||||
if (inputDisplayedFormula!!.last() == '+' || inputDisplayedFormula!!.last() == '-' || inputDisplayedFormula!!.last() == '*' || inputDisplayedFormula!!.last() == '/' || inputDisplayedFormula!!.last() == '^' || inputDisplayedFormula!!.last() == '%') {
|
if (inputDisplayedFormula.last() == '+' || inputDisplayedFormula.last() == '-' || inputDisplayedFormula.last() == '*' || inputDisplayedFormula.last() == '/' || inputDisplayedFormula.last() == '^' || inputDisplayedFormula.last() == '%') {
|
||||||
inputDisplayedFormula = inputDisplayedFormula!!.dropLast(1)
|
inputDisplayedFormula = inputDisplayedFormula.dropLast(1)
|
||||||
inputDisplayedFormula += getSign(operation)
|
inputDisplayedFormula += getSign(operation)
|
||||||
} else {
|
} 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)
|
inputDisplayedFormula += getSign(operation)
|
||||||
} else {
|
} else {
|
||||||
moreOperationsInRaw = true
|
moreOperationsInRaw = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastKey == DIGIT && !lastOperation.isNullOrEmpty() && operation == PERCENT) {
|
if (lastKey == DIGIT && !lastOperation.isNullOrEmpty() && operation == PERCENT) {
|
||||||
val tempOp = lastOperation
|
val tempOp = lastOperation
|
||||||
handlePercent()
|
handlePercent()
|
||||||
@@ -160,7 +160,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
resetValue = true
|
resetValue = true
|
||||||
lastKey = operation
|
lastKey = operation
|
||||||
lastOperation = operation
|
lastOperation = operation
|
||||||
setValue(inputDisplayedFormula!!)
|
setValue(inputDisplayedFormula)
|
||||||
|
|
||||||
if (operation == ROOT) {
|
if (operation == ROOT) {
|
||||||
handleRoot()
|
handleRoot()
|
||||||
@@ -228,7 +228,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
secondValue = getDisplayedNumberAsDouble()
|
secondValue = getDisplayedNumberAsDouble()
|
||||||
calculateResult()
|
calculateResult()
|
||||||
lastKey = EQUALS
|
lastKey = EQUALS
|
||||||
inputDisplayedFormula = displayedNumber
|
inputDisplayedFormula = displayedNumber ?: ""
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun decimalClicked() {
|
private fun decimalClicked() {
|
||||||
@@ -245,7 +245,7 @@ class CalculatorImpl(calculator: Calculator, val context: Context) {
|
|||||||
inputDisplayedFormula += "."
|
inputDisplayedFormula += "."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setValue(inputDisplayedFormula!!)
|
setValue(inputDisplayedFormula)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun zeroClicked() {
|
private fun zeroClicked() {
|
||||||
|
Reference in New Issue
Block a user