more cleanup

This commit is contained in:
tibbi
2020-11-06 22:51:40 +01:00
parent ab5c0a3522
commit 0dbbf6ef2d

View File

@@ -13,7 +13,6 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
private var baseValue = 0.0 private var baseValue = 0.0
private var secondValue = 0.0 private var secondValue = 0.0
private var inputDisplayedFormula = "0" private var inputDisplayedFormula = "0"
private var displayedNumber = ""
private var lastKey = "" private var lastKey = ""
private var lastOperation = "" private var lastOperation = ""
private val operations = listOf("+", "-", "*", "/", "^", "%", "") private val operations = listOf("+", "-", "*", "/", "^", "%", "")
@@ -37,15 +36,6 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
showNewResult(inputDisplayedFormula) showNewResult(inputDisplayedFormula)
} }
private fun formatString(str: String): String {
if (str.contains(".")) {
return str
}
val doubleValue = Formatter.stringToDouble(str)
return doubleValue.format()
}
private fun updateResult(value: Double) { private fun updateResult(value: Double) {
showNewResult(value.format()) showNewResult(value.format())
baseValue = value baseValue = value
@@ -53,19 +43,15 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
private fun showNewResult(value: String) { private fun showNewResult(value: String) {
callback!!.showNewResult(value, context) callback!!.showNewResult(value, context)
displayedNumber = value
} }
private fun showNewFormula(value: String) { private fun showNewFormula(value: String) {
callback!!.showNewFormula(value, context) callback!!.showNewFormula(value, context)
} }
private fun getDisplayedNumberAsDouble() = Formatter.stringToDouble(displayedNumber)
private fun handleResult() { private fun handleResult() {
secondValue = getSecondValue() secondValue = getSecondValue()
calculateResult() calculateResult()
baseValue = getDisplayedNumberAsDouble()
showNewResult(inputDisplayedFormula) showNewResult(inputDisplayedFormula)
} }
@@ -187,7 +173,6 @@ 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
displayedNumber = ""
lastKey = "" lastKey = ""
lastOperation = "" lastOperation = ""
} }
@@ -202,11 +187,8 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
} }
secondValue = getSecondValue() secondValue = getSecondValue()
displayedNumber = secondValue.toString()
calculateResult() calculateResult()
lastKey = EQUALS lastKey = EQUALS
inputDisplayedFormula = displayedNumber
baseValue = getDisplayedNumberAsDouble()
} }
private fun getSecondValue(): Double { private fun getSecondValue(): Double {