VicMikhailau / MaskedEditText

It allows you to add a mask to EditText
Apache License 2.0
284 stars 50 forks source link

fix update text #33

Closed MaiklGureev closed 3 months ago

MaiklGureev commented 4 months ago

hello in MaskedWatcher need fix update value in callback afterTextChanged

now in lib

` override fun afterTextChanged(s: Editable?) { if (s == null) return

    var value = s.toString()

    var maskLength = 0
    mMaskFormatter.maskLength?.let { maskLength = it}

    if (value.length > oldFormattedValue.length && maskLength < value.length) {
        value = oldFormattedValue
    }

    val formattedString = mMaskFormatter.formatString(value)

    formattedString?.let { setFormattedText(it) }
    oldFormattedValue = formattedString.toString()
    afterTextChanged?.invoke(s)
}`

i think should be on the last line afterTextChanged?.invoke(formattedString.toString()
because in afterTextChanged set unformatted updated string arrives with which you can’t do anything, for example 200.5.2024

` override fun afterTextChanged(s: Editable?) {
    if (s == null)
        return

    var value = s.toString()

    var maskLength = 0
    mMaskFormatter.maskLength?.let { maskLength = it}

    if (value.length > oldFormattedValue.length && maskLength < value.length) {
        value = oldFormattedValue
    }

    val formattedString = mMaskFormatter.formatString(value)

    formattedString?.let { setFormattedText(it) }
    oldFormattedValue = formattedString.toString()
    afterTextChanged?.invoke(formattedString.toString())
}`
VicMikhailau commented 3 months ago

@MaiklGureev Hi, Thank you for report.

Unfortunately, there is no way to devote much time to the project. Please feel free to Fork the project and add Pull requests. Thanks a lot!

VicMikhailau commented 3 months ago

@MaiklGureev Fixed here: https://github.com/VicMikhailau/MaskedEditText/releases/tag/v5.0.2