Skip to content

Commit b6751c2

Browse files
Improved PlaylistHeader
1 parent 7151dd6 commit b6751c2

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

app/src/main/java/org/schabi/newpipe/compose/playlist/PlaylistHeader.kt

+20-17
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,21 @@ fun PlaylistHeader(playlistInfo: PlaylistInfo, totalDuration: Long) {
5757
Text(text = playlistInfo.name, style = MaterialTheme.typography.titleMedium)
5858

5959
Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween) {
60+
val clickable = playlistInfo.uploaderName != null && playlistInfo.uploaderUrl != null
61+
6062
Row(
6163
verticalAlignment = Alignment.CenterVertically,
6264
horizontalArrangement = Arrangement.spacedBy(4.dp),
63-
modifier = Modifier.let {
64-
if (playlistInfo.uploaderName != null && playlistInfo.uploaderUrl != null) {
65-
it.clickable {
66-
try {
67-
NavigationHelper.openChannelFragment(
68-
(context as FragmentActivity).supportFragmentManager,
69-
playlistInfo.serviceId, playlistInfo.uploaderUrl,
70-
playlistInfo.uploaderName
71-
)
72-
} catch (e: Exception) {
73-
ErrorUtil.showUiErrorSnackbar(context, "Opening channel fragment", e)
74-
}
75-
}
76-
} else it
65+
modifier = Modifier.clickable(clickable) {
66+
try {
67+
NavigationHelper.openChannelFragment(
68+
(context as FragmentActivity).supportFragmentManager,
69+
playlistInfo.serviceId, playlistInfo.uploaderUrl,
70+
playlistInfo.uploaderName
71+
)
72+
} catch (e: Exception) {
73+
ErrorUtil.showUiErrorSnackbar(context, "Opening channel fragment", e)
74+
}
7775
}
7876
) {
7977
val imageModifier = Modifier
@@ -113,17 +111,22 @@ fun PlaylistHeader(playlistInfo: PlaylistInfo, totalDuration: Long) {
113111
val description = playlistInfo.description ?: Description.EMPTY_DESCRIPTION
114112
if (description != Description.EMPTY_DESCRIPTION) {
115113
var isExpanded by rememberSaveable { mutableStateOf(false) }
116-
val parsedDescription = rememberParsedDescription(description)
114+
var isExpandable by rememberSaveable { mutableStateOf(false) }
117115

118116
Text(
119117
modifier = Modifier.animateContentSize(),
120-
text = parsedDescription,
118+
text = rememberParsedDescription(description),
121119
maxLines = if (isExpanded) Int.MAX_VALUE else 5,
122120
style = MaterialTheme.typography.bodyMedium,
123121
overflow = TextOverflow.Ellipsis,
122+
onTextLayout = {
123+
if (it.hasVisualOverflow) {
124+
isExpandable = true
125+
}
126+
}
124127
)
125128

126-
if (parsedDescription.lineSequence().take(6).count() > 5) {
129+
if (isExpandable) {
127130
TextButton(
128131
onClick = { isExpanded = !isExpanded },
129132
modifier = Modifier.align(Alignment.End)

0 commit comments

Comments
 (0)