From 593649db7bb262d2911810616fb8e7eea7805137 Mon Sep 17 00:00:00 2001 From: Axel Labarre Date: Wed, 22 Feb 2023 21:54:17 +0100 Subject: [PATCH] update CalculatorImpl.kt --- CONTRIBUTING 2.md | 8 ++ .../calculator/helpers/CalculatorImpl.kt | 79 ++++++++++--------- app/src/main/res/values-zgh/strings 2.xml | 19 +++++ .../android/en-US/changelogs/59 2.txt | 1 + .../android/pt-BR/short_description 2.txt | 1 + fastlane/metadata/android/pt-BR/title 2.txt | 1 + 6 files changed, 72 insertions(+), 37 deletions(-) create mode 100644 CONTRIBUTING 2.md create mode 100644 app/src/main/res/values-zgh/strings 2.xml create mode 100644 fastlane/metadata/android/en-US/changelogs/59 2.txt create mode 100644 fastlane/metadata/android/pt-BR/short_description 2.txt create mode 100644 fastlane/metadata/android/pt-BR/title 2.txt diff --git a/CONTRIBUTING 2.md b/CONTRIBUTING 2.md new file mode 100644 index 00000000..0730468b --- /dev/null +++ b/CONTRIBUTING 2.md @@ -0,0 +1,8 @@ +### Reporting +Before you report something, read the reporting rules [here](https://github.com/SimpleMobileTools/General-Discussion#how-do-i-suggest-an-improvement-ask-a-question-or-report-an-issue) please. + +### Contributing as a developer +Some instructions about code style and everything that has to be done to increase the change of your code getting accepted can be found at the [General Discussion](https://github.com/SimpleMobileTools/General-Discussion#contribution-rules-for-developers) section. + +### Contributing as a non developer +In case you just want to for example improve a translation, you can find the way of doing it [here](https://github.com/SimpleMobileTools/General-Discussion#how-can-i-suggest-an-edit-to-a-file). 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 8623fd81..17e03448 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/helpers/CalculatorImpl.kt @@ -2,11 +2,14 @@ package com.simplemobiletools.calculator.helpers import android.content.Context import android.util.Log +import com.google.gson.JsonObject import com.simplemobiletools.calculator.R import com.simplemobiletools.calculator.models.History import com.simplemobiletools.commons.extensions.showErrorToast import com.simplemobiletools.commons.extensions.toast import net.objecthunter.exp4j.ExpressionBuilder +import org.json.JSONObject +import org.json.JSONTokener import java.math.BigDecimal class CalculatorImpl( @@ -14,47 +17,35 @@ class CalculatorImpl( private val context: Context, private var decimalSeparator: String = DOT, private var groupingSeparator: String = COMMA, - - //============================================================ - aRes: String = "123", - aSavedLastOperation: String = "", - aLastKey: String = "", - aLastOperation: String = "", - aBaseValue: Double = 0.0, - aSecondValue: Double = 0.0, - aInputDisplayedFormula: String = "0" + private var json: String = "" - //============================================================ ) { private var callback: Calculator? = calculator - //============================================================ - // Trying Fix it` - public var mResult = aRes - public var previousCalculation = aSavedLastOperation - public var lastKey = aLastKey - public var lastOperation = aLastOperation - public var baseValue = aBaseValue - private var secondValue = aSecondValue - public var inputDisplayedFormula = aInputDisplayedFormula //============================================================ - //private var baseValue = 0.0 - //private var secondValue = 0.0 - //private var inputDisplayedFormula = "0" - //private var lastKey = "" - //private var lastOperation = "" + //============================================================ + private var jsonObj = json + private var mResult = "0" + private var previousCalculation = "" + private var baseValue = 0.0 + private var secondValue = 0.0 + private var inputDisplayedFormula = "0" + private var lastKey = "" + private var lastOperation = "" private val operations = listOf("+", "-", "×", "÷", "^", "%", "√") private val operationsRegex = "[-+×÷^%√]".toPattern() private val numbersRegex = "[^0-9,.]".toRegex() - private val formatter = NumberFormatHelper( decimalSeparator = decimalSeparator, groupingSeparator = groupingSeparator ) init { //============================================================ + if(jsonObj != "") { + setFromSaveInstanceState(jsonObj) + } Log.v("BASEVALUE INIT :", baseValue.toString()) Log.v("SECONDVALUE INIT :", secondValue.toString()) //showNewResult("0") @@ -484,20 +475,34 @@ class CalculatorImpl( return this.secondValue } - //JSON - public fun getJson() : String - { - val jsonObject = buildJsonObject{ - put("res", mResult) - put("savedPreviousCalculation", previousCalculation) - put("savedLastKey", lastKey) - put("savedLastOperation", lastOperation) - put("savedBaseValue", baseValue) - put("savedSecondValue", secondValue) - put("savedInputDisplayedFormula", inputDisplayedFormula) - return jsonObject.toString() + //JSON + public fun getJson() : JSONObject { + + val jsonObj = JSONObject() + jsonObj.put("res",mResult) + jsonObj.put("previousCalculation", previousCalculation) + jsonObj.put("lastKey", lastKey) + jsonObj.put("lastOperation", lastOperation) + jsonObj.put("baseValue", baseValue) + jsonObj.put("secondValue", secondValue) + jsonObj.put("inputDisplayedFormula", inputDisplayedFormula) + + return jsonObj } + + public fun setFromSaveInstanceState( json: String ) + { + val jsonObject = JSONTokener(json).nextValue() as JSONObject + mResult = jsonObject.getString("res") + previousCalculation = jsonObject.getString("previousCalculation") + baseValue = jsonObject.getDouble("baseValue") + secondValue = jsonObject.getDouble("secondValue") + inputDisplayedFormula = jsonObject.getString("inputDisplayedFormula") + lastKey = jsonObject.getString("lastKey") + lastOperation = jsonObject.getString("lastOperation") } + + } diff --git a/app/src/main/res/values-zgh/strings 2.xml b/app/src/main/res/values-zgh/strings 2.xml new file mode 100644 index 00000000..e8a0fd2d --- /dev/null +++ b/app/src/main/res/values-zgh/strings 2.xml @@ -0,0 +1,19 @@ + + + ⵜⴰⵙⵎⵙⵙⵉⴹⵏⵜ ⵜⴰⴼⵔⴰⵔⵜ + ⵜⴰⵙⵎⵙⵙⵉⴹⵏⵜ + ⵜⴰⵙⵎⵙⵙⵉⴹⵏⵜ ⵜⴰⵎⴰⵙⵙⴰⵏⵜ + + ⵜⴰⵣⴳⵍⵜ: ⴰⴱⵟⵟⵓ ⵅⴼ ⵓⵎⵢⴰ + + ⴰⵎⵣⵔⵓⵢ + ⴰⵎⵣⵔⵓⵢ ⵢⵓⵔⴰ + ⴽⴽⵙ + ⵉⵜⵜⵡⴰⴽⴽⵙ ⵓⵎⵣⵔⵓⵢ + + ⴰⵔⵎⵉⵎⵎⵉ ⴳ ⵡⴰⴱⴱⴰⵥ ⵅⴼ ⵜⴳⵎⵎⵓⵜⵉⵏ + ⵙⵎⵔⵙ ⵜⵉⵙⴽⵔⵜ ⴷ ⵜⴰⵎⴰⵜⴰⵔⵜ ⵜⴰⵎⵔⴰⵡⴰⵏⵜ + + ⵎⴰⵎⴽ ⵜⵙⵡⵓⵔⵓⵢ ⵜⴳⵎⵎⵓⵜ C (ⴽⴽⵙ)\? + ⴰⴱⴱⴰⵥ ⵅⴼ ⵓⵢⵏⵏⴰ ⴰⴷ ⵉⴽⴽⵙ ⵢⴰⵏ ⵓⵙⴽⴽⵉⵍ ⴳ ⵢⴰⵏ ⵓⵣⵎⵣ. ⵎⵛ ⵉⵍⵍⴰ ⵡⴰⴱⴱⴰⵥ ⴰⵙⵓⵍⴰⵏ ⵔⴰⴷ ⵜⵜⵓⵙⵏⴼⵍⵏ ⵎⴰⵕⵕⴰ ⵉⴳⵔⴰⵏ ⴳ ⵢⴰⵏ ⵓⵣⵎⵣ. + diff --git a/fastlane/metadata/android/en-US/changelogs/59 2.txt b/fastlane/metadata/android/en-US/changelogs/59 2.txt new file mode 100644 index 00000000..17b882fd --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/59 2.txt @@ -0,0 +1 @@ + * Added some UI, translation and stability improvements diff --git a/fastlane/metadata/android/pt-BR/short_description 2.txt b/fastlane/metadata/android/pt-BR/short_description 2.txt new file mode 100644 index 00000000..c19d0cc9 --- /dev/null +++ b/fastlane/metadata/android/pt-BR/short_description 2.txt @@ -0,0 +1 @@ +Uma linda calculadora para calculos rápidos com uma interface de usuário suave diff --git a/fastlane/metadata/android/pt-BR/title 2.txt b/fastlane/metadata/android/pt-BR/title 2.txt new file mode 100644 index 00000000..43ef335b --- /dev/null +++ b/fastlane/metadata/android/pt-BR/title 2.txt @@ -0,0 +1 @@ +Calculadora Simples