Skip to content

Commit

Permalink
fix: black screen when last caller in a group #WPB-10652
Browse files Browse the repository at this point in the history
  • Loading branch information
damian-kaczmarek committed Oct 25, 2024
1 parent 07b9e6b commit 505a18c
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ import com.wire.kalium.logic.data.call.CallStatus
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.user.UserId
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.collections.immutable.toPersistentList
Expand Down Expand Up @@ -161,6 +162,7 @@ fun OngoingCallScreen(
}
}

val inPictureInPictureMode = activity.isInPictureInPictureMode
OngoingCallContent(
callState = sharedCallingViewModel.callState,
shouldShowDoubleTapToast = ongoingCallViewModel.shouldShowDoubleTapToast,
Expand All @@ -175,7 +177,9 @@ fun OngoingCallScreen(
requestVideoStreams = ongoingCallViewModel::requestVideoStreams,
hideDoubleTapToast = ongoingCallViewModel::hideDoubleTapToast,
onCameraPermissionPermanentlyDenied = onCameraPermissionPermanentlyDenied,
participants = sharedCallingViewModel.participantsState
participants = sharedCallingViewModel.participantsState,
inPictureInPictureMode = inPictureInPictureMode,
currentUserId = ongoingCallViewModel.currentUserId,
)

BackHandler {
Expand Down Expand Up @@ -283,10 +287,10 @@ private fun OngoingCallContent(
hideDoubleTapToast: () -> Unit,
onCameraPermissionPermanentlyDenied: () -> Unit,
requestVideoStreams: (participants: List<UICallParticipant>) -> Unit,
participants: PersistentList<UICallParticipant>
participants: PersistentList<UICallParticipant>,
inPictureInPictureMode: Boolean,
currentUserId: UserId,
) {
val activity = LocalActivity.current

val sheetInitialValue = SheetValue.PartiallyExpanded
val sheetState = rememberStandardBottomSheetState(
initialValue = sheetInitialValue
Expand All @@ -301,7 +305,7 @@ private fun OngoingCallContent(

WireBottomSheetScaffold(
sheetDragHandle = null,
topBar = if (activity.isInPictureInPictureMode) {
topBar = if (inPictureInPictureMode) {
null
} else {
{
Expand All @@ -319,10 +323,10 @@ private fun OngoingCallContent(
)
}
},
sheetPeekHeight = if (activity.isInPictureInPictureMode) 0.dp else dimensions().defaultSheetPeekHeight,
sheetPeekHeight = if (inPictureInPictureMode) 0.dp else dimensions().defaultSheetPeekHeight,
scaffoldState = scaffoldState,
sheetContent = {
if (!activity.isInPictureInPictureMode) {
if (!inPictureInPictureMode) {
CallingControls(
conversationId = callState.conversationId,
isMuted = callState.isMuted ?: true,
Expand All @@ -343,7 +347,7 @@ private fun OngoingCallContent(
modifier = Modifier
.padding(
top = it.calculateTopPadding(),
bottom = if (activity.isInPictureInPictureMode) 0.dp else dimensions().defaultSheetPeekHeight
bottom = if (inPictureInPictureMode) 0.dp else dimensions().defaultSheetPeekHeight
)
) {

Expand Down Expand Up @@ -399,14 +403,16 @@ private fun OngoingCallContent(
participants = participants,
isSelfUserCameraOn = callState.isCameraOn,
isSelfUserMuted = callState.isMuted ?: true,
isInPictureInPictureMode = inPictureInPictureMode,
contentHeight = this@BoxWithConstraints.maxHeight,
onSelfVideoPreviewCreated = setVideoPreview,
onSelfClearVideoPreview = clearVideoPreview,
requestVideoStreams = requestVideoStreams,
currentUserId = currentUserId,
onDoubleTap = { selectedParticipant ->
selectedParticipantForFullScreen = selectedParticipant
shouldOpenFullScreen = !shouldOpenFullScreen
}
},
)
DoubleTapToast(
modifier = Modifier.align(Alignment.TopCenter),
Expand All @@ -417,11 +423,16 @@ private fun OngoingCallContent(
}
}
if (BuildConfig.PICTURE_IN_PICTURE_ENABLED && participants.size > 1) {
val selfUser =
participants.first { participant ->
// API returns only id.value, without domain, till this get changed compare only id.value
participant.id.equalsIgnoringBlankDomain(currentUserId)
}
FloatingSelfUserTile(
modifier = Modifier.align(Alignment.TopEnd),
contentHeight = this@BoxWithConstraints.maxHeight,
contentWidth = this@BoxWithConstraints.maxWidth,
participant = participants.first(),
participant = selfUser,
onSelfUserVideoPreviewCreated = setVideoPreview,
onClearSelfUserVideoPreview = clearVideoPreview
)
Expand Down Expand Up @@ -565,7 +576,9 @@ fun PreviewOngoingCallContent(participants: PersistentList<UICallParticipant>) {
hideDoubleTapToast = {},
onCameraPermissionPermanentlyDenied = {},
requestVideoStreams = {},
participants = participants
participants = participants,
inPictureInPictureMode = false,
currentUserId = UserId("userId", "domain"),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.wire.android.BuildConfig
import com.wire.android.ui.LocalActivity
import com.wire.android.ui.calling.model.UICallParticipant
import com.wire.android.ui.calling.ongoing.buildPreviewParticipantsList
import com.wire.android.ui.calling.ongoing.fullscreen.SelectedParticipant
Expand All @@ -52,6 +51,7 @@ import com.wire.android.ui.common.dimensions
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.kalium.logic.data.user.UserId

private const val MAX_TILES_PER_PAGE = 8
private const val MAX_ITEMS_FOR_HORIZONTAL_VIEW = 3
Expand All @@ -61,15 +61,15 @@ fun VerticalCallingPager(
participants: List<UICallParticipant>,
isSelfUserMuted: Boolean,
isSelfUserCameraOn: Boolean,
isInPictureInPictureMode: Boolean,
contentHeight: Dp,
currentUserId: UserId,
onSelfVideoPreviewCreated: (view: View) -> Unit,
onSelfClearVideoPreview: () -> Unit,
requestVideoStreams: (participants: List<UICallParticipant>) -> Unit,
onDoubleTap: (selectedParticipant: SelectedParticipant) -> Unit,
modifier: Modifier = Modifier,
) {
val activity = LocalActivity.current

Column(
modifier = modifier
.fillMaxWidth()
Expand Down Expand Up @@ -101,13 +101,13 @@ fun VerticalCallingPager(
if (participantsChunkedList[pageIndex].size <= MAX_ITEMS_FOR_HORIZONTAL_VIEW) {
CallingHorizontalView(
participants = participantsChunkedList[pageIndex],
pageIndex = pageIndex,
isSelfUserMuted = isSelfUserMuted,
isSelfUserCameraOn = isSelfUserCameraOn,
contentHeight = contentHeight,
onSelfVideoPreviewCreated = onSelfVideoPreviewCreated,
onSelfClearVideoPreview = onSelfClearVideoPreview,
onDoubleTap = onDoubleTap
onDoubleTap = onDoubleTap,
currentUserId = currentUserId,
)
} else {
GroupCallGrid(
Expand All @@ -118,7 +118,8 @@ fun VerticalCallingPager(
contentHeight = contentHeight,
onSelfVideoPreviewCreated = onSelfVideoPreviewCreated,
onSelfClearVideoPreview = onSelfClearVideoPreview,
onDoubleTap = onDoubleTap
onDoubleTap = onDoubleTap,
currentUserId = currentUserId,
)
}

Expand All @@ -132,7 +133,7 @@ fun VerticalCallingPager(
}
}
// we don't need to display the indicator if we have one page and when it's in PiP mode
if (pagesCount(participants.size) > 1 && !activity.isInPictureInPictureMode) {
if (pagesCount(participants.size) > 1 && !isInPictureInPictureMode) {
Surface(
shape = RoundedCornerShape(dimensions().corner16x),
modifier = Modifier
Expand Down Expand Up @@ -165,7 +166,9 @@ private fun pagesCount(size: Int): Int {
val pages = size / MAX_TILES_PER_PAGE
return if (size % MAX_TILES_PER_PAGE > 0) {
pages + 1
} else pages
} else {
pages
}
}

@Composable
Expand All @@ -178,7 +181,9 @@ private fun PreviewVerticalCallingPager(participants: List<UICallParticipant>) {
onSelfVideoPreviewCreated = {},
onSelfClearVideoPreview = {},
requestVideoStreams = {},
onDoubleTap = { }
onDoubleTap = { },
isInPictureInPictureMode = false,
currentUserId = UserId("id", "domain")
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.times
import com.wire.android.BuildConfig
import com.wire.android.ui.LocalActivity
import com.wire.android.ui.calling.model.UICallParticipant
import com.wire.android.ui.calling.ongoing.buildPreviewParticipantsList
Expand All @@ -43,6 +42,7 @@ import com.wire.android.ui.calling.ongoing.participantsview.ParticipantTile
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.kalium.logic.data.user.UserId

@Composable
fun GroupCallGrid(
Expand All @@ -51,6 +51,7 @@ fun GroupCallGrid(
isSelfUserMuted: Boolean,
isSelfUserCameraOn: Boolean,
contentHeight: Dp,
currentUserId: UserId,
onSelfVideoPreviewCreated: (view: View) -> Unit,
onSelfClearVideoPreview: () -> Unit,
onDoubleTap: (selectedParticipant: SelectedParticipant) -> Unit,
Expand Down Expand Up @@ -82,11 +83,8 @@ fun GroupCallGrid(
key = { it.id.toString() + it.clientId + pageIndex },
contentType = { getContentType(it.isCameraOn, it.isSharingScreen) }
) { participant ->
// since we are getting participants by chunk of 8 items,
// we need to check that we are on first page for self user
val isSelfUser = remember(pageIndex, participants.first()) {
pageIndex == 0 && participants.first() == participant && !BuildConfig.PICTURE_IN_PICTURE_ENABLED
}
// API returns only id.value, without domain, till this get changed compare only id.value
val isSelfUser = participant.id.equalsIgnoringBlankDomain(currentUserId)

ParticipantTile(
modifier = Modifier
Expand Down Expand Up @@ -142,7 +140,8 @@ private fun PreviewGroupCallGrid(participants: List<UICallParticipant>, modifier
contentHeight = 800.dp,
onSelfVideoPreviewCreated = {},
onSelfClearVideoPreview = {},
onDoubleTap = { }
onDoubleTap = { },
currentUserId = UserId("id", "domain")
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.times
import com.wire.android.BuildConfig
import com.wire.android.ui.calling.model.UICallParticipant
import com.wire.android.ui.calling.ongoing.buildPreviewParticipantsList
import com.wire.android.ui.calling.ongoing.fullscreen.SelectedParticipant
import com.wire.android.ui.calling.ongoing.participantsview.ParticipantTile
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.theme.WireTheme
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.kalium.logic.data.user.UserId

@Composable
fun CallingHorizontalView(
participants: List<UICallParticipant>,
pageIndex: Int,
isSelfUserMuted: Boolean,
isSelfUserCameraOn: Boolean,
contentHeight: Dp,
currentUserId: UserId,
onSelfVideoPreviewCreated: (view: View) -> Unit,
onSelfClearVideoPreview: () -> Unit,
onDoubleTap: (selectedParticipant: SelectedParticipant) -> Unit,
Expand All @@ -58,7 +58,8 @@ fun CallingHorizontalView(
spacedBy: Dp = dimensions().spacing2x,
) {
val tileHeight = remember(participants.size, contentHeight, contentPadding, spacedBy) {
val heightAvailableForItems = contentHeight - 2 * contentPadding - (participants.size - 1) * spacedBy
val heightAvailableForItems =
contentHeight - 2 * contentPadding - (participants.size - 1) * spacedBy
heightAvailableForItems / participants.size
}
LazyColumn(
Expand All @@ -68,11 +69,8 @@ fun CallingHorizontalView(
verticalArrangement = Arrangement.spacedBy(spacedBy)
) {
items(items = participants, key = { it.id.toString() + it.clientId }) { participant ->
// since we are getting participants by chunk of 8 items,
// we need to check that we are on first page for self user
val isSelfUser = remember(pageIndex, participants.first()) {
pageIndex == 0 && participants.first() == participant && !BuildConfig.PICTURE_IN_PICTURE_ENABLED
}
// API returns only id.value, without domain, till this get changed compare only id.value
val isSelfUser = participant.id.equalsIgnoringBlankDomain(currentUserId)
ParticipantTile(
modifier = Modifier
.pointerInput(Unit) {
Expand All @@ -96,24 +94,27 @@ fun CallingHorizontalView(
isSelfUserMuted = isSelfUserMuted,
isSelfUserCameraOn = isSelfUserCameraOn,
onSelfUserVideoPreviewCreated = onSelfVideoPreviewCreated,
onClearSelfUserVideoPreview = onSelfClearVideoPreview
onClearSelfUserVideoPreview = onSelfClearVideoPreview,
)
}
}
}

@Composable
fun PreviewCallingHorizontalView(participants: List<UICallParticipant>, modifier: Modifier = Modifier) {
fun PreviewCallingHorizontalView(
participants: List<UICallParticipant>,
modifier: Modifier = Modifier,
) {
Box(modifier = modifier.height(800.dp)) {
CallingHorizontalView(
participants = participants,
pageIndex = 0,
isSelfUserMuted = true,
isSelfUserCameraOn = false,
contentHeight = 800.dp,
currentUserId = UserId("id", "domain"),
onSelfVideoPreviewCreated = {},
onSelfClearVideoPreview = {},
onDoubleTap = { }
onDoubleTap = { },
)
}
}
Expand Down

0 comments on commit 505a18c

Please sign in to comment.