mirror of
https://github.com/nextcloud/talk-android
synced 2025-06-19 19:49:33 +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,76 +40,20 @@ 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??
|
|
||||||
//
|
|
||||||
// val sortedParticipants = remember(participants) {
|
|
||||||
// participants.sortedWith(
|
|
||||||
// compareByDescending<ParticipantUiState> { it.isAudioEnabled && it.isStreamEnabled }
|
|
||||||
// .thenByDescending { it.isAudioEnabled }
|
|
||||||
// .thenByDescending { it.isStreamEnabled }
|
|
||||||
// )
|
|
||||||
// }
|
|
||||||
|
|
||||||
when (participants.size) {
|
|
||||||
0 -> {}
|
|
||||||
1 -> {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
) {
|
|
||||||
ParticipantTile(
|
|
||||||
participant = participants[0],
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxSize()
|
|
||||||
.clickable { onClick() },
|
|
||||||
eglBase = eglBase
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
2, 3 -> {
|
|
||||||
if (isPortrait) {
|
if (isPortrait) {
|
||||||
Column(
|
when (participants.size) {
|
||||||
modifier = Modifier
|
1, 2, 3 -> 1
|
||||||
.fillMaxSize()
|
else -> 2
|
||||||
.padding(vertical = 4.dp)
|
|
||||||
.clickable { onClick() },
|
|
||||||
verticalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
participants.forEach {
|
|
||||||
ParticipantTile(
|
|
||||||
participant = it,
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.fillMaxWidth(),
|
|
||||||
eglBase = eglBase
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Row(
|
when (participants.size) {
|
||||||
modifier = Modifier
|
1 -> 1
|
||||||
.fillMaxSize()
|
2 -> 2
|
||||||
.padding(horizontal = 4.dp)
|
else -> 3
|
||||||
.clickable { onClick() },
|
|
||||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
|
||||||
) {
|
|
||||||
participants.forEach {
|
|
||||||
ParticipantTile(
|
|
||||||
participant = it,
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.fillMaxHeight(),
|
|
||||||
eglBase = eglBase
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
|
||||||
val columns = if (isPortrait) 2 else 3
|
|
||||||
val rows = ceil(participants.size / columns.toFloat()).toInt()
|
val rows = ceil(participants.size / columns.toFloat()).toInt()
|
||||||
|
|
||||||
val screenHeight = LocalConfiguration.current.screenHeightDp.dp
|
val screenHeight = LocalConfiguration.current.screenHeightDp.dp
|
||||||
@ -149,10 +91,6 @@ fun ParticipantGrid(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Preview
|
@Preview
|
||||||
@Composable
|
@Composable
|
||||||
|
Loading…
Reference in New Issue
Block a user