diff --git a/room/tuiroomkit/src/main/AndroidManifest.xml b/room/tuiroomkit/src/main/AndroidManifest.xml
index db17a847..1959f5f4 100644
--- a/room/tuiroomkit/src/main/AndroidManifest.xml
+++ b/room/tuiroomkit/src/main/AndroidManifest.xml
@@ -34,8 +34,9 @@
+ android:screenOrientation="locked" />
createRoom(roomID, behavior.options)
is RoomBehavior.Join -> joinRoom(roomID)
}
}
+ override fun onConfigurationChanged(newConfig: Configuration) {
+ super.onConfigurationChanged(newConfig)
+ updateOrientationVisibility(newConfig.orientation)
+ }
+
override fun initStore(roomID: String) {
participantStore = RoomParticipantStore.create(roomID)
}
@@ -358,6 +374,12 @@ class RoomMainView @JvmOverloads constructor(
.distinctUntilChanged()
.collect { screenShareOverlayView.updateScreenStatus(it) }
}
+ scope.launch {
+ participantStore.state.participantWithScreen
+ .map { it?.userID }
+ .distinctUntilChanged()
+ .collect(::onScreenSharerChanged)
+ }
}
override fun removeObserver() {
@@ -698,6 +720,67 @@ class RoomMainView @JvmOverloads constructor(
return AIMinutesActivity.getForegroundInstance() ?: context
}
+ private fun updateOrientationVisibility(orientation: Int) {
+ val isLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE
+ topBarView.visibility = if (isLandscape) GONE else VISIBLE
+ bottomBarView.visibility = if (isLandscape) GONE else VISIBLE
+ if (isLandscape) aiSubtitleView.visibility = GONE
+ if (roomType == RoomType.WEBINAR) {
+ barrageInputView.visibility = if (isLandscape) GONE else VISIBLE
+ barrageStreamView.visibility = if (isLandscape) GONE else VISIBLE
+ }
+ recordingFloatingView.visibility = when {
+ isLandscape -> GONE
+ roomStore.state.currentRoom.value?.recordingInfo?.status == RecordingStatus.RECORDING -> VISIBLE
+ else -> GONE
+ }
+ updateOrientationSwitchButtonVisibility(orientation)
+ }
+
+ private fun updateOrientationSwitchButtonVisibility(
+ orientation: Int = resources.configuration.orientation
+ ) {
+ val hasRemoteSharer = currentScreenSharerID != null && currentScreenSharerID != localUserID
+ val shouldShow = roomType != RoomType.WEBINAR && hasRemoteSharer
+ orientationSwitchButton.visibility = if (shouldShow) VISIBLE else GONE
+ val isLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE
+ orientationSwitchButton.setImageResource(
+ if (isLandscape) R.drawable.roomkit_ic_switch_portrait_button
+ else R.drawable.roomkit_ic_switch_landscape_button
+ )
+ }
+
+ @SuppressLint("SourceLockedOrientationActivity")
+ private fun switchOrientation() {
+ val activity = context as? Activity ?: return
+ val currentlyLandscape =
+ resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE
+ activity.requestedOrientation = if (currentlyLandscape) {
+ ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
+ } else {
+ ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
+ }
+ }
+
+ @SuppressLint("SourceLockedOrientationActivity")
+ private fun forcePortraitIfLandscape() {
+ val activity = context as? Activity ?: return
+ if (resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
+ activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
+ }
+ }
+
+ private fun onScreenSharerChanged(newSharerID: String?) {
+ if (currentScreenSharerID == newSharerID) {
+ return
+ }
+ currentScreenSharerID = newSharerID
+ updateOrientationSwitchButtonVisibility()
+ if (newSharerID.isNullOrEmpty()) {
+ forcePortraitIfLandscape()
+ }
+ }
+
fun isAISubtitleVisible(): Boolean {
return aiSubtitleView.visibility == VISIBLE
}
diff --git a/room/tuiroomkit/src/main/java/com/trtc/uikit/roomkit/view/main/roomview/PagedVideoLayoutManager.kt b/room/tuiroomkit/src/main/java/com/trtc/uikit/roomkit/view/main/roomview/PagedVideoLayoutManager.kt
index 939e9cac..e1ce8594 100644
--- a/room/tuiroomkit/src/main/java/com/trtc/uikit/roomkit/view/main/roomview/PagedVideoLayoutManager.kt
+++ b/room/tuiroomkit/src/main/java/com/trtc/uikit/roomkit/view/main/roomview/PagedVideoLayoutManager.kt
@@ -1,5 +1,6 @@
package com.trtc.uikit.roomkit.view.main.roomview
+import android.content.res.Configuration
import android.graphics.PointF
import android.view.View
import android.view.ViewGroup
@@ -71,6 +72,7 @@ class PagedVideoLayoutManager(
private var scrollState = RecyclerView.SCROLL_STATE_IDLE
private var lastSpeakerMode = false
+ private var attachedRecyclerView: RecyclerView? = null
override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
val params = RecyclerView.LayoutParams(
@@ -82,7 +84,11 @@ class PagedVideoLayoutManager(
return params
}
- override fun canScrollHorizontally(): Boolean = true
+ override fun canScrollHorizontally(): Boolean {
+ val orientation = attachedRecyclerView?.resources?.configuration?.orientation
+ ?: Configuration.ORIENTATION_PORTRAIT
+ return orientation != Configuration.ORIENTATION_LANDSCAPE
+ }
override fun onLayoutChildren(recycler: RecyclerView.Recycler, state: RecyclerView.State) {
if (state.isPreLayout) return
@@ -118,6 +124,7 @@ class PagedVideoLayoutManager(
override fun onAttachedToWindow(view: RecyclerView) {
super.onAttachedToWindow(view)
cachedAdapter = view.adapter
+ attachedRecyclerView = view
// Listen to scroll state changes
view.addOnScrollListener(object : RecyclerView.OnScrollListener() {
@@ -127,6 +134,11 @@ class PagedVideoLayoutManager(
})
}
+ override fun onDetachedFromWindow(view: RecyclerView, recycler: RecyclerView.Recycler) {
+ super.onDetachedFromWindow(view, recycler)
+ attachedRecyclerView = null
+ }
+
/**
* Check if speaker mode is active
* Speaker mode is ON when first item is screen share stream
diff --git a/room/tuiroomkit/src/main/res/drawable-xxhdpi/roomkit_ic_switch_landscape_button.png b/room/tuiroomkit/src/main/res/drawable-xxhdpi/roomkit_ic_switch_landscape_button.png
new file mode 100644
index 00000000..ab3cc42c
Binary files /dev/null and b/room/tuiroomkit/src/main/res/drawable-xxhdpi/roomkit_ic_switch_landscape_button.png differ
diff --git a/room/tuiroomkit/src/main/res/drawable-xxhdpi/roomkit_ic_switch_portrait_button.png b/room/tuiroomkit/src/main/res/drawable-xxhdpi/roomkit_ic_switch_portrait_button.png
new file mode 100644
index 00000000..449308e4
Binary files /dev/null and b/room/tuiroomkit/src/main/res/drawable-xxhdpi/roomkit_ic_switch_portrait_button.png differ
diff --git a/room/tuiroomkit/src/main/res/layout/roomkit_main_view.xml b/room/tuiroomkit/src/main/res/layout/roomkit_main_view.xml
index 0ea6b93d..b3e82cff 100644
--- a/room/tuiroomkit/src/main/res/layout/roomkit_main_view.xml
+++ b/room/tuiroomkit/src/main/res/layout/roomkit_main_view.xml
@@ -1,6 +1,7 @@
@@ -22,6 +23,17 @@
app:layout_constraintTop_toBottomOf="@id/room_top_bar"
app:layout_constraintVertical_weight="1" />
+
+