Skip to content

Commit

Permalink
Improved PlaylistHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Jul 16, 2024
1 parent 7151dd6 commit b6751c2
Showing 1 changed file with 20 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit b6751c2

Please sign in to comment.