Skip to content

Commit

Permalink
chore: revert changes of #2245
Browse files Browse the repository at this point in the history
  • Loading branch information
ohassine committed Sep 22, 2023
1 parent b4f76b7 commit fd5ffeb
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,12 @@ private fun OngoingCallContent(
onSelfVideoPreviewCreated = setVideoPreview,
onSelfClearVideoPreview = clearVideoPreview,
requestVideoStreams = requestVideoStreams,
onDoubleTap = { selectedParticipant ->
selectedParticipantForFullScreen = selectedParticipant
onDoubleTap = { selectedUserId, selectedClientId, isSelf ->
selectedParticipantForFullScreen = SelectedParticipant(
userId = selectedUserId,
clientId = selectedClientId,
isSelfUser = isSelf
)
shouldOpenFullScreen = !shouldOpenFullScreen
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ fun FullScreenTile(
),
participantTitleState = it,
isSelfUser = selectedParticipant.isSelfUser,
isSelfUserCameraOn = selectedParticipant.isSelfUserCameraOn,
isSelfUserMuted = selectedParticipant.isSelfUserMuted,
shouldFill = false,
isZoomingEnabled = true,
onSelfUserVideoPreviewCreated = sharedCallingViewModel::setVideoPreview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,5 @@ import com.wire.kalium.logic.data.user.UserId
data class SelectedParticipant(
val userId: UserId = UserId("", ""),
val clientId: String = "",
val isSelfUser: Boolean = false,
val isSelfUserCameraOn: Boolean = false,
val isSelfUserMuted: Boolean = false
val isSelfUser: Boolean = false
)
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@ fun ParticipantTile(
isSelfUser: Boolean,
shouldFill: Boolean = true,
isZoomingEnabled: Boolean = false,
isSelfUserMuted: Boolean,
isSelfUserCameraOn: Boolean,
onSelfUserVideoPreviewCreated: (view: View) -> Unit,
onClearSelfUserVideoPreview: () -> Unit
) {
Expand All @@ -113,7 +111,7 @@ fun ParticipantTile(

if (isSelfUser) {
CameraPreview(
isCameraOn = isSelfUserCameraOn,
isCameraOn = participantTitleState.isCameraOn,
onSelfUserVideoPreviewCreated = onSelfUserVideoPreviewCreated,
onClearSelfUserVideoPreview = onClearSelfUserVideoPreview
)
Expand All @@ -138,7 +136,7 @@ fun ParticipantTile(
bottom.linkTo(parent.bottom)
start.linkTo(parent.start)
},
isMuted = if (isSelfUser) isSelfUserMuted else participantTitleState.isMuted,
isMuted = participantTitleState.isMuted,
)

UsernameTile(
Expand Down Expand Up @@ -206,18 +204,12 @@ private fun CameraPreview(
) {
if (isCameraOn) {
val context = LocalContext.current
val videoPreview = remember {
VideoPreview(context).apply {
layoutParams = FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)
AndroidView(factory = {
val videoPreview = VideoPreview(context).apply {
setShouldFill(false)
}
}
AndroidView(
factory = { videoPreview },
update = {
onSelfUserVideoPreviewCreated(videoPreview)
}
)
}.also(onSelfUserVideoPreviewCreated)
videoPreview
})
} else {
onClearSelfUserVideoPreview()
}
Expand All @@ -238,7 +230,8 @@ private fun OthersVideoRenderer(
var offsetY by remember { mutableStateOf(0f) }

val context = LocalContext.current
val rendererFillColor = (colorsScheme().callingParticipantTileBackgroundColor.value shr 32).toLong()
val rendererFillColor =
(colorsScheme().callingParticipantTileBackgroundColor.value shr 32).toLong()
if (isCameraOn || isSharingScreen) {

val videoRenderer = remember {
Expand Down Expand Up @@ -372,9 +365,7 @@ fun PreviewParticipantTile() {
),
onClearSelfUserVideoPreview = {},
onSelfUserVideoPreviewCreated = {},
isSelfUser = false,
isSelfUserMuted = false,
isSelfUserCameraOn = false
isSelfUser = false
)
}

Expand All @@ -396,9 +387,7 @@ fun PreviewParticipantTalking() {
),
onClearSelfUserVideoPreview = {},
onSelfUserVideoPreviewCreated = {},
isSelfUser = false,
isSelfUserMuted = false,
isSelfUserCameraOn = false
isSelfUser = false
)
}

Expand All @@ -422,8 +411,6 @@ fun PreviewParticipantConnecting() {
),
onClearSelfUserVideoPreview = {},
onSelfUserVideoPreviewCreated = {},
isSelfUser = false,
isSelfUserMuted = false,
isSelfUserCameraOn = false
isSelfUser = false
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.wire.android.ui.calling.model.UICallParticipant
import com.wire.android.ui.calling.ongoing.fullscreen.SelectedParticipant
import com.wire.android.ui.calling.ongoing.participantsview.gridview.GroupCallGrid
import com.wire.android.ui.calling.ongoing.participantsview.horizentalview.CallingHorizontalView
import com.wire.android.ui.common.colorsScheme
import com.wire.android.ui.common.dimensions
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 @@ -65,7 +65,7 @@ fun VerticalCallingPager(
onSelfVideoPreviewCreated: (view: View) -> Unit,
onSelfClearVideoPreview: () -> Unit,
requestVideoStreams: (participants: List<UICallParticipant>) -> Unit,
onDoubleTap: (selectedParticipant: SelectedParticipant) -> Unit
onDoubleTap: (userId: UserId, clientId: String, isSelfUser: Boolean) -> Unit
) {
Column(
modifier = Modifier
Expand All @@ -82,9 +82,7 @@ fun VerticalCallingPager(
) { pageIndex ->
if (participants.isNotEmpty()) {

val participantsChunkedList = remember(participants) {
participants.chunked(MAX_TILES_PER_PAGE)
}
val participantsChunkedList = participants.chunked(MAX_TILES_PER_PAGE)
val participantsWithCameraOn by rememberUpdatedState(participants.count { it.isCameraOn })
val participantsWithScreenShareOn by rememberUpdatedState(participants.count { it.isSharingScreen })

Expand All @@ -103,11 +101,7 @@ fun VerticalCallingPager(
isSelfUserMuted = isSelfUserMuted,
isSelfUserCameraOn = isSelfUserCameraOn,
contentHeight = contentHeight,
onSelfVideoPreviewCreated = {
if (pagerState.currentPage == 0) {
onSelfVideoPreviewCreated(it)
}
},
onSelfVideoPreviewCreated = onSelfVideoPreviewCreated,
onSelfClearVideoPreview = onSelfClearVideoPreview,
onDoubleTap = onDoubleTap
)
Expand All @@ -118,11 +112,7 @@ fun VerticalCallingPager(
isSelfUserMuted = isSelfUserMuted,
isSelfUserCameraOn = isSelfUserCameraOn,
contentHeight = contentHeight,
onSelfVideoPreviewCreated = {
if (pagerState.currentPage == 0) {
onSelfVideoPreviewCreated(it)
}
},
onSelfVideoPreviewCreated = onSelfVideoPreviewCreated,
onSelfClearVideoPreview = onSelfClearVideoPreview,
onDoubleTap = onDoubleTap
)
Expand Down Expand Up @@ -177,6 +167,6 @@ fun PreviewVerticalCallingPager() {
onSelfVideoPreviewCreated = {},
onSelfClearVideoPreview = {},
requestVideoStreams = {},
onDoubleTap = { }
onDoubleTap = { _, _, _ -> run {} }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import com.wire.android.ui.calling.ConversationName
import com.wire.android.ui.calling.getConversationName
import com.wire.android.ui.calling.model.UICallParticipant
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.home.conversationslist.model.Membership
import com.wire.android.ui.theme.wireDimensions
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.user.UserId

@OptIn(ExperimentalFoundationApi::class)
@Composable
Expand All @@ -57,7 +59,7 @@ fun GroupCallGrid(
contentHeight: Dp,
onSelfVideoPreviewCreated: (view: View) -> Unit,
onSelfClearVideoPreview: () -> Unit,
onDoubleTap: (selectedParticipant: SelectedParticipant) -> Unit
onDoubleTap: (userId: UserId, clientId: String, isSelfUser: Boolean) -> Unit
) {
val config = LocalConfiguration.current

Expand All @@ -76,53 +78,73 @@ fun GroupCallGrid(
) { 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
}
val isSelfUser = pageIndex == 0 && participants.first() == participant
// We need the number of tiles rows needed to calculate their height
val numberOfTilesRows = remember(participants.size) {
tilesRowsCount(participants.size)
}
val numberOfTilesRows = tilesRowsCount(participants.size)
val isCameraOn = if (isSelfUser) {
isSelfUserCameraOn
} else participant.isCameraOn
// for self user we don't need to get the muted value from participants list
// if we do, this will show visuals with some delay
val isMuted = if (isSelfUser) isSelfUserMuted
else participant.isMuted

// if we have more than 6 participants then we reduce avatar size
val userAvatarSize = if (participants.size <= 6 || config.screenHeightDp > MIN_SCREEN_HEIGHT) {
dimensions().onGoingCallUserAvatarSize
} else {
dimensions().onGoingCallUserAvatarMinimizedSize
}
val userAvatarSize =
if (participants.size <= 6 || config.screenHeightDp > MIN_SCREEN_HEIGHT) {
dimensions().onGoingCallUserAvatarSize
} else {
dimensions().onGoingCallUserAvatarMinimizedSize
}

val spacing4x = dimensions().spacing4x
val tileHeight = remember(numberOfTilesRows) {
(contentHeight - spacing4x) / numberOfTilesRows
}
val usernameString =
when (val conversationName = getConversationName(participant.name)) {
is ConversationName.Known -> conversationName.name
is ConversationName.Unknown -> stringResource(id = conversationName.resourceId)
}

val participantState = UICallParticipant(
id = participant.id,
clientId = participant.clientId,
name = usernameString,
isMuted = isMuted,
isSpeaking = participant.isSpeaking,
isCameraOn = isCameraOn,
isSharingScreen = participant.isSharingScreen,
avatar = participant.avatar,
membership = participant.membership
)
val tileHeight = (contentHeight - dimensions().spacing4x) / numberOfTilesRows

ParticipantTile(
modifier = Modifier
.pointerInput(isSelfUserCameraOn, isSelfUserMuted) {
.pointerInput(Unit) {
detectTapGestures(
onDoubleTap = {
onDoubleTap(
SelectedParticipant(
userId = participant.id,
clientId = participant.clientId,
isSelfUser = isSelfUser,
isSelfUserCameraOn = isSelfUserCameraOn,
isSelfUserMuted = isSelfUserMuted
)
participantState.id,
participantState.clientId,
isSelfUser
)
}
)
}
.height(tileHeight)
.animateItemPlacement(tween(durationMillis = 200)),
participantTitleState = participant,
participantTitleState = participantState,
onGoingCallTileUsernameMaxWidth = dimensions().onGoingCallTileUsernameMaxWidth,
avatarSize = userAvatarSize,
isSelfUser = isSelfUser,
isSelfUserMuted = isSelfUserMuted,
isSelfUserCameraOn = isSelfUserCameraOn,
onSelfUserVideoPreviewCreated = onSelfVideoPreviewCreated,
onClearSelfUserVideoPreview = onSelfClearVideoPreview
onSelfUserVideoPreviewCreated = {
if (isSelfUser) {
onSelfVideoPreviewCreated(it)
}
},
onClearSelfUserVideoPreview = {
if (isSelfUser) {
onSelfClearVideoPreview()
}
}
)
}
}
Expand Down Expand Up @@ -177,6 +199,6 @@ fun PreviewGroupCallGrid() {
isSelfUserCameraOn = false,
onSelfVideoPreviewCreated = { },
onSelfClearVideoPreview = { },
onDoubleTap = { }
onDoubleTap = { _, _, _ -> {} }
)
}
Loading

0 comments on commit fd5ffeb

Please sign in to comment.