mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 11:39:42 +01:00
simplify grid cell calculation
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
bcb276d533
commit
15d7c8371c
@ -14,7 +14,6 @@ import androidx.compose.foundation.layout.Box
|
|||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.foundation.layout.PaddingValues
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.aspectRatio
|
|
||||||
import androidx.compose.foundation.layout.fillMaxHeight
|
import androidx.compose.foundation.layout.fillMaxHeight
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
import androidx.compose.foundation.layout.fillMaxSize
|
||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
@ -28,7 +27,6 @@ import androidx.compose.ui.Modifier
|
|||||||
import androidx.compose.ui.platform.LocalConfiguration
|
import androidx.compose.ui.platform.LocalConfiguration
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.compose.ui.unit.dp
|
import androidx.compose.ui.unit.dp
|
||||||
import androidx.compose.ui.unit.max
|
|
||||||
import com.nextcloud.talk.call.ParticipantUiState
|
import com.nextcloud.talk.call.ParticipantUiState
|
||||||
import org.webrtc.EglBase
|
import org.webrtc.EglBase
|
||||||
import kotlin.math.ceil
|
import kotlin.math.ceil
|
||||||
@ -42,118 +40,58 @@ fun ParticipantGrid(
|
|||||||
) {
|
) {
|
||||||
val configuration = LocalConfiguration.current
|
val configuration = LocalConfiguration.current
|
||||||
val isPortrait = configuration.orientation == Configuration.ORIENTATION_PORTRAIT
|
val isPortrait = configuration.orientation == Configuration.ORIENTATION_PORTRAIT
|
||||||
|
val columns =
|
||||||
// Experimental: sort participants by audio/video enabled. Maybe only do this for many participants??
|
if (isPortrait) {
|
||||||
//
|
when (participants.size) {
|
||||||
// val sortedParticipants = remember(participants) {
|
1, 2, 3 -> 1
|
||||||
// participants.sortedWith(
|
else -> 2
|
||||||
// compareByDescending<ParticipantUiState> { it.isAudioEnabled && it.isStreamEnabled }
|
}
|
||||||
// .thenByDescending { it.isAudioEnabled }
|
} else {
|
||||||
// .thenByDescending { it.isStreamEnabled }
|
when (participants.size) {
|
||||||
// )
|
1 -> 1
|
||||||
// }
|
2 -> 2
|
||||||
|
else -> 3
|
||||||
when (participants.size) {
|
|
||||||
0 -> {}
|
|
||||||
1 -> {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
) {
|
|
||||||
ParticipantTile(
|
|
||||||
participant = participants[0],
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.clickable { onClick() },
|
|
||||||
eglBase = eglBase
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
2, 3 -> {
|
val rows = ceil(participants.size / columns.toFloat()).toInt()
|
||||||
if (isPortrait) {
|
|
||||||
Column(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(vertical = 4.dp)
|
|
||||||
.clickable { onClick() },
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
participants.forEach {
|
|
||||||
ParticipantTile(
|
|
||||||
participant = it,
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.fillMaxWidth(),
|
|
||||||
eglBase = eglBase
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Row(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.padding(horizontal = 4.dp)
|
|
||||||
.clickable { onClick() },
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
participants.forEach {
|
|
||||||
ParticipantTile(
|
|
||||||
participant = it,
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.fillMaxHeight(),
|
|
||||||
eglBase = eglBase
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
else -> {
|
val screenHeight = LocalConfiguration.current.screenHeightDp.dp
|
||||||
val columns = if (isPortrait) 2 else 3
|
val itemSpacing = 8.dp
|
||||||
val rows = ceil(participants.size / columns.toFloat()).toInt()
|
val edgePadding = 8.dp
|
||||||
|
|
||||||
val screenHeight = LocalConfiguration.current.screenHeightDp.dp
|
val totalVerticalSpacing = itemSpacing * (rows - 1)
|
||||||
val itemSpacing = 8.dp
|
val totalVerticalPadding = edgePadding * 2
|
||||||
val edgePadding = 8.dp
|
val availableHeight = screenHeight - totalVerticalSpacing - totalVerticalPadding
|
||||||
|
|
||||||
val totalVerticalSpacing = itemSpacing * (rows - 1)
|
val rawItemHeight = availableHeight / rows
|
||||||
val totalVerticalPadding = edgePadding * 2
|
val itemHeight = maxOf(rawItemHeight, 100.dp)
|
||||||
val availableHeight = screenHeight - totalVerticalSpacing - totalVerticalPadding
|
|
||||||
|
|
||||||
val rawItemHeight = availableHeight / rows
|
LazyVerticalGrid(
|
||||||
val itemHeight = maxOf(rawItemHeight, 100.dp)
|
columns = GridCells.Fixed(columns),
|
||||||
|
modifier = Modifier
|
||||||
LazyVerticalGrid(
|
.fillMaxSize()
|
||||||
columns = GridCells.Fixed(columns),
|
.padding(horizontal = edgePadding) // Only horizontal outer padding here
|
||||||
|
.clickable { onClick() },
|
||||||
|
verticalArrangement = Arrangement.spacedBy(itemSpacing),
|
||||||
|
horizontalArrangement = Arrangement.spacedBy(itemSpacing),
|
||||||
|
contentPadding = PaddingValues(vertical = edgePadding) // vertical padding handled here
|
||||||
|
) {
|
||||||
|
items(
|
||||||
|
participants.sortedBy { it.isAudioEnabled }.asReversed(),
|
||||||
|
key = { it.sessionKey }
|
||||||
|
) { participant ->
|
||||||
|
ParticipantTile(
|
||||||
|
participant = participant,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.height(itemHeight)
|
||||||
.padding(horizontal = edgePadding) // Only horizontal outer padding here
|
.fillMaxWidth(),
|
||||||
.clickable { onClick() },
|
eglBase = eglBase
|
||||||
verticalArrangement = Arrangement.spacedBy(itemSpacing),
|
)
|
||||||
horizontalArrangement = Arrangement.spacedBy(itemSpacing),
|
|
||||||
contentPadding = PaddingValues(vertical = edgePadding) // vertical padding handled here
|
|
||||||
) {
|
|
||||||
items(
|
|
||||||
participants.sortedBy { it.isAudioEnabled }.asReversed(),
|
|
||||||
key = { it.sessionKey }
|
|
||||||
) { participant ->
|
|
||||||
ParticipantTile(
|
|
||||||
participant = participant,
|
|
||||||
modifier = Modifier
|
|
||||||
.height(itemHeight)
|
|
||||||
.fillMaxWidth(),
|
|
||||||
eglBase = eglBase
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
fun ParticipantGridPreview() {
|
fun ParticipantGridPreview() {
|
||||||
|
Loading…
Reference in New Issue
Block a user