From 74071bee5aebff5c96678cad0de7ac8651058170 Mon Sep 17 00:00:00 2001 From: Axel Labarre Date: Sat, 25 Mar 2023 22:43:06 +0100 Subject: [PATCH] use constants to avoid issues caused by typos --- .../calculator/activities/MainActivity.kt | 5 ++--- .../calculator/helpers/CalculatorImpl.kt | 14 +++++++------- .../calculator/helpers/Constants.kt | 2 ++ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt index becb69f6..681a165e 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt @@ -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()) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt index 199d05f1..a9682275 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt @@ -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) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/Constants.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/Constants.kt index 71e79989..6519b925 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/Constants.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/Constants.kt @@ -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"