11/*
22 * Nextcloud Talk - Android Client
33 *
4- * SPDX-FileCopyrightText: 2025 Your Name <your@email.com >
4+ * SPDX-FileCopyrightText: 2025 Marcel Hibbe <dev@mhibbe.de >
55 * SPDX-License-Identifier: GPL-3.0-or-later
66 */
77
88package com.nextcloud.talk.threadsoverview.components
99
10+ import android.content.res.Configuration
11+ import androidx.compose.foundation.background
1012import androidx.compose.foundation.clickable
13+ import androidx.compose.foundation.layout.Box
1114import androidx.compose.foundation.layout.Column
1215import androidx.compose.foundation.layout.Row
1316import androidx.compose.foundation.layout.Spacer
@@ -16,19 +19,23 @@ import androidx.compose.foundation.layout.height
1619import androidx.compose.foundation.layout.padding
1720import androidx.compose.foundation.layout.size
1821import androidx.compose.foundation.layout.width
22+ import androidx.compose.foundation.shape.CircleShape
23+ import androidx.compose.material3.Icon
1924import androidx.compose.material3.MaterialTheme
2025import androidx.compose.material3.Text
2126import androidx.compose.runtime.Composable
2227import androidx.compose.ui.Alignment
2328import androidx.compose.ui.Modifier
24- import androidx.compose.ui.res.stringResource
29+ import androidx.compose.ui.draw.clip
30+ import androidx.compose.ui.graphics.Color
31+ import androidx.compose.ui.graphics.vector.ImageVector
32+ import androidx.compose.ui.res.vectorResource
2533import androidx.compose.ui.text.font.FontWeight
2634import androidx.compose.ui.text.style.TextOverflow
2735import androidx.compose.ui.tooling.preview.Preview
2836import androidx.compose.ui.unit.dp
29- import coil.compose.AsyncImage
30- import coil.request.ImageRequest
3137import com.nextcloud.talk.R
38+ import com.nextcloud.talk.utils.ColorGenerator
3239
3340@Suppress(" LongParameterList" , " Detekt.LongMethod" )
3441@Composable
@@ -40,7 +47,6 @@ fun ThreadRow(
4047 secondLine : String ,
4148 numReplies : String ,
4249 date : String ,
43- imageRequest : ImageRequest ? ,
4450 onClick : ((String , Int ) -> Unit? )?
4551) {
4652 Row (
@@ -52,11 +58,7 @@ fun ThreadRow(
5258 .padding(vertical = 8 .dp, horizontal = 8 .dp),
5359 verticalAlignment = Alignment .Companion .CenterVertically
5460 ) {
55- AsyncImage (
56- model = imageRequest,
57- contentDescription = stringResource(R .string.user_avatar),
58- modifier = Modifier .Companion .size(48 .dp)
59- )
61+ ThreadsIcon (title)
6062
6163 Spacer (modifier = Modifier .Companion .width(12 .dp))
6264
@@ -67,7 +69,7 @@ fun ThreadRow(
6769 text = title,
6870 style = MaterialTheme .typography.titleSmall,
6971 color = MaterialTheme .colorScheme.onSurfaceVariant,
70- fontWeight = FontWeight .Thin ,
72+ fontWeight = FontWeight .Medium ,
7173 maxLines = 1 ,
7274 overflow = TextOverflow .Companion .Ellipsis
7375 )
@@ -87,7 +89,7 @@ fun ThreadRow(
8789 Text (
8890 text = secondLineTitle,
8991 style = MaterialTheme .typography.titleMedium,
90- fontWeight = FontWeight .Normal ,
92+ fontWeight = FontWeight .Medium ,
9193 maxLines = 1 ,
9294 overflow = TextOverflow .Companion .Ellipsis
9395 )
@@ -96,7 +98,8 @@ fun ThreadRow(
9698 modifier = Modifier .Companion .weight(1f ),
9799 text = secondLine,
98100 style = MaterialTheme .typography.titleMedium,
99- fontWeight = FontWeight .Thin ,
101+ fontWeight = FontWeight .Normal ,
102+ color = MaterialTheme .colorScheme.outline,
100103 maxLines = 1 ,
101104 overflow = TextOverflow .Companion .Ellipsis
102105 )
@@ -113,19 +116,56 @@ fun ThreadRow(
113116 }
114117}
115118
119+ @Composable
120+ fun ThreadsIcon (title : String ) {
121+ val baseColorInt = ColorGenerator .usernameToColor(title)
122+
123+ Box (
124+ modifier = Modifier
125+ .size(48 .dp)
126+ .clip(CircleShape )
127+ .background(Color (baseColorInt).copy(alpha = 0.1f )),
128+ contentAlignment = Alignment .Center
129+ ) {
130+ Icon (
131+ imageVector = ImageVector .vectorResource(R .drawable.outline_forum_24),
132+ contentDescription = null ,
133+ tint = Color (baseColorInt).copy(alpha = 0.9f ),
134+ modifier = Modifier .size(32 .dp)
135+ )
136+ }
137+ }
138+
116139@Preview
117140@Composable
118141fun ThreadRowPreview () {
119142 ThreadRow (
120143 roomToken = " 1234" ,
121144 threadId = 123 ,
122- title = " title" ,
145+ title = " title1" ,
146+ secondLine = " last message" ,
147+ secondLineTitle = " Mia:" ,
148+ numReplies = " 12 replies" ,
149+ date = " 14 sec ago" ,
150+ onClick = null
151+ )
152+ }
153+
154+ @Preview(
155+ name = " Dark Mode" ,
156+ uiMode = Configuration .UI_MODE_NIGHT_YES
157+ )
158+ @Composable
159+ fun ThreadRowPreviewDark () {
160+ ThreadRow (
161+ roomToken = " 1234" ,
162+ threadId = 123 ,
163+ title = " title2" ,
123164 secondLine = " last message" ,
124165 secondLineTitle = " Mia:" ,
125166 numReplies = " 12 replies" ,
126167 date = " 14 sec ago" ,
127- onClick = null ,
128- imageRequest = null
168+ onClick = null
129169 )
130170}
131171
@@ -135,13 +175,12 @@ fun ThreadRowUnreadMessagePreview() {
135175 ThreadRow (
136176 roomToken = " 1234" ,
137177 threadId = 123 ,
138- title = " title " ,
178+ title = " title3 " ,
139179 secondLine = " last message" ,
140180 secondLineTitle = " Mia:" ,
141181 numReplies = " 12 replies" ,
142182 date = " 14 sec ago" ,
143- onClick = null ,
144- imageRequest = null
183+ onClick = null
145184 )
146185}
147186
@@ -151,13 +190,12 @@ fun ThreadRowMentionPreview() {
151190 ThreadRow (
152191 roomToken = " 1234" ,
153192 threadId = 123 ,
154- title = " title " ,
193+ title = " title3 " ,
155194 secondLine = " last message" ,
156195 secondLineTitle = " Mia:" ,
157196 numReplies = " 12 replies" ,
158197 date = " 14 sec ago" ,
159- onClick = null ,
160- imageRequest = null
198+ onClick = null
161199 )
162200}
163201
@@ -172,7 +210,6 @@ fun ThreadRowDirectMentionPreview() {
172210 secondLineTitle = " Mia:" ,
173211 numReplies = " 12 replies" ,
174212 date = " 14 sec ago" ,
175- onClick = null ,
176- imageRequest = null
213+ onClick = null
177214 )
178215}
0 commit comments