From f821d0976b2fab0a13de984132bcd94668de0597 Mon Sep 17 00:00:00 2001 From: Axel Labarre Date: Sat, 18 Feb 2023 15:16:55 +0100 Subject: [PATCH 1/2] fix calc constructor --- .../com/simplemobiletools/calculator/activities/MainActivity.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 bb858d93..1d38636d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt @@ -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) //============================================================ From 6c4c47a1f0b93acb8f9f4d2d0404140ecedb44d6 Mon Sep 17 00:00:00 2001 From: Axel Labarre Date: Sat, 18 Feb 2023 18:49:34 +0100 Subject: [PATCH 2/2] get SecondValue with new method getSecondValueV2() --- .../calculator/activities/MainActivity.kt | 5 ++--- .../calculator/helpers/CalculatorImpl.kt | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 4 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 1d38636d..db0ded8a 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/MainActivity.kt @@ -77,7 +77,7 @@ class MainActivity : SimpleActivity(), Calculator { - calc = CalculatorImpl(this, applicationContext,decimalSeparator, groupingSeparator, savedRes, savedPreviousCalculation, savedLastKey, savedLastOperation, savedBaseValue, savedSecondValue, savedInputDisplayedFormula) + 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("savedLastOperation", calc.lastOperation) bundle.putDouble("savedBaseValue", calc.baseValue) - bundle.putDouble("savedSecondValue", calc.getSecondValue()) + bundle.putDouble("savedSecondValue", calc.getSecondValueV2()) bundle.putString("savedInputDisplayedFormula", calc.inputDisplayedFormula) - } //============================================================ } 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 eaa703f0..ba3f7710 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt @@ -24,12 +24,13 @@ class CalculatorImpl( aSecondValue: Double = 0.0, aInputDisplayedFormula: String = "0" + //============================================================ ) { private var callback: Calculator? = calculator //============================================================ - // Trying Fix it + // Trying Fix it` public var mResult = aRes public var previousCalculation = aSavedLastOperation public var lastKey = aLastKey @@ -227,7 +228,10 @@ class CalculatorImpl( public fun getSecondValue(): Double { val valueToCheck = inputDisplayedFormula.trimStart('-').removeGroupSeparator() + Log.v("VALUEToCheck GETSV :", valueToCheck) + var value = valueToCheck.substring(valueToCheck.indexOfAny(operations) + 1) + Log.v("VALUE GETSV :", value) if (value == "") { value = "0" } @@ -309,6 +313,8 @@ class CalculatorImpl( //mResult = result.format() Log.v("CalculResult", result.format()) + Log.v("BASEVALUE CR :", baseValue.toString()) + Log.v("SECONDVALUE CR :", secondValue.toString()) //============================================================ showNewResult(result.format()) @@ -366,6 +372,8 @@ class CalculatorImpl( private fun showNewFormula(value: String) { //============================================================ previousCalculation = value; + Log.v("BASEVALUE SHOWNF :", baseValue.toString()) + Log.v("SECONDVALUE SHOWNF:", secondValue.toString()) //============================================================ callback!!.showNewFormula(value, context) } @@ -466,4 +474,10 @@ class CalculatorImpl( private fun Double.format() = formatter.doubleToString(this) private fun String.removeGroupSeparator() = formatter.removeGroupingSeparator(this) + + public fun getSecondValueV2() : Double + { + return this.secondValue + } + }