Avoid NPE for voice message recording

Exception java.lang.NullPointerException:
  at com.nextcloud.talk.controllers.ChatController$onViewBound$11.onTouch (ChatController.kt:867)
  at android.view.View.dispatchTouchEvent (View.java:15540)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at android.view.ViewGroup.dispatchTransformedTouchEvent (ViewGroup.java:3316)
  at android.view.ViewGroup.dispatchTouchEvent (ViewGroup.java:2990)
  at com.android.internal.policy.DecorView.superDispatchTouchEvent (DecorView.java:1112)
  at com.android.internal.policy.PhoneWindow.superDispatchTouchEvent (PhoneWindow.java:1971)
  at android.app.Activity.dispatchTouchEvent (Activity.java:4388)
  at androidx.appcompat.view.WindowCallbackWrapper.dispatchTouchEvent (WindowCallbackWrapper.java:70)
  at com.android.internal.policy.DecorView.dispatchTouchEvent (DecorView.java:1070)
  at android.view.View.dispatchPointerEvent (View.java:15803)
  at android.view.ViewRootImpl$ViewPostImeInputStage.processPointerEvent (ViewRootImpl.java:8153)
  at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess (ViewRootImpl.java:7877)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:7213)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:7270)
  at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:7236)
  at android.view.ViewRootImpl$AsyncInputStage.forward (ViewRootImpl.java:7434)
  at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:7244)
  at android.view.ViewRootImpl$AsyncInputStage.apply (ViewRootImpl.java:7491)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:7217)
  at android.view.ViewRootImpl$InputStage.onDeliverToNext (ViewRootImpl.java:7270)
  at android.view.ViewRootImpl$InputStage.forward (ViewRootImpl.java:7236)
  at android.view.ViewRootImpl$InputStage.apply (ViewRootImpl.java:7244)
  at android.view.ViewRootImpl$InputStage.deliver (ViewRootImpl.java:7217)
  at android.view.ViewRootImpl.deliverInputEvent (ViewRootImpl.java:10788)
  at android.view.ViewRootImpl.doProcessInputEvents (ViewRootImpl.java:10676)
  at android.view.ViewRootImpl.enqueueInputEvent (ViewRootImpl.java:10632)
  at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent (ViewRootImpl.java:10926)
  at android.view.InputEventReceiver.dispatchInputEvent (InputEventReceiver.java:285)
  at android.os.MessageQueue.nativePollOnce
  at android.os.MessageQueue.next (MessageQueue.java:335)
  at android.os.Looper.loopOnce (Looper.java:186)
  at android.os.Looper.loop (Looper.java:313)
  at android.app.ActivityThread.main (ActivityThread.java:8757)
  at java.lang.reflect.Method.invoke
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:571)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1067)

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2023-03-06 12:59:47 +01:00
parent 1add979750
commit 9367eb1a49
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B

View file

@ -858,30 +858,31 @@ class ChatController(args: Bundle) :
showRecordAudioUi(true) showRecordAudioUi(true)
binding?.messageInputView?.slideToCancelDescription?.x?.let {
if (sliderInitX == 0.0F) {
sliderInitX = it
}
}
val movedX: Float = event.x val movedX: Float = event.x
deltaX = movedX - downX deltaX = movedX - downX
// only allow slide to left // only allow slide to left
if (binding?.messageInputView?.slideToCancelDescription?.x!! > sliderInitX) { binding?.messageInputView?.slideToCancelDescription?.x?.let {
binding?.messageInputView?.slideToCancelDescription?.x = sliderInitX if (sliderInitX == 0.0F) {
sliderInitX = it
}
if (it > sliderInitX) {
binding?.messageInputView?.slideToCancelDescription?.x = sliderInitX
}
} }
if (binding?.messageInputView?.slideToCancelDescription?.x!! < VOICE_RECORD_CANCEL_SLIDER_X) { binding?.messageInputView?.slideToCancelDescription?.x?.let {
Log.d(TAG, "stopping recording because slider was moved to left") if (it < VOICE_RECORD_CANCEL_SLIDER_X) {
stopAndDiscardAudioRecording() Log.d(TAG, "stopping recording because slider was moved to left")
showRecordAudioUi(false) stopAndDiscardAudioRecording()
binding?.messageInputView?.slideToCancelDescription?.x = sliderInitX showRecordAudioUi(false)
return true binding?.messageInputView?.slideToCancelDescription?.x = sliderInitX
} else { return true
binding?.messageInputView?.slideToCancelDescription?.x = } else {
binding?.messageInputView?.slideToCancelDescription?.x!! + deltaX binding?.messageInputView?.slideToCancelDescription?.x = it + deltaX
downX = movedX downX = movedX
}
} }
} }
} }