From b70b0589255208e132eee0f66a8c4094540967fd Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Fri, 19 Jul 2024 14:11:22 -0300 Subject: [PATCH] Fix crash with reused destroyed context. --- .../securesms/WebRtcCallActivity.java | 2 ++ ...CallParticipantsListUpdatePopupWindow.java | 19 ++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java index f545f62172..724187a2f9 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java @@ -491,6 +491,8 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan } return state.getLocalParticipant().isHandRaised(); }); + + getLifecycle().addObserver(participantUpdateWindow); } private @NonNull Orientation resolveOrientationFromContext() { diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsListUpdatePopupWindow.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsListUpdatePopupWindow.java index fdc387cc3d..3b444c7520 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsListUpdatePopupWindow.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsListUpdatePopupWindow.java @@ -2,6 +2,8 @@ package org.thoughtcrime.securesms.components.webrtc; import android.content.Context; +import android.os.Handler; +import android.os.Looper; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; @@ -13,6 +15,8 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.PluralsRes; import androidx.annotation.StringRes; +import androidx.lifecycle.DefaultLifecycleObserver; +import androidx.lifecycle.LifecycleOwner; import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.badges.BadgeImageView; @@ -24,14 +28,15 @@ import java.util.Iterator; import java.util.Set; import java.util.concurrent.TimeUnit; -public class CallParticipantsListUpdatePopupWindow extends PopupWindow { +public class CallParticipantsListUpdatePopupWindow extends PopupWindow implements DefaultLifecycleObserver { - private static final long DURATION = TimeUnit.SECONDS.toMillis(2); + private static final long DURATION = TimeUnit.SECONDS.toMillis(10); private final ViewGroup parent; private final AvatarImageView avatarImageView; private final BadgeImageView badgeImageView; private final TextView descriptionTextView; + private final Handler handler; private final Set pendingAdditions = new HashSet<>(); private final Set pendingRemovals = new HashSet<>(); @@ -47,6 +52,7 @@ public class CallParticipantsListUpdatePopupWindow extends PopupWindow { this.avatarImageView = getContentView().findViewById(R.id.avatar); this.badgeImageView = getContentView().findViewById(R.id.badge); this.descriptionTextView = getContentView().findViewById(R.id.description); + this.handler = new Handler(Looper.getMainLooper()); setOnDismissListener(this::showPending); setAnimationStyle(R.style.PopupAnimation); @@ -72,6 +78,13 @@ public class CallParticipantsListUpdatePopupWindow extends PopupWindow { } } + @Override + public void onDestroy(@NonNull LifecycleOwner owner) { + handler.removeCallbacksAndMessages(null); + setOnDismissListener(null); + dismiss(); + } + private void showPending() { if (!pendingAdditions.isEmpty()) { showAdditions(); @@ -102,7 +115,7 @@ public class CallParticipantsListUpdatePopupWindow extends PopupWindow { showAtLocation(parent, Gravity.TOP | Gravity.START, 0, 0); measureChild(); update(); - getContentView().postDelayed(this::dismiss, DURATION); + handler.postDelayed(this::dismiss, DURATION); } private void measureChild() {