Merge branch 'fix_data_lost_during_rotation' into dev-axel-saveInstanceState

Pull commits from 'fix_data' branch
This commit is contained in:
Axel Labarre 2023-02-08 15:22:33 +01:00
commit 6a0f3bd1bf
2 changed files with 11 additions and 2 deletions

View file

@ -34,6 +34,7 @@ class MainActivity : SimpleActivity(), Calculator {
//============================================================
private var savedRes: String = "999"
private var savedPreviousCalculation = ""
//============================================================
@ -51,10 +52,10 @@ class MainActivity : SimpleActivity(), Calculator {
if(savedInstanceState != null) {
Log.v("MainActivity", "LOG TEST");
savedRes = savedInstanceState?.getCharSequence("res", "123") as String
savedPreviousCalculation = savedInstanceState?.getCharSequence("savedPreviousCalculation", "") as String
}
Log.v("MainActivity", "LOG NO IF TEST");
calc = CalculatorImpl(this, applicationContext, savedRes)
calc = CalculatorImpl(this, applicationContext, savedRes, savedPreviousCalculation)
//============================================================
@ -264,6 +265,7 @@ class MainActivity : SimpleActivity(), Calculator {
override fun onSaveInstanceState(bundle: Bundle) {
super.onSaveInstanceState(bundle)
bundle.putString("res", calc.mResult)
bundle.putString("savedPreviousCalculation", calc.previousCalculation)
}
//============================================================

View file

@ -13,6 +13,7 @@ class CalculatorImpl(
private val context: Context,
//============================================================
var res: String,
savedLastOperation: String,
//============================================================
private var decimalSeparator: String = DOT,
private var groupingSeparator: String = COMMA
@ -22,6 +23,7 @@ class CalculatorImpl(
//============================================================
// Trying Fix it
public var mResult = res
public var previousCalculation = savedLastOperation
//============================================================
private var baseValue = 0.0
@ -41,6 +43,7 @@ class CalculatorImpl(
//============================================================
//showNewResult("0")
showNewResult(mResult)
showNewFormula(previousCalculation)
//============================================================
}
@ -295,6 +298,10 @@ class CalculatorImpl(
)
showNewFormula(newFormula)
//============================================================
previousCalculation = newFormula
//============================================================
inputDisplayedFormula = result.format()
baseValue = result
} catch (e: Exception) {