@@ -45,7 +45,9 @@ import com.google.android.material.shape.MaterialShapeDrawable
45
45
import im.vector.app.R
46
46
import im.vector.app.core.extensions.setTextIfDifferent
47
47
import im.vector.app.core.extensions.showKeyboard
48
+ import im.vector.app.core.utils.Debouncer
48
49
import im.vector.app.core.utils.DimensionConverter
50
+ import im.vector.app.core.utils.createUIHandler
49
51
import im.vector.app.databinding.ComposerRichTextLayoutBinding
50
52
import im.vector.app.databinding.ViewRichTextMenuButtonBinding
51
53
import im.vector.app.features.home.room.detail.composer.images.UriContentListener
@@ -195,10 +197,16 @@ internal class RichTextComposerLayout @JvmOverloads constructor(
195
197
renderComposerMode(MessageComposerMode .Normal (null ))
196
198
197
199
views.richTextComposerEditText.addTextChangedListener(
198
- TextChangeListener ({ callback?.onTextChanged(it) }, { updateTextFieldBorder(isFullScreen) })
200
+ TextChangeListener (
201
+ onTextChanged = {
202
+ callback?.onTextChanged(it)
203
+ },
204
+ onExpandedChanged = { updateTextFieldBorder(isFullScreen) })
199
205
)
200
206
views.plainTextComposerEditText.addTextChangedListener(
201
- TextChangeListener ({ callback?.onTextChanged(it) }, { updateTextFieldBorder(isFullScreen) })
207
+ TextChangeListener ({
208
+ callback?.onTextChanged(it)
209
+ }, { updateTextFieldBorder(isFullScreen) })
202
210
)
203
211
ViewCompat .setOnReceiveContentListener(
204
212
views.richTextComposerEditText,
@@ -516,18 +524,21 @@ internal class RichTextComposerLayout @JvmOverloads constructor(
516
524
private val onTextChanged : (s: Editable ) -> Unit ,
517
525
private val onExpandedChanged : (isExpanded: Boolean ) -> Unit ,
518
526
) : TextWatcher {
527
+
528
+ private val debouncer = Debouncer (createUIHandler())
519
529
private var previousTextWasExpanded = false
520
530
521
531
override fun beforeTextChanged (s : CharSequence? , start : Int , count : Int , after : Int ) {}
522
532
override fun onTextChanged (s : CharSequence? , start : Int , before : Int , count : Int ) {}
523
533
override fun afterTextChanged (s : Editable ) {
524
- onTextChanged.invoke(s)
525
-
526
- val isExpanded = s.lines().count() > 1
527
- if (previousTextWasExpanded != isExpanded) {
528
- onExpandedChanged(isExpanded)
534
+ debouncer.debounce(" afterTextChanged" , 50L ) {
535
+ onTextChanged.invoke(s)
536
+ val isExpanded = s.lines().count() > 1
537
+ if (previousTextWasExpanded != isExpanded) {
538
+ onExpandedChanged(isExpanded)
539
+ }
540
+ previousTextWasExpanded = isExpanded
529
541
}
530
- previousTextWasExpanded = isExpanded
531
542
}
532
543
}
533
544
}
0 commit comments