Merge branch 'fix_data_lost_during_rotation' into dev-axel-saveInstanceState
Pull commits from 'fix_data' branch
This commit is contained in:
commit
6a0f3bd1bf
|
@ -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)
|
||||
}
|
||||
|
||||
//============================================================
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue