add setFromSaveInstanceState method

This commit is contained in:
Axel Labarre 2023-02-22 16:58:08 +01:00
parent 709df3fa87
commit 064e0bdb3b
1 changed files with 24 additions and 30 deletions

View File

@ -33,13 +33,13 @@ class MainActivity : SimpleActivity(), Calculator {
//============================================================
private var savedRes: String = "0"
private var savedPreviousCalculation = ""
private var savedLastKey: String = ""
private var savedLastOperation: String = ""
private var savedBaseValue : Double= 0.0
private var savedSecondValue : Double = 0.0
private var savedInputDisplayedFormula : String = "0"
//private var savedRes: String = "0"
//private var savedPreviousCalculation = ""
//private var savedLastKey: String = ""
//private var savedLastOperation: String = ""
//private var savedBaseValue : Double= 0.0
//private var savedSecondValue : Double = 0.0
//private var savedInputDisplayedFormula : String = "0"
//============================================================
@ -60,28 +60,28 @@ class MainActivity : SimpleActivity(), Calculator {
if(savedInstanceState != null) {
Log.v("MainActivity", "LOG TEST");
savedRes = savedInstanceState?.getCharSequence("res") as String
savedPreviousCalculation = savedInstanceState?.getCharSequence("savedPreviousCalculation") as String
savedLastKey = savedInstanceState?.getCharSequence("savedLastKey") as String
savedLastOperation = savedInstanceState?.getCharSequence("savedLastOperation") as String
savedBaseValue = savedInstanceState.getDouble("savedBaseValue")
savedSecondValue = savedInstanceState.getDouble("savedSecondValue")
savedInputDisplayedFormula = savedInstanceState.getCharSequence("savedInputDisplayedFormula") as String
//savedRes = savedInstanceState?.getCharSequence("res") as String
//savedPreviousCalculation = savedInstanceState?.getCharSequence("savedPreviousCalculation") as String
//savedLastKey = savedInstanceState?.getCharSequence("savedLastKey") as String
//savedLastOperation = savedInstanceState?.getCharSequence("savedLastOperation") as String
//savedBaseValue = savedInstanceState.getDouble("savedBaseValue")
//savedSecondValue = savedInstanceState.getDouble("savedSecondValue")
//savedInputDisplayedFormula = savedInstanceState.getCharSequence("savedInputDisplayedFormula") as String
}
Log.v("SAVEDRES : ", savedRes)
Log.v("SAVEDPREVIOUS : ", savedPreviousCalculation)
Log.v("SAVEDLASTKEY : ", savedLastKey)
Log.v("SAVEDLASTOP : ", savedLastOperation)
Log.v("DECIMALSEP : ", decimalSeparator)
Log.v("GROUPINGSEP : ", groupingSeparator)
Log.v("BASEVALUE : ", savedBaseValue.toString())
Log.v("SECONDVALUE : ", savedSecondValue.toString())
//Log.v("SAVEDRES : ", savedRes)
//Log.v("SAVEDPREVIOUS : ", savedPreviousCalculation)
//Log.v("SAVEDLASTKEY : ", savedLastKey)
//Log.v("SAVEDLASTOP : ", savedLastOperation)
//Log.v("DECIMALSEP : ", decimalSeparator)
//Log.v("GROUPINGSEP : ", groupingSeparator)
//Log.v("BASEVALUE : ", savedBaseValue.toString())
//Log.v("SECONDVALUE : ", savedSecondValue.toString())
calc = CalculatorImpl(this, applicationContext,decimalSeparator, groupingSeparator, savedRes, savedPreviousCalculation, savedLastKey, savedLastOperation, savedBaseValue, savedSecondValue, savedInputDisplayedFormula)
calc = CalculatorImpl(this, applicationContext,decimalSeparator, groupingSeparator)
//============================================================
@ -290,13 +290,7 @@ class MainActivity : SimpleActivity(), Calculator {
// ****** ADD ONSAVEINSTANCESTATE FUNCTION ******
override fun onSaveInstanceState(bundle: Bundle) {
super.onSaveInstanceState(bundle)
bundle.putString("res", calc.mResult)
bundle.putString("savedPreviousCalculation", calc.previousCalculation)
bundle.putString("savedLastKey", calc.lastKey)
bundle.putString("savedLastOperation", calc.lastOperation)
bundle.putDouble("savedBaseValue", calc.baseValue)
bundle.putDouble("savedSecondValue", calc.getSecondValueV2())
bundle.putString("savedInputDisplayedFormula", calc.inputDisplayedFormula)
}
//============================================================
}