Merge branch 'dev-axel-saveInstanceState' into fix_data_lost_during_rotation

This commit is contained in:
Axel Labarre 2023-02-18 18:50:08 +01:00
commit cc5aa18b47
2 changed files with 17 additions and 4 deletions

View File

@ -77,7 +77,7 @@ class MainActivity : SimpleActivity(), Calculator {
calc = CalculatorImpl(this, applicationContext,decimalSeparator, groupingSeparator, savedRes, savedPreviousCalculation, savedLastKey, savedLastOperation, savedBaseValue, savedSecondValue) calc = CalculatorImpl(this, applicationContext,decimalSeparator, groupingSeparator, savedRes, savedPreviousCalculation, savedLastKey, savedLastOperation, savedBaseValue, savedSecondValue, savedInputDisplayedFormula)
//============================================================ //============================================================
@ -291,9 +291,8 @@ class MainActivity : SimpleActivity(), Calculator {
bundle.putString("savedLastKey", calc.lastKey) bundle.putString("savedLastKey", calc.lastKey)
bundle.putString("savedLastOperation", calc.lastOperation) bundle.putString("savedLastOperation", calc.lastOperation)
bundle.putDouble("savedBaseValue", calc.baseValue) bundle.putDouble("savedBaseValue", calc.baseValue)
bundle.putDouble("savedSecondValue", calc.getSecondValue()) bundle.putDouble("savedSecondValue", calc.getSecondValueV2())
bundle.putString("savedInputDisplayedFormula", calc.inputDisplayedFormula) bundle.putString("savedInputDisplayedFormula", calc.inputDisplayedFormula)
}
//============================================================ //============================================================
} }

View File

@ -24,12 +24,13 @@ class CalculatorImpl(
aSecondValue: Double = 0.0, aSecondValue: Double = 0.0,
aInputDisplayedFormula: String = "0" aInputDisplayedFormula: String = "0"
//============================================================ //============================================================
) { ) {
private var callback: Calculator? = calculator private var callback: Calculator? = calculator
//============================================================ //============================================================
// Trying Fix it // Trying Fix it`
public var mResult = aRes public var mResult = aRes
public var previousCalculation = aSavedLastOperation public var previousCalculation = aSavedLastOperation
public var lastKey = aLastKey public var lastKey = aLastKey
@ -227,7 +228,10 @@ class CalculatorImpl(
public fun getSecondValue(): Double { public fun getSecondValue(): Double {
val valueToCheck = inputDisplayedFormula.trimStart('-').removeGroupSeparator() val valueToCheck = inputDisplayedFormula.trimStart('-').removeGroupSeparator()
Log.v("VALUEToCheck GETSV :", valueToCheck)
var value = valueToCheck.substring(valueToCheck.indexOfAny(operations) + 1) var value = valueToCheck.substring(valueToCheck.indexOfAny(operations) + 1)
Log.v("VALUE GETSV :", value)
if (value == "") { if (value == "") {
value = "0" value = "0"
} }
@ -309,6 +313,8 @@ class CalculatorImpl(
//mResult = result.format() //mResult = result.format()
Log.v("CalculResult", result.format()) Log.v("CalculResult", result.format())
Log.v("BASEVALUE CR :", baseValue.toString())
Log.v("SECONDVALUE CR :", secondValue.toString())
//============================================================ //============================================================
showNewResult(result.format()) showNewResult(result.format())
@ -366,6 +372,8 @@ class CalculatorImpl(
private fun showNewFormula(value: String) { private fun showNewFormula(value: String) {
//============================================================ //============================================================
previousCalculation = value; previousCalculation = value;
Log.v("BASEVALUE SHOWNF :", baseValue.toString())
Log.v("SECONDVALUE SHOWNF:", secondValue.toString())
//============================================================ //============================================================
callback!!.showNewFormula(value, context) callback!!.showNewFormula(value, context)
} }
@ -466,4 +474,10 @@ class CalculatorImpl(
private fun Double.format() = formatter.doubleToString(this) private fun Double.format() = formatter.doubleToString(this)
private fun String.removeGroupSeparator() = formatter.removeGroupingSeparator(this) private fun String.removeGroupSeparator() = formatter.removeGroupingSeparator(this)
public fun getSecondValueV2() : Double
{
return this.secondValue
}
} }