Start working on QuickPicks screen

This commit is contained in:
vfsfitvnm
2022-09-28 21:46:56 +02:00
parent 7a3c0ca110
commit 33778b33dd
37 changed files with 1354 additions and 272 deletions

View File

@@ -26,6 +26,6 @@ object DetailedSongSaver : Saver<DetailedSong, List<Any?>> {
thumbnailUrl = value[4] as String?,
totalPlayTimeMs = value[5] as Long,
albumId = value[6] as String?,
artists = InfoListSaver.restore(value[7] as List<List<String>>)
artists = (value[7] as List<List<String>>?)?.let(InfoListSaver::restore)
)
}

View File

@@ -8,9 +8,6 @@ object InfoSaver : Saver<Info, List<String>> {
override fun SaverScope.save(value: Info): List<String> = listOf(value.id, value.name)
override fun restore(value: List<String>): Info? {
return if (value.size == 2) Info(
id = value[0],
name = value[1],
) else null
return if (value.size == 2) Info(id = value[0], name = value[1]) else null
}
}

View File

@@ -0,0 +1,13 @@
package it.vfsfitvnm.vimusic.savers
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.SaverScope
fun <Original, Saveable : Any> nullableSaver(saver: Saver<Original, Saveable>) =
object : Saver<Original?, Saveable> {
override fun SaverScope.save(value: Original?): Saveable? =
value?.let { with(saver) { save(it) } }
override fun restore(value: Saveable): Original? =
saver.restore(value)
}

View File

