Skip to content

Commit

Permalink
Release/1.0.23 (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tweener committed Jun 2, 2022
1 parent d05bb3d commit 751dc42
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
buildscript {

ext {
grapes_version = '1.0.22'
grapes_version = '1.0.23'

kotlin_version = '1.5.31'
firebase_app_distribution_version = '2.1.2'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class EditableTextBottomSheetDialogFragment : BottomSheetDialogFragment() {
binding?.apply {
headerCloseButton.setOnClickListener { dismiss() }
validateButton.setOnClickListener { withActivityAttached { runOnUiThread { onValidateButtonClicked?.invoke(editText.text.toString().trim()) } } }
editText.afterTextChangedWith(EDITTEXT_TEXT_CHANGED_DELAY) { withActivityAttached { runOnUiThread { updateValidateButton() } } }
editText.onTextChanged { withActivityAttached { runOnUiThread { updateValidateButton() } } }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,31 @@ internal fun EditText.afterTextChangedWith(delay: Long, consumer: (String) -> Un
override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}

override fun afterTextChanged(editable: Editable?) {
timer.cancel()
timer = Timer().apply { schedule(delay) { editable?.let { consumer(it.toString()) } } }
try {
editable?.let {
val newText = editable.toString()

timer.cancel()
timer = Timer().apply { schedule(delay) { consumer(newText) } }
}
} catch (exception: IndexOutOfBoundsException) {
// A crash randomly happens here causing an IndexOutOfBoundsException when toString() tries to get the characters from the EditText
// https://console.firebase.google.com/u/0/project/spendesk-mobile/crashlytics/app/android:com.spendesk.spendesk/issues/366c950f3b688d79a5de9004b6c5e947?time=last-ninety-days&types=crash&versions=2.23.4%20(22302888);2.23.3%20(22302887)&sessionEventKey=6297C55100E60001732296088542CD65_1682809803838467563
// There is nothing much we can do here to get the text from the EditText if this method fails, so we just catch it to avoid a crash.
}
}
})

internal fun EditText.onTextChanged(consumer: (String) -> Unit) =
addTextChangedListener(object : TextWatcher {
override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {}

override fun onTextChanged(text: CharSequence?, p1: Int, p2: Int, p3: Int) {
text?.let { consumer(it.toString()) }
}

override fun afterTextChanged(editable: Editable?) {}
})

fun EditText.setTextAndPositionCursorEnd(text: CharSequence) {
setText(text)
Expand Down

0 comments on commit 751dc42

Please sign in to comment.