Redesign PlaylistScreen (#172)

This commit is contained in:
vfsfitvnm
2022-09-27 16:43:59 +02:00
parent 2e3d437c15
commit 83230e3817
21 changed files with 537 additions and 609 deletions

View File

@@ -51,6 +51,30 @@ fun <T> produceSaveableState(
return state
}
@Composable
fun <T> produceSaveableOneShotState(
initialValue: T,
stateSaver: Saver<T, out Any>,
@BuilderInference producer: suspend ProduceStateScope<T>.() -> Unit
): State<T> {
val state = rememberSaveable(stateSaver = stateSaver) {
mutableStateOf(initialValue)
}
var produced by rememberSaveable {
mutableStateOf(false)
}
LaunchedEffect(Unit) {
if (!produced) {
ProduceSaveableStateScope(state, coroutineContext).producer()
produced = true
}
}
return state
}
@Composable
fun <T> produceSaveableOneShotState(
initialValue: T,

View File

@@ -89,37 +89,6 @@ val DetailedSong.asMediaItem: MediaItem
.setCustomCacheKey(id)
.build()
fun YouTube.PlaylistOrAlbum.Item.toMediaItem(
albumId: String,
playlistOrAlbum: YouTube.PlaylistOrAlbum
): MediaItem? {
val isFromAlbum = thumbnail == null
return MediaItem.Builder()
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle(info.name)
.setArtist((authors ?: playlistOrAlbum.authors)?.joinToString("") { it.name })
.setAlbumTitle(if (isFromAlbum) playlistOrAlbum.title else album?.name)
.setArtworkUri(if (isFromAlbum) playlistOrAlbum.thumbnail?.url?.toUri() else thumbnail?.url?.toUri())
.setExtras(
bundleOf(
"videoId" to info.endpoint?.videoId,
"playlistId" to info.endpoint?.playlistId,
"albumId" to (if (isFromAlbum) albumId else album?.endpoint?.browseId),
"durationText" to durationText,
"artistNames" to (authors ?: playlistOrAlbum.authors)?.filter { it.endpoint != null }?.map { it.name },
"artistIds" to (authors ?: playlistOrAlbum.authors)?.mapNotNull { it.endpoint?.browseId }
)
)
.build()
)
.setMediaId(info.endpoint?.videoId ?: return null)
.setUri(info.endpoint?.videoId ?: return null)
.setCustomCacheKey(info.endpoint?.videoId ?: return null)
.build()
}
fun String?.thumbnail(size: Int): String? {
return when {
this?.startsWith("https://lh3.googleusercontent.com") == true -> "$this-w$size-h$size"