codestyle

This commit is contained in:
Vladimir 2020-08-22 22:08:38 +05:00
parent 817f41da3e
commit b484c6dd48
1 changed files with 6 additions and 8 deletions

View File

@ -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(), "") }