diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java index 8de91fc1f2..12695edcc1 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantView.java @@ -105,6 +105,10 @@ public class CallParticipantView extends ConstraintLayout { renderer.setScalingType(scalingType); } + void setScalingType(@NonNull RendererCommon.ScalingType scalingTypeMatchOrientation, @NonNull RendererCommon.ScalingType scalingTypeMismatchOrientation) { + renderer.setScalingType(scalingTypeMatchOrientation, scalingTypeMismatchOrientation); + } + void setCallParticipant(@NonNull CallParticipant participant) { boolean participantChanged = recipientId == null || !recipientId.equals(participant.getRecipient().getId()); recipientId = participant.getRecipient().getId(); 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 648923258b..85b49758c1 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 @@ -115,11 +115,7 @@ public class CallParticipantsLayout extends FlexboxLayout { callParticipantView.setCallParticipant(participant); callParticipantView.setRenderInPip(shouldRenderInPip); - if (participant.isScreenSharing()) { - callParticipantView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT); - } else { - callParticipantView.setScalingType(isPortrait || count < 3 ? RendererCommon.ScalingType.SCALE_ASPECT_FILL : RendererCommon.ScalingType.SCALE_ASPECT_BALANCED); - } + layoutStrategy.setChildScaling(participant, callParticipantView, isPortrait, count); if (count > 1) { view.setPadding(MULTIPLE_PARTICIPANT_SPACING, MULTIPLE_PARTICIPANT_SPACING, MULTIPLE_PARTICIPANT_SPACING, MULTIPLE_PARTICIPANT_SPACING); @@ -150,6 +146,11 @@ public class CallParticipantsLayout extends FlexboxLayout { public interface LayoutStrategy { int getFlexDirection(); + void setChildScaling(@NonNull CallParticipant callParticipant, + @NonNull CallParticipantView callParticipantView, + boolean isPortrait, + int childCount); + void setChildLayoutParams(@NonNull View child, int childPosition, int childCount); } } diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayoutStrategies.kt b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayoutStrategies.kt index db6f990b2c..e8007d2531 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayoutStrategies.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/CallParticipantsLayoutStrategies.kt @@ -3,12 +3,22 @@ package org.thoughtcrime.securesms.components.webrtc import android.view.View import com.google.android.flexbox.FlexDirection import com.google.android.flexbox.FlexboxLayout +import org.thoughtcrime.securesms.events.CallParticipant +import org.webrtc.RendererCommon object CallParticipantsLayoutStrategies { private object Portrait : CallParticipantsLayout.LayoutStrategy { override fun getFlexDirection(): Int = FlexDirection.ROW + override fun setChildScaling(callParticipant: CallParticipant, callParticipantView: CallParticipantView, isPortrait: Boolean, childCount: Int) { + if (callParticipant.isScreenSharing) { + callParticipantView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT) + } else { + callParticipantView.setScalingType(if (isPortrait || childCount < 3) RendererCommon.ScalingType.SCALE_ASPECT_FILL else RendererCommon.ScalingType.SCALE_ASPECT_BALANCED) + } + } + override fun setChildLayoutParams(child: View, childPosition: Int, childCount: Int) { val params = child.layoutParams as FlexboxLayout.LayoutParams if (childCount < 3) { @@ -27,6 +37,14 @@ object CallParticipantsLayoutStrategies { private object Landscape : CallParticipantsLayout.LayoutStrategy { override fun getFlexDirection() = FlexDirection.COLUMN + override fun setChildScaling(callParticipant: CallParticipant, callParticipantView: CallParticipantView, isPortrait: Boolean, childCount: Int) { + if (callParticipant.isScreenSharing) { + callParticipantView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT) + } else { + callParticipantView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FILL, RendererCommon.ScalingType.SCALE_ASPECT_BALANCED) + } + } + override fun setChildLayoutParams(child: View, childPosition: Int, childCount: Int) { val params = child.layoutParams as FlexboxLayout.LayoutParams if (childCount < 4) {