Merge branch 'fix_data_lost_during_rotation' into dev-axel-saveInstanceState
This commit is contained in:
commit
ab5325c1a6
|
@ -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).
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -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>
|
|
@ -0,0 +1 @@
|
|||
* Added some UI, translation and stability improvements
|
|
@ -0,0 +1 @@
|
|||
Uma linda calculadora para calculos rápidos com uma interface de usuário suave
|
|
@ -0,0 +1 @@
|
|||
Calculadora Simples
|
Loading…
Reference in New Issue