use constants to avoid issues caused by typos

This commit is contained in:
Axel Labarre 2023-03-25 22:43:06 +01:00
parent 95b7c6b995
commit 74071bee5a
3 changed files with 11 additions and 10 deletions

View File

@ -48,7 +48,7 @@ class MainActivity : SimpleActivity(), Calculator {
setupMaterialScrollListener(main_nested_scrollview, main_toolbar)
if (savedInstanceState != null) {
saveCalculatorState = savedInstanceState.getCharSequence("calculatorState") as String
saveCalculatorState = savedInstanceState.getCharSequence(CALCULATOR_STATE) as String
}
calc = CalculatorImpl(this, applicationContext, decimalSeparator, groupingSeparator, saveCalculatorState)
@ -256,7 +256,6 @@ class MainActivity : SimpleActivity(), Calculator {
override fun onSaveInstanceState(bundle: Bundle) {
super.onSaveInstanceState(bundle)
bundle.putString("calculatorState", calc.getCalculatorStateJson().toString())
bundle.putString(CALCULATOR_STATE, calc.getCalculatorStateJson().toString())
}
}

View File

@ -448,12 +448,12 @@ class CalculatorImpl(
private fun setFromSaveInstanceState(json: String) {
val jsonObject = JSONTokener(json).nextValue() as JSONObject
currentResult = jsonObject.getString("res")
previousCalculation = jsonObject.getString("previousCalculation")
baseValue = jsonObject.getDouble("baseValue")
secondValue = jsonObject.getDouble("secondValue")
inputDisplayedFormula = jsonObject.getString("inputDisplayedFormula")
lastKey = jsonObject.getString("lastKey")
lastOperation = jsonObject.getString("lastOperation")
currentResult = jsonObject.getString(RES)
previousCalculation = jsonObject.getString(PREVIOUS_CALCULATION)
baseValue = jsonObject.getDouble(BASE_VALUE)
secondValue = jsonObject.getDouble(SECOND_VALUE)
inputDisplayedFormula = jsonObject.getString(INPUT_DISPLAYED_FORMULA)
lastKey = jsonObject.getString(LAST_KEY)
lastOperation = jsonObject.getString(LAST_OPERATION)
}
}

View File

@ -38,3 +38,5 @@ const val LAST_OPERATION = "lastOperation"
const val BASE_VALUE = "baseValue"
const val SECOND_VALUE = "secondValue"
const val INPUT_DISPLAYED_FORMULA = "inputDisplayedFormula"
const val CALCULATOR_STATE = "calculatorState"