mirror of
https://github.com/nextcloud/talk-android
synced 2025-03-12 10:32:36 +00:00
Handle async call back to already destroyed UI
Fixes #1426 Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
parent
c4ca802408
commit
73e96198de
@ -602,35 +602,44 @@ class ChatController(args: Bundle) :
|
|||||||
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
|
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Suppress("Detekt.TooGenericExceptionCaught")
|
||||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
|
||||||
if (s.length >= lengthFilter) {
|
try {
|
||||||
binding.messageInputView.inputEditText?.error = String.format(
|
if (s.length >= lengthFilter) {
|
||||||
Objects.requireNonNull<Resources>(resources).getString(R.string.nc_limit_hit),
|
binding.messageInputView.inputEditText?.error = String.format(
|
||||||
Integer.toString(lengthFilter)
|
Objects.requireNonNull<Resources>(resources).getString(R.string.nc_limit_hit),
|
||||||
)
|
Integer.toString(lengthFilter)
|
||||||
} else {
|
)
|
||||||
binding.messageInputView.inputEditText?.error = null
|
} else {
|
||||||
}
|
binding.messageInputView.inputEditText?.error = null
|
||||||
|
}
|
||||||
|
|
||||||
val editable = binding.messageInputView.inputEditText?.editableText
|
val editable = binding.messageInputView.inputEditText?.editableText
|
||||||
if (editable != null && binding.messageInputView.inputEditText != null) {
|
if (editable != null && binding.messageInputView.inputEditText != null) {
|
||||||
val mentionSpans = editable.getSpans(
|
val mentionSpans = editable.getSpans(
|
||||||
0, binding.messageInputView.inputEditText!!.length(),
|
0, binding.messageInputView.inputEditText!!.length(),
|
||||||
Spans.MentionChipSpan::class.java
|
Spans.MentionChipSpan::class.java
|
||||||
)
|
)
|
||||||
var mentionSpan: Spans.MentionChipSpan
|
var mentionSpan: Spans.MentionChipSpan
|
||||||
for (i in mentionSpans.indices) {
|
for (i in mentionSpans.indices) {
|
||||||
mentionSpan = mentionSpans[i]
|
mentionSpan = mentionSpans[i]
|
||||||
if (start >= editable.getSpanStart(mentionSpan) && start < editable.getSpanEnd(mentionSpan)) {
|
if (start >= editable.getSpanStart(mentionSpan) &&
|
||||||
if (editable.subSequence(
|
start < editable.getSpanEnd(mentionSpan)
|
||||||
editable.getSpanStart(mentionSpan),
|
|
||||||
editable.getSpanEnd(mentionSpan)
|
|
||||||
).toString().trim { it <= ' ' } != mentionSpan.label
|
|
||||||
) {
|
) {
|
||||||
editable.removeSpan(mentionSpan)
|
if (editable.subSequence(
|
||||||
|
editable.getSpanStart(mentionSpan),
|
||||||
|
editable.getSpanEnd(mentionSpan)
|
||||||
|
).toString().trim { it <= ' ' } != mentionSpan.label
|
||||||
|
) {
|
||||||
|
editable.removeSpan(mentionSpan)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} catch (npe: NullPointerException) {
|
||||||
|
// view binding can be null
|
||||||
|
// since this is called asynchrously and UI might have been destroyed in the meantime
|
||||||
|
Log.i(TAG, "UI destroyed - view binding already gone")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user