@@ -128,6 +128,8 @@ fun GetMessageAvatar(logo: String?) {
128128}
129129
130130
131+
132+
131133@OptIn(ExperimentalFoundationApi ::class )
132134@Composable
133135fun RecentMessageCard (
@@ -137,9 +139,19 @@ fun RecentMessageCard(
137139 logo : String? = null,
138140 onClickCallback : (Payloads ) -> Unit ,
139141) {
140- var text by remember { mutableStateOf(payload.content.getBody().toUtf8String()) }
141- var heading by remember { mutableStateOf(payload.content.getSubject()?.toUtf8String() ? : " " ) }
142- var subHeading by remember { mutableStateOf(payload.content.getTo()?.toUtf8String() ? : " " ) }
142+ val rawBody = payload.content.getBody().toUtf8String()
143+ val heading = payload.content.getSubject()?.toUtf8String() ? : " "
144+ val subHeading = payload.content.getTo()?.toUtf8String() ? : " "
145+
146+ val hasHeading = heading.isNotBlank()
147+ val hasSubHeading = subHeading.isNotBlank()
148+
149+ val maxPreviewChars = 50
150+ val previewText = remember(rawBody) {
151+ if (rawBody.length > maxPreviewChars) {
152+ rawBody.take(maxPreviewChars).trimEnd() + " …"
153+ } else rawBody
154+ }
143155
144156 Column {
145157 ListItem (
@@ -152,41 +164,44 @@ fun RecentMessageCard(
152164 .fillMaxWidth(),
153165 headlineContent = {
154166 Text (
155- subHeading,
167+ text = if (hasSubHeading) subHeading else previewText ,
156168 style = MaterialTheme .typography.bodyMedium,
157169 color = MaterialTheme .colorScheme.onSurfaceVariant,
158170 maxLines = 1 ,
159171 overflow = TextOverflow .Ellipsis
160172 )
161173 },
162- overlineContent = {
163- Text (
164- heading,
165- style = if (cat == V1ContentCategories .TEXT ) {
166- MaterialTheme .typography.bodyLarge.copy(fontWeight = FontWeight .Bold )
167- } else {
168- MaterialTheme .typography.bodyLarge
169- },
170- color = MaterialTheme .colorScheme.onSurfaceVariant,
171- maxLines = 1 ,
172- overflow = TextOverflow .Ellipsis
173- )
174- },
175- supportingContent = {
176- Text (
177- text = text,
178- style = MaterialTheme .typography.bodySmall,
179- maxLines = 2 ,
180- overflow = TextOverflow .Ellipsis ,
181- color = MaterialTheme .colorScheme.onSurfaceVariant
182- )
183- },
174+ overlineContent = if (hasHeading) {
175+ {
176+ Text (
177+ heading,
178+ style = if (cat == V1ContentCategories .TEXT ) {
179+ MaterialTheme .typography.bodyLarge.copy(fontWeight = FontWeight .Bold )
180+ } else {
181+ MaterialTheme .typography.bodyLarge
182+ },
183+ color = MaterialTheme .colorScheme.onSurfaceVariant,
184+ maxLines = 1 ,
185+ overflow = TextOverflow .Ellipsis
186+ )
187+ }
188+ } else null ,
189+ supportingContent = if (hasSubHeading) {
190+ {
191+ Text (
192+ text = previewText,
193+ style = MaterialTheme .typography.bodySmall,
194+ maxLines = 1 ,
195+ overflow = TextOverflow .Ellipsis ,
196+ color = MaterialTheme .colorScheme.onSurfaceVariant
197+ )
198+ }
199+ } else null ,
184200 leadingContent = {
185201 GetMessageAvatar (logo)
186202 },
187203 trailingContent = {
188204 Text (
189- // text = Helpers.formatDate(LocalContext.current, payload.date),
190205 text = date,
191206 style = MaterialTheme .typography.labelSmall,
192207 color = MaterialTheme .colorScheme.onSurfaceVariant
@@ -195,3 +210,5 @@ fun RecentMessageCard(
195210 )
196211 }
197212}
213+
214+
0 commit comments