From b484c6dd482ca03babbf5aa94fe0cddab16d5fc3 Mon Sep 17 00:00:00 2001 From: Vladimir Date: Sat, 22 Aug 2020 22:08:38 +0500 Subject: [PATCH] codestyle --- .../ru/touchin/widget/AmountWithDecimalEditText.kt | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/views/src/main/java/ru/touchin/widget/AmountWithDecimalEditText.kt b/views/src/main/java/ru/touchin/widget/AmountWithDecimalEditText.kt index 8dedf59..ff14056 100644 --- a/views/src/main/java/ru/touchin/widget/AmountWithDecimalEditText.kt +++ b/views/src/main/java/ru/touchin/widget/AmountWithDecimalEditText.kt @@ -26,22 +26,21 @@ class AmountWithDecimalEditText @JvmOverloads constructor( private const val DEFAULT_DECIMAL_PART_LENGTH = 2 private val hardcodedSymbols = listOf(GROUPING_SEPARATOR) private val possibleDecimalSeparators = listOf(",", ".") + } - private var textBefore = "" - private var isTextWasArtificiallyChanged = true - var decimalSeparator = DEFAULT_DECIMAL_SEPARATOR set(value) { if (!possibleDecimalSeparators.contains(value)) throw Exception("Not allowed decimal separator. Supports only: $possibleDecimalSeparators") field = value } - - var decimalPartLength = DEFAULT_DECIMAL_PART_LENGTH var isSeparatorCutInvalidDecimalLength = false + private var textBefore = "" + private var isTextWasArtificiallyChanged = true + init { doOnTextChanged { text, _, _, _ -> if (isTextWasArtificiallyChanged) { @@ -130,6 +129,8 @@ class AmountWithDecimalEditText @JvmOverloads constructor( } } + fun getTextWithoutFormatting() = text.toString().withoutFormatting() + private fun setTextWhichWasPasted(text: String) { var result = "" var decimalLength = -1 @@ -152,9 +153,6 @@ class AmountWithDecimalEditText @JvmOverloads constructor( setSelection(result.length) } - - fun getTextWithoutFormatting() = text.toString().withoutFormatting() - private fun String.withoutFormatting(): String { var result = this hardcodedSymbols.forEach { result = this.replace(it.toString(), "") }