@@ -3,8 +3,6 @@ package it.vfsfitvnm.vimusic.savers
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.SaverScope
interface ResultSaver<Original, Saveable> : Saver<Result<Original>?, Pair<Saveable?, Throwable?>>
fun <Original, Saveable : Any> resultSaver(saver: Saver<Original, Saveable>) =
object : Saver<Result<Original>?, Pair<Saveable?, Throwable?>> {
override fun restore(value: Pair<Saveable?, Throwable?>) =

View File

@@ -6,15 +6,15 @@ import it.vfsfitvnm.youtubemusic.YouTube
object YouTubeAlbumSaver : Saver<YouTube.Item.Album, List<Any?>> {
override fun SaverScope.save(value: YouTube.Item.Album): List<Any?> = listOf(
with(YouTubeBrowseInfoSaver) { save(value.info) },
with(YouTubeBrowseInfoListSaver) { value.authors?.let { save(it) } },
value.info?.let { with(YouTubeBrowseInfoSaver) { save(it) } },
value.authors?.let { with(YouTubeBrowseInfoListSaver) { save(it) } },
value.year,
with(YouTubeThumbnailSaver) { value.thumbnail?.let { save(it) } }
value.thumbnail?.let { with(YouTubeThumbnailSaver) { save(it) } }
)
@Suppress("UNCHECKED_CAST")
override fun restore(value: List<Any?>) = YouTube.Item.Album(
info = YouTubeBrowseInfoSaver.restore(value[0] as List<Any?>),
info = (value[0] as List<Any?>?)?.let(YouTubeBrowseInfoSaver::restore),
authors = (value[1] as List<List<Any?>>?)?.let(YouTubeBrowseInfoListSaver::restore),
year = value[2] as String?,
thumbnail = (value[3] as List<Any?>?)?.let(YouTubeThumbnailSaver::restore)

View File

@@ -6,13 +6,13 @@ import it.vfsfitvnm.youtubemusic.YouTube
object YouTubeArtistSaver : Saver<YouTube.Item.Artist, List<Any?>> {
override fun SaverScope.save(value: YouTube.Item.Artist): List<Any?> = listOf(
with(YouTubeBrowseInfoSaver) { save(value.info) },
value.info?.let { with(YouTubeBrowseInfoSaver) { save(it) } },
value.subscribersCountText,
with(YouTubeThumbnailSaver) { value.thumbnail?.let { save(it) } }
)
override fun restore(value: List<Any?>) = YouTube.Item.Artist(
info = YouTubeBrowseInfoSaver.restore(value[0] as List<Any?>),
info = (value[0] as List<Any?>?)?.let(YouTubeBrowseInfoSaver::restore),
subscribersCountText = value[1] as String?,
thumbnail = (value[2] as List<Any?>?)?.let(YouTubeThumbnailSaver::restore)
)

View File

@@ -8,11 +8,11 @@ import it.vfsfitvnm.youtubemusic.models.NavigationEndpoint
object YouTubeBrowseInfoSaver : Saver<YouTube.Info<NavigationEndpoint.Endpoint.Browse>, List<Any?>> {
override fun SaverScope.save(value: YouTube.Info<NavigationEndpoint.Endpoint.Browse>) = listOf(
value.name,
with(YouTubeBrowseEndpointSaver) { value.endpoint?.let { save(it) } }
value.endpoint?.let { with(YouTubeBrowseEndpointSaver) { save(it) } }
)
override fun restore(value: List<Any?>) = YouTube.Info(
name = value[0] as String,
name = value[0] as String?,
endpoint = (value[1] as List<Any?>?)?.let(YouTubeBrowseEndpointSaver::restore)
)
}

View File

@@ -6,14 +6,14 @@ import it.vfsfitvnm.youtubemusic.YouTube
object YouTubePlaylistSaver : Saver<YouTube.Item.Playlist, List<Any?>> {
override fun SaverScope.save(value: YouTube.Item.Playlist): List<Any?> = listOf(
with(YouTubeBrowseInfoSaver) { save(value.info) },
with(YouTubeBrowseInfoSaver) { value.channel?.let { save(it) } },
value.info?.let { with(YouTubeBrowseInfoSaver) { save(it) } },
value.channel?.let { with(YouTubeBrowseInfoSaver) { save(it) } },
value.songCount,
with(YouTubeThumbnailSaver) { value.thumbnail?.let { save(it) } }
value.thumbnail?.let { with(YouTubeThumbnailSaver) { save(it) } }
)
override fun restore(value: List<Any?>) = YouTube.Item.Playlist(
info = YouTubeBrowseInfoSaver.restore(value[0] as List<Any?>),
info = (value[0] as List<Any?>?)?.let(YouTubeBrowseInfoSaver::restore),
channel = (value[1] as List<Any?>?)?.let(YouTubeBrowseInfoSaver::restore),
songCount = value[2] as Int?,
thumbnail = (value[3] as List<Any?>?)?.let(YouTubeThumbnailSaver::restore)

View File

@@ -0,0 +1,22 @@
package it.vfsfitvnm.vimusic.savers
import androidx.compose.runtime.saveable.Saver
import androidx.compose.runtime.saveable.SaverScope
import it.vfsfitvnm.youtubemusic.YouTube
object YouTubeRelatedSaver : Saver<YouTube.Related, List<Any?>> {
override fun SaverScope.save(value: YouTube.Related): List<Any?> = listOf(
value.songs?.let { with(YouTubeSongListSaver) { save(it) } },
value.playlists?.let { with(YouTubePlaylistListSaver) { save(it) } },
value.albums?.let { with(YouTubeAlbumListSaver) { save(it) } },
value.artists?.let { with(YouTubeArtistListSaver) { save(it) } },
)
@Suppress("UNCHECKED_CAST")
override fun restore(value: List<Any?>) = YouTube.Related(
songs = (value[0] as List<List<Any?>>?)?.let(YouTubeSongListSaver::restore),
playlists = (value[1] as List<List<Any?>>?)?.let(YouTubePlaylistListSaver::restore),
albums = (value[2] as List<List<Any?>>?)?.let(YouTubeAlbumListSaver::restore),
artists = (value[3] as List<List<Any?>>?)?.let(YouTubeArtistListSaver::restore),
)
}

View File

@@ -6,17 +6,17 @@ import it.vfsfitvnm.youtubemusic.YouTube
object YouTubeSongSaver : Saver<YouTube.Item.Song, List<Any?>> {
override fun SaverScope.save(value: YouTube.Item.Song): List<Any?> = listOf(
with(YouTubeWatchInfoSaver) { save(value.info) },
with(YouTubeBrowseInfoListSaver) { value.authors?.let { save(it) } },
with(YouTubeBrowseInfoSaver) { value.album?.let { save(it) } },
value.info?.let { with(YouTubeWatchInfoSaver) { save(it) } },
value.authors?.let { with(YouTubeBrowseInfoListSaver) { save(it) } },
value.album?.let { with(YouTubeBrowseInfoSaver) { save(it) } },
value.durationText,
with(YouTubeThumbnailSaver) { value.thumbnail?.let { save(it) } }
value.thumbnail?.let { with(YouTubeThumbnailSaver) { save(it) } }
)
@Suppress("UNCHECKED_CAST")
override fun restore(value: List<Any?>) = YouTube.Item.Song(
info = YouTubeWatchInfoSaver.restore(value[0] as List<Any?>),
authors = YouTubeBrowseInfoListSaver.restore(value[1] as List<List<Any?>>),
info = (value[0] as List<Any?>?)?.let(YouTubeWatchInfoSaver::restore),
authors = (value[1] as List<List<Any?>>?)?.let(YouTubeBrowseInfoListSaver::restore),
album = (value[2] as List<Any?>?)?.let(YouTubeBrowseInfoSaver::restore),
durationText = value[3] as String?,
thumbnail = (value[4] as List<Any?>?)?.let(YouTubeThumbnailSaver::restore)

View File

@@ -6,17 +6,17 @@ import it.vfsfitvnm.youtubemusic.YouTube
object YouTubeVideoSaver : Saver<YouTube.Item.Video, List<Any?>> {
override fun SaverScope.save(value: YouTube.Item.Video): List<Any?> = listOf(
with(YouTubeWatchInfoSaver) { save(value.info) },
with(YouTubeBrowseInfoListSaver) { value.authors?.let { save(it) } },
value.info?.let { with(YouTubeWatchInfoSaver) { save(it) } },
value.authors?.let { with(YouTubeBrowseInfoListSaver) { save(it) } },
value.viewsText,
value.durationText,
with(YouTubeThumbnailSaver) { value.thumbnail?.let { save(it) } }
value.thumbnail?.let { with(YouTubeThumbnailSaver) { save(it) } }
)
@Suppress("UNCHECKED_CAST")
override fun restore(value: List<Any?>) = YouTube.Item.Video(
info = YouTubeWatchInfoSaver.restore(value[0] as List<Any?>),
authors = YouTubeBrowseInfoListSaver.restore(value[1] as List<List<Any?>>),
info = (value[0] as List<Any?>?)?.let(YouTubeWatchInfoSaver::restore),
authors = (value[1] as List<List<Any?>>?)?.let(YouTubeBrowseInfoListSaver::restore),
viewsText = value[2] as String?,
durationText = value[3] as String?,
thumbnail = (value[4] as List<Any?>?)?.let(YouTubeThumbnailSaver::restore)

View File

@@ -8,11 +8,11 @@ import it.vfsfitvnm.youtubemusic.models.NavigationEndpoint
object YouTubeWatchInfoSaver : Saver<YouTube.Info<NavigationEndpoint.Endpoint.Watch>, List<Any?>> {
override fun SaverScope.save(value: YouTube.Info<NavigationEndpoint.Endpoint.Watch>) = listOf(
value.name,
with(YouTubeWatchEndpointSaver) { value.endpoint?.let { save(it) } }
value.endpoint?.let { with(YouTubeWatchEndpointSaver) { save(it) } },
)
override fun restore(value: List<Any?>) = YouTube.Info(
name = value[0] as String,
name = value[0] as String?,
endpoint = (value[1] as List<Any?>?)?.let(YouTubeWatchEndpointSaver::restore)
)
}