mirror of
https://github.com/SimpleMobileTools/Simple-Calculator.git
synced 2025-02-21 05:50:59 +01:00
Handle clear button short taps
This commit is contained in:
parent
128986bf7c
commit
89f8502a13
@ -42,7 +42,11 @@ class UnitConverterActivity : SimpleActivity() {
|
|||||||
this.converter = converter
|
this.converter = converter
|
||||||
|
|
||||||
binding.viewUnitConverter.btnClear.setVibratingOnClickListener {
|
binding.viewUnitConverter.btnClear.setVibratingOnClickListener {
|
||||||
|
binding.viewUnitConverter.viewConverter.root.deleteCharacter()
|
||||||
|
}
|
||||||
|
binding.viewUnitConverter.btnClear.setOnLongClickListener {
|
||||||
binding.viewUnitConverter.viewConverter.root.clear()
|
binding.viewUnitConverter.viewConverter.root.clear()
|
||||||
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
getButtonIds().forEach {
|
getButtonIds().forEach {
|
||||||
|
@ -9,7 +9,6 @@ import android.graphics.drawable.RippleDrawable
|
|||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import android.widget.TextView
|
|
||||||
import androidx.core.content.res.ResourcesCompat
|
import androidx.core.content.res.ResourcesCompat
|
||||||
import androidx.core.widget.TextViewCompat
|
import androidx.core.widget.TextViewCompat
|
||||||
import com.simplemobiletools.calculator.R
|
import com.simplemobiletools.calculator.R
|
||||||
@ -105,6 +104,19 @@ class ConverterView @JvmOverloads constructor(
|
|||||||
binding.bottomUnitText.text = "0"
|
binding.bottomUnitText.text = "0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun deleteCharacter() {
|
||||||
|
var newValue = binding.topUnitText.text.dropLast(1)
|
||||||
|
newValue = newValue.trimEnd(groupingSeparator.single())
|
||||||
|
if (newValue == "") {
|
||||||
|
newValue = "0"
|
||||||
|
}
|
||||||
|
|
||||||
|
val value = formatter.removeGroupingSeparator(newValue.toString()).toDouble()
|
||||||
|
binding.topUnitText.text = formatter.doubleToString(value)
|
||||||
|
|
||||||
|
updateBottomValue()
|
||||||
|
}
|
||||||
|
|
||||||
fun numpadClicked(id: Int) {
|
fun numpadClicked(id: Int) {
|
||||||
when (id) {
|
when (id) {
|
||||||
R.id.btn_decimal -> decimalClicked()
|
R.id.btn_decimal -> decimalClicked()
|
||||||
@ -185,10 +197,6 @@ class ConverterView @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun TextView.getValue(): Double {
|
|
||||||
return formatter.removeGroupingSeparator(text.toString()).toDouble()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun <T> KMutableProperty0<T>.swapWith(other: KMutableProperty0<T>) {
|
private fun <T> KMutableProperty0<T>.swapWith(other: KMutableProperty0<T>) {
|
||||||
this.get().also {
|
this.get().also {
|
||||||
this.set(other.get())
|
this.set(other.get())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user