Avoid NPE in setupSwipeToReply

Exception java.lang.NullPointerException:
  at com.nextcloud.talk.controllers.ChatController.setupSwipeToReply (ChatController.kt:419)
  at com.nextcloud.talk.controllers.ChatController.access$setupSwipeToReply (ChatController.kt:221)
  at com.nextcloud.talk.controllers.ChatController$getRoomInfo$1.onNext (ChatController.kt:378)
  at com.nextcloud.talk.controllers.ChatController$getRoomInfo$1.onNext (ChatController.kt:362)
  at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal (ObservableObserveOn.java:201)
  at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run (ObservableObserveOn.java:255)
  at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run (HandlerScheduler.java:124)
  at android.os.Handler.handleCallback (Handler.java:883)
  at android.os.Handler.dispatchMessage (Handler.java:100)
  at android.os.Looper.loop (Looper.java:237)
  at android.app.ActivityThread.main (ActivityThread.java:7830)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:492)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1040)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-03-23 11:50:14 +01:00
parent bf32d9e457
commit a941be5276
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -415,18 +415,20 @@ class ChatController(args: Bundle) :
participantPermissions.hasChatPermission() &&
!isReadOnlyConversation()
) {
val messageSwipeController = MessageSwipeCallback(
activity!!,
object : MessageSwipeActions {
override fun showReplyUI(position: Int) {
val chatMessage = adapter?.items?.get(position)?.item as ChatMessage?
replyToMessage(chatMessage)
activity?.let {
val messageSwipeController = MessageSwipeCallback(
it,
object : MessageSwipeActions {
override fun showReplyUI(position: Int) {
val chatMessage = adapter?.items?.get(position)?.item as ChatMessage?
replyToMessage(chatMessage)
}
}
}
)
)
val itemTouchHelper = ItemTouchHelper(messageSwipeController)
itemTouchHelper.attachToRecyclerView(binding?.messagesListView)
val itemTouchHelper = ItemTouchHelper(messageSwipeController)
itemTouchHelper.attachToRecyclerView(binding?.messagesListView)
}
}
}