From 61886ea10a7b9cd789b36bd9ce47e473fa9723f6 Mon Sep 17 00:00:00 2001 From: Alex Hart Date: Mon, 7 Dec 2020 13:16:02 -0400 Subject: [PATCH] Display speaker in PiP. --- .../webrtc/CallParticipantsLayout.java | 10 +++++---- .../webrtc/WebRtcCallParticipantsPage.java | 21 +++++++++++++------ .../WebRtcCallParticipantsPagerAdapter.java | 2 +- .../components/webrtc/WebRtcCallView.java | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayout.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayout.java index 2322ed223..997f4fd7f 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayout.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayout.java @@ -30,6 +30,7 @@ public class CallParticipantsLayout extends FlexboxLayout { private static final int CORNER_RADIUS = ViewUtil.dpToPx(10); private List callParticipants = Collections.emptyList(); + private CallParticipant focusedParticipant = null; private boolean shouldRenderInPip; public CallParticipantsLayout(@NonNull Context context) { @@ -44,9 +45,10 @@ public class CallParticipantsLayout extends FlexboxLayout { super(context, attrs, defStyleAttr); } - void update(@NonNull List callParticipants, boolean shouldRenderInPip) { - this.callParticipants = callParticipants; - this.shouldRenderInPip = shouldRenderInPip; + void update(@NonNull List callParticipants, @NonNull CallParticipant focusedParticipant, boolean shouldRenderInPip) { + this.callParticipants = callParticipants; + this.focusedParticipant = focusedParticipant; + this.shouldRenderInPip = shouldRenderInPip; updateLayout(); } @@ -55,7 +57,7 @@ public class CallParticipantsLayout extends FlexboxLayout { if (shouldRenderInPip && Util.hasItems(callParticipants)) { updateChildrenCount(1); - update(0, 1, callParticipants.get(0)); + update(0, 1, focusedParticipant); } else { int count = callParticipants.size(); updateChildrenCount(count); diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallParticipantsPage.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallParticipantsPage.java index 357f94ca4..89889289b 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallParticipantsPage.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallParticipantsPage.java @@ -11,34 +11,42 @@ import java.util.Objects; class WebRtcCallParticipantsPage { private final List callParticipants; + private final CallParticipant focusedParticipant; private final boolean isSpeaker; private final boolean isRenderInPip; static WebRtcCallParticipantsPage forMultipleParticipants(@NonNull List callParticipants, + @NonNull CallParticipant focusedParticipant, boolean isRenderInPip) { - return new WebRtcCallParticipantsPage(callParticipants, false, isRenderInPip); + return new WebRtcCallParticipantsPage(callParticipants, focusedParticipant, false, isRenderInPip); } static WebRtcCallParticipantsPage forSingleParticipant(@NonNull CallParticipant singleParticipant, boolean isRenderInPip) { - return new WebRtcCallParticipantsPage(Collections.singletonList(singleParticipant), true, isRenderInPip); + return new WebRtcCallParticipantsPage(Collections.singletonList(singleParticipant), singleParticipant, true, isRenderInPip); } private WebRtcCallParticipantsPage(@NonNull List callParticipants, + @NonNull CallParticipant focusedParticipant, boolean isSpeaker, boolean isRenderInPip) { - this.callParticipants = callParticipants; - this.isSpeaker = isSpeaker; - this.isRenderInPip = isRenderInPip; + this.callParticipants = callParticipants; + this.focusedParticipant = focusedParticipant; + this.isSpeaker = isSpeaker; + this.isRenderInPip = isRenderInPip; } public @NonNull List getCallParticipants() { return callParticipants; } + public @NonNull CallParticipant getFocusedParticipant() { + return focusedParticipant; + } + public boolean isRenderInPip() { return isRenderInPip; } @@ -54,11 +62,12 @@ class WebRtcCallParticipantsPage { WebRtcCallParticipantsPage that = (WebRtcCallParticipantsPage) o; return isSpeaker == that.isSpeaker && isRenderInPip == that.isRenderInPip && + focusedParticipant.equals(that.focusedParticipant) && callParticipants.equals(that.callParticipants); } @Override public int hashCode() { - return Objects.hash(callParticipants, isSpeaker); + return Objects.hash(callParticipants, isSpeaker, focusedParticipant, isRenderInPip); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallParticipantsPagerAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallParticipantsPagerAdapter.java index c53e201c6..06c3afd62 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallParticipantsPagerAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallParticipantsPagerAdapter.java @@ -84,7 +84,7 @@ class WebRtcCallParticipantsPagerAdapter extends ListAdapter pages = new ArrayList<>(2); if (!state.getGridParticipants().isEmpty()) { - pages.add(WebRtcCallParticipantsPage.forMultipleParticipants(state.getGridParticipants(), state.isInPipMode())); + pages.add(WebRtcCallParticipantsPage.forMultipleParticipants(state.getGridParticipants(), state.getFocusedParticipant(), state.isInPipMode())); } if (state.getFocusedParticipant() != null && state.getAllRemoteParticipants().size() > 1) {