From 2741f5962a2fe978f5eac664f75d7b37da27383a Mon Sep 17 00:00:00 2001 From: Marcel Hibbe Date: Tue, 6 May 2025 18:55:50 +0200 Subject: [PATCH] sort participants by audio/video (experimental, commented out) Signed-off-by: Marcel Hibbe --- .../talk/call/components/ParticipantGrid.kt | 46 +++++++++++++------ 1 file changed, 33 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/nextcloud/talk/call/components/ParticipantGrid.kt b/app/src/main/java/com/nextcloud/talk/call/components/ParticipantGrid.kt index f3d750b50..b2a465ed4 100644 --- a/app/src/main/java/com/nextcloud/talk/call/components/ParticipantGrid.kt +++ b/app/src/main/java/com/nextcloud/talk/call/components/ParticipantGrid.kt @@ -11,16 +11,17 @@ import android.content.res.Configuration import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyRow import androidx.compose.foundation.lazy.grid.GridCells import androidx.compose.foundation.lazy.grid.LazyVerticalGrid import androidx.compose.foundation.lazy.grid.items +import androidx.compose.foundation.lazy.items import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration @@ -39,6 +40,16 @@ fun ParticipantGrid( val configuration = LocalConfiguration.current val isPortrait = configuration.orientation == Configuration.ORIENTATION_PORTRAIT + // Experimental: sort participants by audio/video enabled. Maybe only do this for many participants?? + // + // val sortedParticipants = remember(participants) { + // participants.sortedWith( + // compareByDescending { it.isAudioEnabled && it.isStreamEnabled } + // .thenByDescending { it.isAudioEnabled } + // .thenByDescending { it.isStreamEnabled } + // ) + // } + when (participants.size) { 0 -> {} 1 -> { @@ -58,37 +69,43 @@ fun ParticipantGrid( 2, 3 -> { if (isPortrait) { - Column( + LazyColumn( modifier = Modifier .fillMaxSize() .padding(vertical = 4.dp) .clickable { onClick() }, verticalArrangement = Arrangement.spacedBy(8.dp) ) { - participants.forEach { + items( + items = participants, + key = { it.sessionKey } + ) { participant -> ParticipantTile( - participant = it, + participant = participant, modifier = Modifier - .weight(1f) - .fillMaxWidth(), + .fillMaxWidth() + .aspectRatio(1.5f), eglBase = eglBase ) } } } else { - Row( + LazyRow( modifier = Modifier .fillMaxSize() .padding(horizontal = 4.dp) .clickable { onClick() }, horizontalArrangement = Arrangement.spacedBy(8.dp) ) { - participants.forEach { + items( + items = participants, + key = { it.sessionKey } + ) { participant -> ParticipantTile( - participant = it, + participant = participant, modifier = Modifier - .weight(1f) - .fillMaxHeight(), + .fillMaxHeight() + .aspectRatio(1.5f), eglBase = eglBase ) } @@ -106,7 +123,10 @@ fun ParticipantGrid( verticalArrangement = Arrangement.spacedBy(8.dp), horizontalArrangement = Arrangement.spacedBy(8.dp) ) { - items(participants) { participant -> + items( + participants.sortedBy { it.isAudioEnabled }.asReversed(), + key = { it.sessionKey } + ) { participant -> ParticipantTile( participant = participant, modifier = Modifier