From 0c2afe9f13887e6180d25e786fc48ca470a07e37 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Tue, 16 Jul 2024 19:13:02 +0530 Subject: [PATCH] Improved PlaylistHeader --- .../compose/playlist/PlaylistHeader.kt | 37 ++++++++++--------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/compose/playlist/PlaylistHeader.kt b/app/src/main/java/org/schabi/newpipe/compose/playlist/PlaylistHeader.kt index cdb87351c64..88e29d2ad48 100644 --- a/app/src/main/java/org/schabi/newpipe/compose/playlist/PlaylistHeader.kt +++ b/app/src/main/java/org/schabi/newpipe/compose/playlist/PlaylistHeader.kt @@ -57,23 +57,21 @@ fun PlaylistHeader(playlistInfo: PlaylistInfo, totalDuration: Long) { Text(text = playlistInfo.name, style = MaterialTheme.typography.titleMedium) Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) { + val clickable = playlistInfo.uploaderName != null && playlistInfo.uploaderUrl != null + Row( verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(4.dp), - modifier = Modifier.let { - if (playlistInfo.uploaderName != null && playlistInfo.uploaderUrl != null) { - it.clickable { - try { - NavigationHelper.openChannelFragment( - (context as FragmentActivity).supportFragmentManager, - playlistInfo.serviceId, playlistInfo.uploaderUrl, - playlistInfo.uploaderName - ) - } catch (e: Exception) { - ErrorUtil.showUiErrorSnackbar(context, "Opening channel fragment", e) - } - } - } else it + modifier = Modifier.clickable(clickable) { + try { + NavigationHelper.openChannelFragment( + (context as FragmentActivity).supportFragmentManager, + playlistInfo.serviceId, playlistInfo.uploaderUrl, + playlistInfo.uploaderName + ) + } catch (e: Exception) { + ErrorUtil.showUiErrorSnackbar(context, "Opening channel fragment", e) + } } ) { val imageModifier = Modifier @@ -113,17 +111,22 @@ fun PlaylistHeader(playlistInfo: PlaylistInfo, totalDuration: Long) { val description = playlistInfo.description ?: Description.EMPTY_DESCRIPTION if (description != Description.EMPTY_DESCRIPTION) { var isExpanded by rememberSaveable { mutableStateOf(false) } - val parsedDescription = rememberParsedDescription(description) + var isExpandable by rememberSaveable { mutableStateOf(false) } Text( modifier = Modifier.animateContentSize(), - text = parsedDescription, + text = rememberParsedDescription(description), maxLines = if (isExpanded) Int.MAX_VALUE else 5, style = MaterialTheme.typography.bodyMedium, overflow = TextOverflow.Ellipsis, + onTextLayout = { + if (it.hasVisualOverflow) { + isExpandable = true + } + } ) - if (parsedDescription.lineSequence().take(6).count() > 5) { + if (isExpandable) { TextButton( onClick = { isExpanded = !isExpanded }, modifier = Modifier.align(Alignment.End)