update CalculatorImpl.kt

This commit is contained in:
Axel Labarre 2023-02-22 21:54:17 +01:00
parent d0cac4ce7f
commit 593649db7b
6 changed files with 72 additions and 37 deletions

8
CONTRIBUTING 2.md Normal file
View File

@ -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).

View File

@ -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")
}
}

View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">ⵜⴰⵙⵎⵙⵙⵉⴹⵏⵜ ⵜⴰⴼⵔⴰⵔⵜ</string>
<string name="app_launcher_name">ⵜⴰⵙⵎⵙⵙⵉⴹⵏⵜ</string>
<string name="scientific_calculator">ⵜⴰⵙⵎⵙⵙⵉⴹⵏⵜ ⵜⴰⵎⴰⵙⵙⴰⵏⵜ</string>
<!-- Calculator field -->
<string name="formula_divide_by_zero_error">ⵜⴰⵣⴳⵍⵜ: ⴰⴱⵟⵟⵓ ⵅⴼ ⵓⵎⵢⴰ</string>
<!-- History -->
<string name="history">ⴰⵎⵣⵔⵓⵢ</string>
<string name="history_empty">ⴰⵎⵣⵔⵓⵢ ⵢⵓⵔⴰ</string>
<string name="clear_history">ⴽⴽⵙ</string>
<string name="history_cleared">ⵉⵜⵜⵡⴰⴽⴽⵙ ⵓⵎⵣⵔⵓⵢ</string>
<!-- Settings -->
<string name="vibrate_on_button_press">ⴰⵔⵎⵉⵎⵎⵉ ⴳ ⵡⴰⴱⴱⴰⵥ ⵅⴼ ⵜⴳⵎⵎⵓⵜⵉⵏ</string>
<string name="use_comma_as_decimal_mark">ⵙⵎⵔⵙ ⵜⵉⵙⴽⵔⵜ ⴷ ⵜⴰⵎⴰⵜⴰⵔⵜ ⵜⴰⵎⵔⴰⵡⴰⵏⵜ</string>
<!-- FAQ -->
<string name="faq_1_title">ⵎⴰⵎⴽ ⵜⵙⵡⵓⵔⵓⵢ ⵜⴳⵎⵎⵓⵜ C (ⴽⴽⵙ)\?</string>
<string name="faq_1_text">ⴰⴱⴱⴰⵥ ⵅⴼ ⵓⵢⵏⵏⴰ ⴰⴷ ⵉⴽⴽⵙ ⵢⴰⵏ ⵓⵙⴽⴽⵉⵍ ⴳ ⵢⴰⵏ ⵓⵣⵎⵣ. ⵎⵛ ⵉⵍⵍⴰ ⵡⴰⴱⴱⴰⵥ ⴰⵙⵓⵍⴰⵏ ⵔⴰⴷ ⵜⵜⵓⵙⵏⴼⵍⵏ ⵎⴰⵕⵕⴰ ⵉⴳⵔⴰⵏ ⴳ ⵢⴰⵏ ⵓⵣⵎⵣ.</string>
</resources>

View File

@ -0,0 +1 @@
* Added some UI, translation and stability improvements

View File

@ -0,0 +1 @@
Uma linda calculadora para calculos rápidos com uma interface de usuário suave

View File

@ -0,0 +1 @@
Calculadora Simples