diff --git a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java index d204cfd93..6bf2f76a6 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java +++ b/app/src/main/java/org/thoughtcrime/securesms/WebRtcCallActivity.java @@ -17,6 +17,8 @@ package org.thoughtcrime.securesms; +import static org.thoughtcrime.securesms.components.sensors.Orientation.PORTRAIT_BOTTOM_EDGE; + import android.Manifest; import android.annotation.SuppressLint; import android.app.PictureInPictureParams; @@ -73,15 +75,13 @@ import org.thoughtcrime.securesms.util.FullscreenHelper; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.livedata.LiveDataUtil; +import org.thoughtcrime.securesms.webrtc.CallParticipantsViewState; import org.whispersystems.libsignal.IdentityKey; -import org.whispersystems.libsignal.util.Pair; import org.whispersystems.signalservice.api.messages.calls.HangupMessage; import java.util.List; import java.util.Optional; -import static org.thoughtcrime.securesms.components.sensors.Orientation.PORTRAIT_BOTTOM_EDGE; - public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChangeDialog.Callback { private static final String TAG = Log.tag(WebRtcCallActivity.class); @@ -111,18 +111,6 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan super.attachBaseContext(newBase); } - @Override - public void onConfigurationChanged(@NonNull Configuration newConfig) { - super.onConfigurationChanged(newConfig); - - if (newConfig.densityDpi >= 480 && getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT) { - viewModel.setIsLandscapeEnabled(true); - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); - } else if (newConfig.densityDpi < 480){ - viewModel.setIsLandscapeEnabled(false); - } - } - @SuppressLint("SourceLockedOrientationActivity") @Override public void onCreate(Bundle savedInstanceState) { @@ -131,7 +119,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); super.onCreate(savedInstanceState); - boolean isLandscapeEnabled = getResources().getConfiguration().densityDpi >= 480; + boolean isLandscapeEnabled = getResources().getConfiguration().smallestScreenWidthDp >= 480; if (!isLandscapeEnabled) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } @@ -152,7 +140,7 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan getIntent().removeExtra(EXTRA_ENABLE_VIDEO_IF_AVAILABLE); windowManager = new androidx.window.WindowManager(this); - windowLayoutInfoConsumer = new WindowLayoutInfoConsumer(windowManager); + windowLayoutInfoConsumer = new WindowLayoutInfoConsumer(); windowManager.registerLayoutChangeCallback(SignalExecutors.BOUNDED, windowLayoutInfoConsumer); } @@ -296,8 +284,10 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan viewModel.getWebRtcControls().observe(this, callScreen::setWebRtcControls); viewModel.getEvents().observe(this, this::handleViewModelEvent); viewModel.getCallTime().observe(this, this::handleCallTime); - LiveDataUtil.combineLatest(viewModel.getCallParticipantsState(), viewModel.getOrientation(), (s, o) -> new Pair<>(s, o == PORTRAIT_BOTTOM_EDGE)) - .observe(this, p -> callScreen.updateCallParticipants(p.first(), p.second())); + LiveDataUtil.combineLatest(viewModel.getCallParticipantsState(), + viewModel.getOrientationAndLandscapeEnabled(), + (s, o) -> new CallParticipantsViewState(s, o.first == PORTRAIT_BOTTOM_EDGE, o.second)) + .observe(this, p -> callScreen.updateCallParticipants(p)); viewModel.getCallParticipantListUpdate().observe(this, participantUpdateWindow::addCallParticipantListUpdate); viewModel.getSafetyNumberChangeEvent().observe(this, this::handleSafetyNumberChangeEvent); viewModel.getGroupMembers().observe(this, unused -> updateGroupMembersForGroupCall()); @@ -773,17 +763,13 @@ public class WebRtcCallActivity extends BaseActivity implements SafetyNumberChan private class WindowLayoutInfoConsumer implements Consumer { - private final androidx.window.WindowManager windowManager; - - private WindowLayoutInfoConsumer(androidx.window.WindowManager windowManager) { - this.windowManager = windowManager; - } - @Override public void accept(WindowLayoutInfo windowLayoutInfo) { Log.d(TAG, "On WindowLayoutInfo accepted: " + windowLayoutInfo.toString()); Optional feature = windowLayoutInfo.getDisplayFeatures().stream().filter(f -> f instanceof FoldingFeature).findFirst(); + viewModel.setIsLandscapeEnabled(feature.isPresent()); + setRequestedOrientation(feature.isPresent() ? ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED : ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); if (feature.isPresent()) { FoldingFeature foldingFeature = (FoldingFeature) feature.get(); Rect bounds = foldingFeature.getBounds(); 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 c234445c2..db6f990b2 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 @@ -43,8 +43,8 @@ object CallParticipantsLayoutStrategies { } @JvmStatic - fun getStrategy(isPortrait: Boolean): CallParticipantsLayout.LayoutStrategy { - return if (isPortrait) { + fun getStrategy(isPortrait: Boolean, isLandscapeEnabled: Boolean): CallParticipantsLayout.LayoutStrategy { + return if (isPortrait || !isLandscapeEnabled) { Portrait } else { Landscape 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 1320dacbe..ca89e3da8 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 @@ -15,33 +15,38 @@ class WebRtcCallParticipantsPage { private final boolean isSpeaker; private final boolean isRenderInPip; private final boolean isPortrait; + private final boolean isLandscapeEnabled; static WebRtcCallParticipantsPage forMultipleParticipants(@NonNull List callParticipants, @NonNull CallParticipant focusedParticipant, boolean isRenderInPip, - boolean isPortrait) + boolean isPortrait, + boolean isLandscapeEnabled) { - return new WebRtcCallParticipantsPage(callParticipants, focusedParticipant, false, isRenderInPip, isPortrait); + return new WebRtcCallParticipantsPage(callParticipants, focusedParticipant, false, isRenderInPip, isPortrait, isLandscapeEnabled); } static WebRtcCallParticipantsPage forSingleParticipant(@NonNull CallParticipant singleParticipant, boolean isRenderInPip, - boolean isPortrait) + boolean isPortrait, + boolean isLandscapeEnabled) { - return new WebRtcCallParticipantsPage(Collections.singletonList(singleParticipant), singleParticipant, true, isRenderInPip, isPortrait); + return new WebRtcCallParticipantsPage(Collections.singletonList(singleParticipant), singleParticipant, true, isRenderInPip, isPortrait, isLandscapeEnabled); } private WebRtcCallParticipantsPage(@NonNull List callParticipants, @NonNull CallParticipant focusedParticipant, boolean isSpeaker, boolean isRenderInPip, - boolean isPortrait) + boolean isPortrait, + boolean isLandscapeEnabled) { this.callParticipants = callParticipants; this.focusedParticipant = focusedParticipant; this.isSpeaker = isSpeaker; this.isRenderInPip = isRenderInPip; this.isPortrait = isPortrait; + this.isLandscapeEnabled = isLandscapeEnabled; } public @NonNull List getCallParticipants() { @@ -65,7 +70,7 @@ class WebRtcCallParticipantsPage { } public @NonNull CallParticipantsLayout.LayoutStrategy getLayoutStrategy() { - return CallParticipantsLayoutStrategies.getStrategy(isPortrait); + return CallParticipantsLayoutStrategies.getStrategy(isPortrait, isLandscapeEnabled); } @Override diff --git a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java index 08f371d7d..150d46000 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java +++ b/app/src/main/java/org/thoughtcrime/securesms/components/webrtc/WebRtcCallView.java @@ -49,6 +49,7 @@ import org.thoughtcrime.securesms.util.ServiceUtil; import org.thoughtcrime.securesms.util.SetUtil; import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.views.Stub; +import org.thoughtcrime.securesms.webrtc.CallParticipantsViewState; import org.webrtc.RendererCommon; import org.whispersystems.signalservice.api.messages.calls.HangupMessage; @@ -318,15 +319,18 @@ public class WebRtcCallView extends ConstraintLayout { micToggle.setChecked(isMicEnabled, false); } - public void updateCallParticipants(@NonNull CallParticipantsState state, boolean isPortrait) { - List pages = new ArrayList<>(2); + public void updateCallParticipants(@NonNull CallParticipantsViewState callParticipantsViewState) { + CallParticipantsState state = callParticipantsViewState.getCallParticipantsState(); + boolean isPortrait = callParticipantsViewState.isPortrait(); + boolean isLandscapeEnabled = callParticipantsViewState.isLandscapeEnabled(); + List pages = new ArrayList<>(2); if (!state.getGridParticipants().isEmpty()) { - pages.add(WebRtcCallParticipantsPage.forMultipleParticipants(state.getGridParticipants(), state.getFocusedParticipant(), state.isInPipMode(), isPortrait)); + pages.add(WebRtcCallParticipantsPage.forMultipleParticipants(state.getGridParticipants(), state.getFocusedParticipant(), state.isInPipMode(), isPortrait, isLandscapeEnabled)); } if (state.getFocusedParticipant() != CallParticipant.EMPTY && state.getAllRemoteParticipants().size() > 1) { - pages.add(WebRtcCallParticipantsPage.forSingleParticipant(state.getFocusedParticipant(), state.isInPipMode(), isPortrait)); + pages.add(WebRtcCallParticipantsPage.forSingleParticipant(state.getFocusedParticipant(), state.isInPipMode(), isPortrait, isLandscapeEnabled)); } if ((state.getGroupCallState().isNotIdle() && state.getRemoteDevicesCount().orElse(0) > 0) || state.getGroupCallState().isConnected()) { diff --git a/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallParticipantsViewState.kt b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallParticipantsViewState.kt new file mode 100644 index 000000000..be865115f --- /dev/null +++ b/app/src/main/java/org/thoughtcrime/securesms/webrtc/CallParticipantsViewState.kt @@ -0,0 +1,9 @@ +package org.thoughtcrime.securesms.webrtc + +import org.thoughtcrime.securesms.components.webrtc.CallParticipantsState + +data class CallParticipantsViewState( + val callParticipantsState: CallParticipantsState, + val isPortrait: Boolean, + val isLandscapeEnabled: Boolean +)