diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/UnitConverterActivity.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/UnitConverterActivity.kt index 61691e5..1039c7d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/activities/UnitConverterActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/activities/UnitConverterActivity.kt @@ -42,7 +42,11 @@ class UnitConverterActivity : SimpleActivity() { this.converter = converter binding.viewUnitConverter.btnClear.setVibratingOnClickListener { + binding.viewUnitConverter.viewConverter.root.deleteCharacter() + } + binding.viewUnitConverter.btnClear.setOnLongClickListener { binding.viewUnitConverter.viewConverter.root.clear() + true } getButtonIds().forEach { diff --git a/app/src/main/kotlin/com/simplemobiletools/calculator/views/ConverterView.kt b/app/src/main/kotlin/com/simplemobiletools/calculator/views/ConverterView.kt index 3b8abc3..62ceda8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/calculator/views/ConverterView.kt +++ b/app/src/main/kotlin/com/simplemobiletools/calculator/views/ConverterView.kt @@ -9,7 +9,6 @@ import android.graphics.drawable.RippleDrawable import android.util.AttributeSet import android.view.View import android.widget.LinearLayout -import android.widget.TextView import androidx.core.content.res.ResourcesCompat import androidx.core.widget.TextViewCompat import com.simplemobiletools.calculator.R @@ -105,6 +104,19 @@ class ConverterView @JvmOverloads constructor( 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) { when (id) { 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 KMutableProperty0.swapWith(other: KMutableProperty0) { this.get().also { this.set(other.get())