88package com.nextcloud.talk.call.components
99
1010import android.annotation.SuppressLint
11+ import androidx.annotation.DrawableRes
1112import androidx.compose.foundation.background
1213import androidx.compose.foundation.clickable
14+ import androidx.compose.foundation.layout.Arrangement
1315import androidx.compose.foundation.layout.Box
1416import androidx.compose.foundation.layout.BoxWithConstraints
1517import androidx.compose.foundation.layout.Row
@@ -54,12 +56,12 @@ fun ParticipantTile(
5456 isVoiceOnlyCall : Boolean ,
5557 onScreenShareIconClick : ((String? ) -> Unit? )?
5658) {
57- val colorInt = ColorGenerator .usernameToColor(participantUiState.nick!! )
59+ val color = Color ( ColorGenerator .usernameToColor(participantUiState.nick ? : " " ) )
5860
5961 BoxWithConstraints (
6062 modifier = modifier
6163 .clip(RoundedCornerShape (12 .dp))
62- .background(Color (colorInt) )
64+ .background(color )
6365 ) {
6466 val avatarSize = min(maxWidth, maxHeight) * AVATAR_SIZE_FACTOR
6567
@@ -80,73 +82,77 @@ fun ParticipantTile(
8082 .padding(8 .dp)
8183 ) {
8284 Row (
83- modifier = Modifier
84- .align( Alignment . BottomEnd )
85+ modifier = Modifier .align( Alignment . BottomEnd ),
86+ horizontalArrangement = Arrangement .spacedBy( 4 .dp )
8587 ) {
8688 if (participantUiState.isScreenStreamEnabled) {
87- Icon (
88- painter = painterResource(id = R .drawable.outline_monitor_24),
89- contentDescription = " Mic Off" ,
90- modifier = Modifier
91- .padding(6 .dp)
92- .size(24 .dp)
93- .clickable {
94- onScreenShareIconClick?.invoke(participantUiState.sessionKey)
95- },
96- tint = Color .White
89+ OverlayIcon (
90+ iconRes = R .drawable.outline_monitor_24,
91+ description = " Screen Share" ,
92+ onClick = { onScreenShareIconClick?.invoke(participantUiState.sessionKey) }
9793 )
9894 }
9995
10096 if (! participantUiState.isAudioEnabled) {
101- Icon (
102- painter = painterResource(id = R .drawable.ic_mic_off_white_24px),
103- contentDescription = " Mic Off" ,
104- modifier = Modifier
105- .padding(6 .dp)
106- .size(24 .dp),
107- tint = Color .White
97+ OverlayIcon (
98+ iconRes = R .drawable.ic_mic_off_white_24px,
99+ description = " Mic Off"
108100 )
109101 }
110102 }
111103
112104 Row (
113- modifier = Modifier
114- .align(Alignment .BottomStart )
105+ modifier = Modifier .align(Alignment .BottomStart ),
106+ horizontalArrangement = Arrangement .spacedBy(4 .dp),
107+ verticalAlignment = Alignment .Bottom
115108 ) {
116109 if (participantUiState.raisedHand) {
117- Icon (
118- painter = painterResource(id = R .drawable.ic_hand_back_left),
119- contentDescription = " Raised Hand" ,
120- modifier = Modifier
121- .padding(6 .dp)
122- .size(24 .dp),
123- tint = Color .White
110+ OverlayIcon (
111+ iconRes = R .drawable.ic_hand_back_left,
112+ description = " Raised Hand"
124113 )
125114 }
126115
127116 Text (
128- text = participantUiState.nick,
117+ text = participantUiState.nick ? : " " ,
129118 color = Color .White ,
130119 style = MaterialTheme .typography.bodyMedium.copy(
131120 shadow = Shadow (
132121 color = Color .Black ,
133122 offset = Offset (NICK_OFFSET , NICK_OFFSET ),
134123 blurRadius = NICK_BLUR_RADIUS
135124 )
136- )
125+ ),
126+ modifier = Modifier .padding(bottom = 2 .dp)
137127 )
138128 }
139129
140-
141130 if (! participantUiState.isConnected) {
142- CircularProgressIndicator (
143- modifier = Modifier .align(Alignment .Center )
144- )
131+ CircularProgressIndicator (modifier = Modifier .align(Alignment .Center ))
145132 }
146133 }
147134 }
148135}
149136
137+ @Composable
138+ private fun OverlayIcon (
139+ @DrawableRes iconRes : Int ,
140+ description : String ,
141+ onClick : (() -> Unit )? = null
142+ ) {
143+ val clickableModifier = onClick?.let { Modifier .clickable { it() } } ? : Modifier
144+
145+ Icon (
146+ painter = painterResource(id = iconRes),
147+ contentDescription = description,
148+ modifier = Modifier
149+ .padding(6 .dp)
150+ .size(24 .dp)
151+ .then(clickableModifier),
152+ tint = Color .White
153+ )
154+ }
155+
150156@Preview(showBackground = false )
151157@Composable
152158fun ParticipantTilePreview () {
0 commit comments