Skip to content

Commit

Permalink
bugfix : #24 addTextChangeListener
Browse files Browse the repository at this point in the history
  • Loading branch information
MSajidJuneja committed Jun 20, 2022
1 parent e874cd1 commit 835bf24
Showing 1 changed file with 30 additions and 0 deletions.
Expand Up @@ -5,7 +5,9 @@ import android.graphics.Typeface
import android.graphics.drawable.DrawableContainer.DrawableContainerState
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.StateListDrawable
import android.text.Editable
import android.text.InputFilter
import android.text.TextWatcher
import android.text.method.HideReturnsTransformationMethod
import android.text.method.PasswordTransformationMethod
import android.util.AttributeSet
Expand All @@ -32,6 +34,7 @@ class SSCustomEdittextOutlinedBorder @JvmOverloads constructor(context: Context,
private var borderColor = ContextCompat.getColor(context, R.color.color_warm_grey)
private var borderErrorColor = ContextCompat.getColor(context, R.color.color_error)
private var borderWidth = 1
private var onTextChangeListener: OnTextChangeListener? = null

val getTextValue: String
get() {
Expand Down Expand Up @@ -67,6 +70,7 @@ class SSCustomEdittextOutlinedBorder @JvmOverloads constructor(context: Context,
setIsErrorEnable(isErrorEnable)
setIsToggleEnable(isToggleEnable)
setPasswordToggleClick()
setTextChangeListeners()
setStyle(inputType, maxLine, minLine, maxLength)
setTitleBackGroundColor(titleBgColor)
setEditTextBackGroundColor(editTextBgColor)
Expand Down Expand Up @@ -128,6 +132,32 @@ class SSCustomEdittextOutlinedBorder @JvmOverloads constructor(context: Context,
}
}

interface OnTextChangeListener {
fun beforeTextChange(s: CharSequence?, start: Int, count: Int, after: Int)
fun onTextChange(s: CharSequence?, start: Int, count: Int, after: Int)
fun afterTextChange(s: Editable?)
}

fun setOnTextChangeListener(onTextChangeListener: OnTextChangeListener?) {
this.onTextChangeListener = onTextChangeListener
}

private fun setTextChangeListeners() {
editText.addTextChangedListener(object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
onTextChangeListener?.afterTextChange(s)
}

override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
onTextChangeListener?.beforeTextChange(s, start, count, after)
}

override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
onTextChangeListener?.onTextChange(s, start, before, count)
}
})
}

private fun setTitleColor(@ColorInt colorID: Int) {
lableTitle.setTextColor(colorID)
}
Expand Down

0 comments on commit 835bf24

Please sign in to comment.