@@ -12,11 +12,11 @@ package com.nextcloud.talk.call.components
1212import android.content.res.Configuration
1313import androidx.compose.foundation.clickable
1414import androidx.compose.foundation.layout.Arrangement
15+ import androidx.compose.foundation.layout.BoxWithConstraints
1516import androidx.compose.foundation.layout.PaddingValues
1617import androidx.compose.foundation.layout.fillMaxSize
1718import androidx.compose.foundation.layout.fillMaxWidth
1819import androidx.compose.foundation.layout.height
19- import androidx.compose.foundation.layout.padding
2020import androidx.compose.foundation.lazy.grid.GridCells
2121import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
2222import androidx.compose.foundation.lazy.grid.items
@@ -36,71 +36,66 @@ fun ParticipantGrid(
3636 eglBase : EglBase ? ,
3737 participantUiStates : List <ParticipantUiState >,
3838 isVoiceOnlyCall : Boolean ,
39- isInPipMode : Boolean ,
4039 onClick : () -> Unit
4140) {
4241 val configuration = LocalConfiguration .current
4342 val isPortrait = configuration.orientation == Configuration .ORIENTATION_PORTRAIT
4443
4544 val minItemHeight = 100 .dp
4645
47- val columns =
48- if (isPortrait) {
49- when (participantUiStates.size) {
50- 1 , 2 , 3 -> 1
51- else -> 2
52- }
53- } else {
54- when (participantUiStates.size) {
55- 1 -> 1
56- 2 , 4 -> 2
57- else -> 3
58- }
59- }
60-
61- val rows = ceil(participantUiStates.size / columns.toFloat()).toInt()
46+ if (participantUiStates.isEmpty()) return
6247
63- val heightForNonGridComponents = if (isVoiceOnlyCall && ! isInPipMode) {
64- // this is a workaround for now. It should ~summarize the height of callInfosLinearLayout and callControls
65- // Once everything is migrated to jetpack, this workaround should be obsolete or solved in a better way
66- 240 .dp
48+ val columns = if (isPortrait) {
49+ when (participantUiStates.size) {
50+ 1 , 2 , 3 -> 1
51+ else -> 2
52+ }
6753 } else {
68- 0 .dp
69- }
54+ when (participantUiStates.size) {
55+ 1 -> 1
56+ 2 , 4 -> 2
57+ else -> 3
58+ }
59+ }.coerceAtLeast(1 ) // Prevent 0
60+
61+ val rows = ceil(participantUiStates.size / columns.toFloat()).toInt().coerceAtLeast(1 )
7062
71- val gridHeight = LocalConfiguration .current.screenHeightDp.dp - heightForNonGridComponents
7263 val itemSpacing = 8 .dp
7364 val edgePadding = 8 .dp
74-
7565 val totalVerticalSpacing = itemSpacing * (rows - 1 )
7666 val totalVerticalPadding = edgePadding * 2
77- val availableHeight = gridHeight - totalVerticalSpacing - totalVerticalPadding
78-
79- val rawItemHeight = availableHeight / rows
80- val itemHeight = maxOf(rawItemHeight, minItemHeight)
8167
82- LazyVerticalGrid (
83- columns = GridCells .Fixed (columns),
84- modifier = Modifier
68+ BoxWithConstraints (
69+ modifier = modifier
8570 .fillMaxSize()
86- .padding(horizontal = edgePadding)
87- .clickable { onClick() },
88- verticalArrangement = Arrangement .spacedBy(itemSpacing),
89- horizontalArrangement = Arrangement .spacedBy(itemSpacing),
90- contentPadding = PaddingValues (vertical = edgePadding)
71+ .clickable { onClick() }
9172 ) {
92- items(
93- participantUiStates,
94- key = { it.sessionKey }
95- ) { participant ->
96- ParticipantTile (
97- participantUiState = participant,
98- modifier = Modifier
99- .height(itemHeight)
100- .fillMaxWidth(),
101- eglBase = eglBase,
102- isVoiceOnlyCall = isVoiceOnlyCall
103- )
73+ val availableHeight = maxHeight
74+
75+ val gridAvailableHeight = availableHeight - totalVerticalSpacing - totalVerticalPadding
76+ val rawItemHeight = gridAvailableHeight / rows
77+ val itemHeight = maxOf(rawItemHeight, minItemHeight)
78+
79+ LazyVerticalGrid (
80+ columns = GridCells .Fixed (columns),
81+ modifier = Modifier .fillMaxSize(),
82+ verticalArrangement = Arrangement .spacedBy(itemSpacing),
83+ horizontalArrangement = Arrangement .spacedBy(itemSpacing),
84+ contentPadding = PaddingValues (vertical = edgePadding, horizontal = edgePadding)
85+ ) {
86+ items(
87+ participantUiStates,
88+ key = { it.sessionKey }
89+ ) { participant ->
90+ ParticipantTile (
91+ participantUiState = participant,
92+ modifier = Modifier
93+ .height(itemHeight)
94+ .fillMaxWidth(),
95+ eglBase = eglBase,
96+ isVoiceOnlyCall = isVoiceOnlyCall
97+ )
98+ }
10499 }
105100 }
106101}
@@ -111,8 +106,7 @@ fun ParticipantGridPreview() {
111106 ParticipantGrid (
112107 participantUiStates = getTestParticipants(1 ),
113108 eglBase = null ,
114- isVoiceOnlyCall = false ,
115- isInPipMode = false
109+ isVoiceOnlyCall = false
116110 ) {}
117111}
118112
@@ -122,8 +116,7 @@ fun TwoParticipants() {
122116 ParticipantGrid (
123117 participantUiStates = getTestParticipants(2 ),
124118 eglBase = null ,
125- isVoiceOnlyCall = false ,
126- isInPipMode = false
119+ isVoiceOnlyCall = false
127120 ) {}
128121}
129122
@@ -133,8 +126,7 @@ fun ThreeParticipants() {
133126 ParticipantGrid (
134127 participantUiStates = getTestParticipants(3 ),
135128 eglBase = null ,
136- isVoiceOnlyCall = false ,
137- isInPipMode = false
129+ isVoiceOnlyCall = false
138130 ) {}
139131}
140132
@@ -144,8 +136,7 @@ fun FourParticipants() {
144136 ParticipantGrid (
145137 participantUiStates = getTestParticipants(4 ),
146138 eglBase = null ,
147- isVoiceOnlyCall = false ,
148- isInPipMode = false
139+ isVoiceOnlyCall = false
149140 ) {}
150141}
151142
@@ -155,8 +146,7 @@ fun FiveParticipants() {
155146 ParticipantGrid (
156147 participantUiStates = getTestParticipants(5 ),
157148 eglBase = null ,
158- isVoiceOnlyCall = false ,
159- isInPipMode = false
149+ isVoiceOnlyCall = false
160150 ) {}
161151}
162152
@@ -166,8 +156,7 @@ fun SevenParticipants() {
166156 ParticipantGrid (
167157 participantUiStates = getTestParticipants(7 ),
168158 eglBase = null ,
169- isVoiceOnlyCall = false ,
170- isInPipMode = false
159+ isVoiceOnlyCall = false
171160 ) {}
172161}
173162
@@ -177,8 +166,7 @@ fun FiftyParticipants() {
177166 ParticipantGrid (
178167 participantUiStates = getTestParticipants(50 ),
179168 eglBase = null ,
180- isVoiceOnlyCall = false ,
181- isInPipMode = false
169+ isVoiceOnlyCall = false
182170 ) {}
183171}
184172
@@ -192,8 +180,7 @@ fun OneParticipantLandscape() {
192180 ParticipantGrid (
193181 participantUiStates = getTestParticipants(1 ),
194182 eglBase = null ,
195- isVoiceOnlyCall = false ,
196- isInPipMode = false
183+ isVoiceOnlyCall = false
197184 ) {}
198185}
199186
@@ -207,8 +194,7 @@ fun TwoParticipantsLandscape() {
207194 ParticipantGrid (
208195 participantUiStates = getTestParticipants(2 ),
209196 eglBase = null ,
210- isVoiceOnlyCall = false ,
211- isInPipMode = false
197+ isVoiceOnlyCall = false
212198 ) {}
213199}
214200
@@ -222,8 +208,7 @@ fun ThreeParticipantsLandscape() {
222208 ParticipantGrid (
223209 participantUiStates = getTestParticipants(3 ),
224210 eglBase = null ,
225- isVoiceOnlyCall = false ,
226- isInPipMode = false
211+ isVoiceOnlyCall = false
227212 ) {}
228213}
229214
@@ -237,8 +222,7 @@ fun FourParticipantsLandscape() {
237222 ParticipantGrid (
238223 participantUiStates = getTestParticipants(4 ),
239224 eglBase = null ,
240- isVoiceOnlyCall = false ,
241- isInPipMode = false
225+ isVoiceOnlyCall = false
242226 ) {}
243227}
244228
@@ -252,8 +236,7 @@ fun SevenParticipantsLandscape() {
252236 ParticipantGrid (
253237 participantUiStates = getTestParticipants(7 ),
254238 eglBase = null ,
255- isVoiceOnlyCall = false ,
256- isInPipMode = false
239+ isVoiceOnlyCall = false
257240 ) {}
258241}
259242
@@ -267,8 +250,7 @@ fun FiftyParticipantsLandscape() {
267250 ParticipantGrid (
268251 participantUiStates = getTestParticipants(50 ),
269252 eglBase = null ,
270- isVoiceOnlyCall = false ,
271- isInPipMode = false
253+ isVoiceOnlyCall = false
272254 ) {}
273255}
274256
0 commit comments