Browse Source

add destruction check before accessing the binding object

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
Andy Scherzinger 3 years ago
parent
commit
266a9f73ee
1 changed files with 19 additions and 17 deletions
  1. 19 17
      app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

+ 19 - 17
app/src/main/java/com/nextcloud/talk/controllers/ChatController.kt

@@ -773,24 +773,26 @@ class ChatController(args: Bundle) :
     }
 
     private fun setupMentionAutocomplete() {
-        val elevation = 6f
-        resources?.let {
-            val backgroundDrawable = ColorDrawable(it.getColor(R.color.bg_default))
-            val presenter = MentionAutocompletePresenter(activity, roomToken)
-            val callback = MentionAutocompleteCallback(
-                activity,
-                conversationUser,
-                binding?.messageInputView?.inputEditText
-            )
+        if (!isDestroyed && !isBeingDestroyed) {
+            val elevation = 6f
+            resources?.let {
+                val backgroundDrawable = ColorDrawable(it.getColor(R.color.bg_default))
+                val presenter = MentionAutocompletePresenter(activity, roomToken)
+                val callback = MentionAutocompleteCallback(
+                    activity,
+                    conversationUser,
+                    binding?.messageInputView?.inputEditText
+                )
 
-            if (mentionAutocomplete == null && binding?.messageInputView?.inputEditText != null) {
-                mentionAutocomplete = Autocomplete.on<Mention>(binding?.messageInputView?.inputEditText)
-                    .with(elevation)
-                    .with(backgroundDrawable)
-                    .with(MagicCharPolicy('@'))
-                    .with(presenter)
-                    .with(callback)
-                    .build()
+                if (mentionAutocomplete == null && binding?.messageInputView?.inputEditText != null) {
+                    mentionAutocomplete = Autocomplete.on<Mention>(binding?.messageInputView?.inputEditText)
+                        .with(elevation)
+                        .with(backgroundDrawable)
+                        .with(MagicCharPolicy('@'))
+                        .with(presenter)
+                        .with(callback)
+                        .build()
+                }
             }
         }
     }