mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 11:39:42 +01:00
calculate item height
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
2741f5962a
commit
ecf6d362bf
@ -11,24 +11,26 @@ import android.content.res.Configuration
|
|||||||
import androidx.compose.foundation.clickable
|
import androidx.compose.foundation.clickable
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Box
|
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.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
|
||||||
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
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.GridCells
|
||||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||||
import androidx.compose.foundation.lazy.grid.items
|
import androidx.compose.foundation.lazy.grid.items
|
||||||
import androidx.compose.foundation.lazy.items
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
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
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ParticipantGrid(
|
fun ParticipantGrid(
|
||||||
@ -69,43 +71,37 @@ fun ParticipantGrid(
|
|||||||
|
|
||||||
2, 3 -> {
|
2, 3 -> {
|
||||||
if (isPortrait) {
|
if (isPortrait) {
|
||||||
LazyColumn(
|
Column(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(vertical = 4.dp)
|
.padding(vertical = 4.dp)
|
||||||
.clickable { onClick() },
|
.clickable { onClick() },
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
verticalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
) {
|
) {
|
||||||
items(
|
participants.forEach {
|
||||||
items = participants,
|
|
||||||
key = { it.sessionKey }
|
|
||||||
) { participant ->
|
|
||||||
ParticipantTile(
|
ParticipantTile(
|
||||||
participant = participant,
|
participant = it,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.weight(1f)
|
||||||
.aspectRatio(1.5f),
|
.fillMaxWidth(),
|
||||||
eglBase = eglBase
|
eglBase = eglBase
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
LazyRow(
|
Row(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(horizontal = 4.dp)
|
.padding(horizontal = 4.dp)
|
||||||
.clickable { onClick() },
|
.clickable { onClick() },
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||||
) {
|
) {
|
||||||
items(
|
participants.forEach {
|
||||||
items = participants,
|
|
||||||
key = { it.sessionKey }
|
|
||||||
) { participant ->
|
|
||||||
ParticipantTile(
|
ParticipantTile(
|
||||||
participant = participant,
|
participant = it,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxHeight()
|
.weight(1f)
|
||||||
.aspectRatio(1.5f),
|
.fillMaxHeight(),
|
||||||
eglBase = eglBase
|
eglBase = eglBase
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -114,24 +110,30 @@ fun ParticipantGrid(
|
|||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
|
val columns = if (isPortrait) 2 else 3
|
||||||
|
val rows = ceil(participants.size / columns.toFloat()).toInt()
|
||||||
|
val screenHeight = LocalConfiguration.current.screenHeightDp.dp
|
||||||
|
val rawItemHeight = screenHeight / rows
|
||||||
|
val itemHeight = max(rawItemHeight, 120.dp)
|
||||||
|
|
||||||
LazyVerticalGrid(
|
LazyVerticalGrid(
|
||||||
columns = GridCells.Fixed(if (isPortrait) 2 else 3),
|
columns = GridCells.Fixed(columns),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.padding(8.dp)
|
.padding(0.dp)
|
||||||
.clickable { onClick() },
|
.clickable { onClick() },
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
verticalArrangement = Arrangement.spacedBy(0.dp),
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
horizontalArrangement = Arrangement.spacedBy(0.dp)
|
||||||
) {
|
) {
|
||||||
items(
|
items(
|
||||||
participants.sortedBy { it.isAudioEnabled }.asReversed(),
|
participants,
|
||||||
key = { it.sessionKey }
|
key = { it.sessionKey }
|
||||||
) { participant ->
|
) { participant ->
|
||||||
ParticipantTile(
|
ParticipantTile(
|
||||||
participant = participant,
|
participant = participant,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.fillMaxWidth()
|
.height(itemHeight)
|
||||||
.aspectRatio(1.5f),
|
.fillMaxWidth(),
|
||||||
eglBase = eglBase
|
eglBase = eglBase
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -140,28 +142,67 @@ fun ParticipantGrid(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const val numberOfParticipants = 4
|
|
||||||
|
|
||||||
@Preview(
|
|
||||||
showBackground = false
|
@Preview
|
||||||
)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ParticipantGridPreview() {
|
fun ParticipantGridPreview() {
|
||||||
ParticipantGrid(
|
ParticipantGrid(
|
||||||
participants = getTestParticipants(numberOfParticipants),
|
participants = getTestParticipants(1),
|
||||||
eglBase = null
|
eglBase = null
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Preview(
|
@Preview
|
||||||
showBackground = false,
|
|
||||||
heightDp = 902,
|
|
||||||
widthDp = 434
|
|
||||||
)
|
|
||||||
@Composable
|
@Composable
|
||||||
fun ParticipantGridPreviewPortrait2() {
|
fun TwoParticipants() {
|
||||||
ParticipantGrid(
|
ParticipantGrid(
|
||||||
participants = getTestParticipants(numberOfParticipants),
|
participants = getTestParticipants(2),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun ThreeParticipants() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(3),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun FourParticipants() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(4),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun FiveParticipants() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(5),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun SevenParticipants() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(7),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview
|
||||||
|
@Composable
|
||||||
|
fun FiftyParticipants() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(50),
|
||||||
eglBase = null
|
eglBase = null
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
@ -172,9 +213,74 @@ fun ParticipantGridPreviewPortrait2() {
|
|||||||
widthDp = 800
|
widthDp = 800
|
||||||
)
|
)
|
||||||
@Composable
|
@Composable
|
||||||
fun ParticipantGridPreviewLandscape1() {
|
fun OneParticipantLandscape() {
|
||||||
ParticipantGrid(
|
ParticipantGrid(
|
||||||
participants = getTestParticipants(numberOfParticipants),
|
participants = getTestParticipants(1),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(
|
||||||
|
showBackground = false,
|
||||||
|
heightDp = 360,
|
||||||
|
widthDp = 800
|
||||||
|
)
|
||||||
|
@Composable
|
||||||
|
fun TwoParticipantsLandscape() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(2),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(
|
||||||
|
showBackground = false,
|
||||||
|
heightDp = 360,
|
||||||
|
widthDp = 800
|
||||||
|
)
|
||||||
|
@Composable
|
||||||
|
fun ThreeParticipantsLandscape() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(3),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(
|
||||||
|
showBackground = false,
|
||||||
|
heightDp = 360,
|
||||||
|
widthDp = 800
|
||||||
|
)
|
||||||
|
@Composable
|
||||||
|
fun FourParticipantsLandscape() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(4),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(
|
||||||
|
showBackground = false,
|
||||||
|
heightDp = 360,
|
||||||
|
widthDp = 800
|
||||||
|
)
|
||||||
|
@Composable
|
||||||
|
fun SevenParticipantsLandscape() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(7),
|
||||||
|
eglBase = null
|
||||||
|
) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Preview(
|
||||||
|
showBackground = false,
|
||||||
|
heightDp = 360,
|
||||||
|
widthDp = 800
|
||||||
|
)
|
||||||
|
@Composable
|
||||||
|
fun FiftyParticipantsLandscape() {
|
||||||
|
ParticipantGrid(
|
||||||
|
participants = getTestParticipants(50),
|
||||||
eglBase = null
|
eglBase = null
|
||||||
) {}
|
) {}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user