simplifying Clear, not sure why was it so complicated
This commit is contained in:
parent
f527d8d954
commit
ab5c0a3522
|
@ -167,29 +167,14 @@ class CalculatorImpl(calculator: Calculator, private val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleClear() {
|
fun handleClear() {
|
||||||
val oldValue = displayedNumber
|
var newValue = inputDisplayedFormula.dropLast(1)
|
||||||
var newValue = "0"
|
if (newValue.isEmpty()) {
|
||||||
val len = oldValue.length
|
newValue = "0"
|
||||||
var minLen = 1
|
|
||||||
if (oldValue.contains("-"))
|
|
||||||
minLen++
|
|
||||||
|
|
||||||
if (len > minLen) {
|
|
||||||
newValue = oldValue.substring(0, len - 1)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
newValue = newValue.replace("\\.$".toRegex(), "")
|
newValue = newValue.trimEnd(',')
|
||||||
if (!newValue.contains('+') &&
|
inputDisplayedFormula = newValue
|
||||||
!newValue.contains('-') &&
|
|
||||||
!newValue.contains('*') &&
|
|
||||||
!newValue.contains('/') &&
|
|
||||||
!newValue.contains('%') &&
|
|
||||||
!newValue.contains('^') &&
|
|
||||||
!newValue.contains('√')) {
|
|
||||||
newValue = formatString(newValue)
|
|
||||||
}
|
|
||||||
showNewResult(newValue)
|
showNewResult(newValue)
|
||||||
inputDisplayedFormula = if (newValue != "0") newValue else ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun handleReset() {
|
fun handleReset() {
|
||||||
|
|
Loading…
Reference in New Issue