Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playlist description #5561

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.compose.material.Checkbox
import androidx.compose.material.CheckboxDefaults
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material3.ripple
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.derivedStateOf
Expand Down Expand Up @@ -74,6 +75,8 @@ import androidx.compose.ui.text.input.ImeAction
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.zIndex
import androidx.compose.ui.text.style.TextAlign
import androidx.lifecycle.Lifecycle
import androidx.media3.common.MediaItem
import androidx.media3.common.util.UnstableApi
import androidx.media3.exoplayer.offline.Download
Expand All @@ -88,7 +91,9 @@ import it.fast4x.compose.reordering.rememberReorderingState
import it.fast4x.compose.reordering.reorder
import it.fast4x.innertube.Innertube
import it.fast4x.innertube.YtMusic
import it.fast4x.innertube.models.bodies.BrowseBody
import it.fast4x.innertube.models.bodies.NextBody
import it.fast4x.innertube.requests.playlistPage
import it.fast4x.innertube.requests.relatedSongs
import it.fast4x.innertube.utils.completed
import it.fast4x.rimusic.Database
Expand Down Expand Up @@ -177,6 +182,8 @@ import it.fast4x.rimusic.cleanPrefix
import it.fast4x.rimusic.MONTHLY_PREFIX
import it.fast4x.rimusic.PINNED_PREFIX
import it.fast4x.rimusic.PIPED_PREFIX
import it.fast4x.rimusic.YTP_PREFIX
import it.fast4x.rimusic.colorPalette
import it.fast4x.rimusic.enums.PlaylistSongsTypeFilter
import it.fast4x.rimusic.ui.components.themed.NowPlayingSongIndicator
import it.fast4x.rimusic.ui.screens.settings.isYouTubeSyncEnabled
Expand All @@ -199,6 +206,7 @@ import it.fast4x.rimusic.utils.isExplicit
import it.fast4x.rimusic.utils.isNetworkConnected
import it.fast4x.rimusic.utils.mediaItemToggleLike
import it.fast4x.rimusic.utils.playlistSongsTypeFilterKey
import it.fast4x.rimusic.utils.showPlaylistDescriptionEnabledKey
import it.fast4x.rimusic.utils.removeYTSongFromPlaylist
import it.fast4x.rimusic.utils.updateLocalPlaylist
import kotlinx.coroutines.Job
Expand Down Expand Up @@ -232,6 +240,7 @@ fun LocalPlaylistSongs(
var playlistSongsSortByPosition by persistList<SongEntity>("localPlaylist/$playlistId/songs")
var playlistPreview by persist<PlaylistPreview?>("localPlaylist/playlist")
val thumbnailUrl = remember { mutableStateOf("") }
val isPlaylistDescriptionEnabled = rememberPreference(showPlaylistDescriptionEnabledKey,true)


var sortBy by rememberPreference(playlistSongSortByKey, PlaylistSongSortBy.Title)
Expand Down Expand Up @@ -390,6 +399,25 @@ fun LocalPlaylistSongs(
}?.toLong() ?: 0
}

var playlistDescription by remember { mutableStateOf<String?>(null) }

LaunchedEffect(playlistPreview?.playlist?.browseId) {
playlistPreview?.playlist?.browseId?.let { browseId ->
Innertube.playlistPage(BrowseBody(browseId = browseId))
// ?.completed()
?.getOrNull()
?.let { response ->
playlistDescription = response.description
?.takeIf { it.isNotEmpty() }
?.takeUnless { it.equals("null", ignoreCase = true) }
// SmartMessage(
// "Fetched playlist description: ${response.description}, title: ${response.title}, info: ${response.otherInfo}",
// type = PopupType.Info,
// context = context
// )
}
}
}

val thumbnailRoundness by rememberPreference(
thumbnailRoundnessKey,
Expand Down Expand Up @@ -461,8 +489,6 @@ fun LocalPlaylistSongs(
pipedSession = pipedSession.toApiSession(),
id = UUID.fromString(cleanPrefix(playlistPreview?.playlist?.browseId ?: ""))
)


//onDelete()
navController.popBackStack()
}
Expand Down Expand Up @@ -1087,7 +1113,20 @@ fun LocalPlaylistSongs(
icon = painterResource(R.drawable.smart_shuffle)
)
}
Spacer(modifier = Modifier.height(30.dp))
Spacer(modifier = Modifier.height(5.dp))

if (isPlaylistDescriptionEnabled.value) {
val description = playlistDescription ?: ""

Text(
text = description,
color = colorPalette().text,
textAlign = TextAlign.Left,
overflow = TextOverflow.Ellipsis,
maxLines = 4
)
}
Spacer(modifier = Modifier.height(10.dp))
}

Column(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ import it.fast4x.rimusic.utils.autoDownloadSongKey
import it.fast4x.rimusic.utils.autoDownloadSongWhenAlbumBookmarkedKey
import it.fast4x.rimusic.utils.autoDownloadSongWhenLikedKey
import it.fast4x.rimusic.utils.customColorKey
import it.fast4x.rimusic.utils.showPlaylistDescriptionEnabledKey

@Composable
fun DefaultUiSettings() {
Expand Down Expand Up @@ -619,6 +620,7 @@ fun UiSettings(
var showPipedPlaylists by rememberPreference(showPipedPlaylistsKey, true)
var showPinnedPlaylists by rememberPreference(showPinnedPlaylistsKey, true)
var showMonthlyPlaylists by rememberPreference(showMonthlyPlaylistsKey, true)
var showPlaylistDescription by rememberPreference(showPlaylistDescriptionEnabledKey, false)

var customThemeLight_Background0 by rememberPreference(customThemeLight_Background0Key, DefaultLightColorPalette.background0.hashCode())
var customThemeLight_Background1 by rememberPreference(customThemeLight_Background1Key, DefaultLightColorPalette.background1.hashCode())
Expand Down Expand Up @@ -1492,6 +1494,16 @@ fun UiSettings(
onCheckedChange = { showMonthlyPlaylists = it }
)

SwitchSettingEntry(
// title = "Show Playlist Description",
title = "${stringResource(R.string.show)} ${stringResource(R.string.playlist_description)}",
text = "",
isChecked = showPlaylistDescription,
onCheckedChange = {
showPlaylistDescription = it
}
)

SettingsGroupSpacer()
SettingsEntryGroupText(stringResource(R.string.monthly_playlists).uppercase())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ const val showFloatingIconKey = "showFloatingIcon"
const val transitionEffectKey = "transitionEffect"
const val showMonthlyPlaylistsKey = "showMonthlyPlaylists"
const val showPipedPlaylistsKey = "showPipedPlaylists"
const val showPlaylistDescriptionEnabledKey = "isPlaylistDescriptionEnabled"
const val showMonthlyPlaylistInQuickPicksKey = "showMonthlyPlaylistInQuickPicks"
const val showMonthlyPlaylistInLibraryKey = "showMonthlyPlaylistInLibrary"
const val enableQuickPicksPageKey = "enableQuickPicksPage"
Expand Down
1 change: 1 addition & 0 deletions composeApp/src/androidMain/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,7 @@
<string name="updating_playlist_message">Update the Songs with the Missing Album ID</string>
<string name="syncing">Syncing...</string>
<string name="autosync_channels">Auto Sync Subscribed Channels</string>
<string name="playlist_description">playlist description</string>
<string name="autosync_albums">Auto Sync Saved Albums</string>
<string name="save_youtube_library">Save playlist to the Youtube Library</string>
<string name="cant_rename_Saved_albums">Cannot Rename Albums saved in the Youtube Music Library</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,23 @@ suspend fun Innertube.playlistPage(body: BrowseBody) = runCatchingCancellable {
title = header
?.title
?.text,
description = null,
// description = response.contents.twoColumnBrowseResultsRenderer.tabs?.firstOrNull()?.tabRenderer?.content?.sectionListRenderer
// ?.contents?.firstOrNull()?.musicResponsiveHeaderRenderer?.description?.musicDescriptionShelfRenderer?.description?.runs?.joinToString("") { it.text.toString() },
// description = null,
description = response
.contents
.twoColumnBrowseResultsRenderer
.tabs
?.firstOrNull()
?.tabRenderer
?.content
?.sectionListRenderer
?.contents
?.firstOrNull()
?.musicResponsiveHeaderRenderer
?.description
?.musicDescriptionShelfRenderer
?.description
?.runs
?.joinToString("") { it.text.toString() },
thumbnail = header
?.thumbnail
?.musicThumbnailRenderer
Expand Down