Tweak code
This commit is contained in:
parent
13028e41c7
commit
a4b4af1fbd
16 changed files with 27 additions and 56 deletions
|
@ -15,5 +15,3 @@ object SearchQuerySaver : Saver<SearchQuery, List<Any?>> {
|
|||
query = value[1] as String
|
||||
)
|
||||
}
|
||||
|
||||
val SearchQueryListSaver = listSaver(SearchQuerySaver)
|
||||
|
|
|
@ -37,7 +37,7 @@ import kotlinx.coroutines.flow.flowOn
|
|||
|
||||
@ExperimentalAnimationApi
|
||||
@Composable
|
||||
fun ArtistLocalSongsList(
|
||||
fun ArtistLocalSongs(
|
||||
browseId: String,
|
||||
headerContent: @Composable (textButton: (@Composable () -> Unit)?) -> Unit,
|
||||
thumbnailContent: @Composable ColumnScope.() -> Unit,
|
|
@ -9,15 +9,12 @@ import androidx.compose.foundation.layout.Box
|
|||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.ColumnScope
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.text.BasicText
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.ripple.rememberRipple
|
||||
|
@ -25,14 +22,10 @@ import androidx.compose.runtime.Composable
|
|||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.unit.dp
|
||||
import it.vfsfitvnm.vimusic.LocalPlayerAwarePaddingValues
|
||||
import it.vfsfitvnm.vimusic.LocalPlayerServiceBinder
|
||||
import it.vfsfitvnm.vimusic.R
|
||||
import it.vfsfitvnm.vimusic.models.Artist
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.Header
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.HeaderPlaceholder
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.PrimaryButton
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.SecondaryTextButton
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.ShimmerHost
|
||||
|
@ -40,13 +33,11 @@ import it.vfsfitvnm.vimusic.ui.components.themed.TextPlaceholder
|
|||
import it.vfsfitvnm.vimusic.ui.styling.Dimensions
|
||||
import it.vfsfitvnm.vimusic.ui.styling.LocalAppearance
|
||||
import it.vfsfitvnm.vimusic.ui.styling.px
|
||||
import it.vfsfitvnm.vimusic.ui.styling.shimmer
|
||||
import it.vfsfitvnm.vimusic.ui.views.AlbumItem
|
||||
import it.vfsfitvnm.vimusic.ui.views.AlbumItemPlaceholder
|
||||
import it.vfsfitvnm.vimusic.ui.views.SongItem
|
||||
import it.vfsfitvnm.vimusic.ui.views.SongItemPlaceholder
|
||||
import it.vfsfitvnm.vimusic.utils.asMediaItem
|
||||
import it.vfsfitvnm.vimusic.utils.center
|
||||
import it.vfsfitvnm.vimusic.utils.forcePlay
|
||||
import it.vfsfitvnm.vimusic.utils.secondary
|
||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||
|
|
|
@ -399,7 +399,7 @@ fun ArtistScreen(browseId: String) {
|
|||
)
|
||||
}
|
||||
|
||||
4 -> ArtistLocalSongsList(
|
||||
4 -> ArtistLocalSongs(
|
||||
browseId = browseId,
|
||||
headerContent = headerContent,
|
||||
thumbnailContent = thumbnailContent,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package it.vfsfitvnm.vimusic.ui.screens.builtinplaylist
|
||||
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
|
@ -11,6 +12,7 @@ import it.vfsfitvnm.vimusic.enums.BuiltInPlaylist
|
|||
import it.vfsfitvnm.vimusic.ui.components.themed.Scaffold
|
||||
import it.vfsfitvnm.vimusic.ui.screens.globalRoutes
|
||||
|
||||
@ExperimentalFoundationApi
|
||||
@ExperimentalAnimationApi
|
||||
@Composable
|
||||
fun BuiltInPlaylistScreen(builtInPlaylist: BuiltInPlaylist) {
|
||||
|
@ -39,8 +41,8 @@ fun BuiltInPlaylistScreen(builtInPlaylist: BuiltInPlaylist) {
|
|||
) { currentTabIndex ->
|
||||
saveableStateHolder.SaveableStateProvider(key = currentTabIndex) {
|
||||
when (currentTabIndex) {
|
||||
0 -> BuiltInPlaylistSongList(builtInPlaylist = BuiltInPlaylist.Favorites)
|
||||
1 -> BuiltInPlaylistSongList(builtInPlaylist = BuiltInPlaylist.Offline)
|
||||
0 -> BuiltInPlaylistSongs(builtInPlaylist = BuiltInPlaylist.Favorites)
|
||||
1 -> BuiltInPlaylistSongs(builtInPlaylist = BuiltInPlaylist.Offline)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package it.vfsfitvnm.vimusic.ui.screens.builtinplaylist
|
||||
|
||||
import androidx.compose.animation.ExperimentalAnimationApi
|
||||
import androidx.compose.foundation.ExperimentalFoundationApi
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
|
@ -10,6 +11,7 @@ import androidx.compose.foundation.lazy.itemsIndexed
|
|||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import it.vfsfitvnm.reordering.animateItemPlacement
|
||||
import it.vfsfitvnm.vimusic.Database
|
||||
import it.vfsfitvnm.vimusic.LocalPlayerAwarePaddingValues
|
||||
import it.vfsfitvnm.vimusic.LocalPlayerServiceBinder
|
||||
|
@ -35,9 +37,10 @@ import kotlinx.coroutines.Dispatchers
|
|||
import kotlinx.coroutines.flow.flowOn
|
||||
import kotlinx.coroutines.flow.map
|
||||
|
||||
@ExperimentalFoundationApi
|
||||
@ExperimentalAnimationApi
|
||||
@Composable
|
||||
fun BuiltInPlaylistSongList(builtInPlaylist: BuiltInPlaylist) {
|
||||
fun BuiltInPlaylistSongs(builtInPlaylist: BuiltInPlaylist) {
|
||||
val (colorPalette) = LocalAppearance.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
||||
|
@ -116,7 +119,9 @@ fun BuiltInPlaylistSongList(builtInPlaylist: BuiltInPlaylist) {
|
|||
BuiltInPlaylist.Favorites -> InFavoritesMediaItemMenu(song = song)
|
||||
BuiltInPlaylist.Offline -> InHistoryMediaItemMenu(song = song)
|
||||
}
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.animateItemPlacement()
|
||||
)
|
||||
}
|
||||
}
|
|
@ -61,7 +61,7 @@ import kotlinx.coroutines.flow.flowOn
|
|||
@ExperimentalFoundationApi
|
||||
@ExperimentalAnimationApi
|
||||
@Composable
|
||||
fun HomeAlbumList(
|
||||
fun HomeAlbums(
|
||||
onAlbumClick: (Album) -> Unit
|
||||
) {
|
||||
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
|
|
@ -57,7 +57,7 @@ import kotlinx.coroutines.flow.flowOn
|
|||
|
||||
@ExperimentalFoundationApi
|
||||
@Composable
|
||||
fun HomePlaylistList(
|
||||
fun HomePlaylists(
|
||||
onBuiltInPlaylist: (BuiltInPlaylist) -> Unit,
|
||||
onPlaylistClick: (Playlist) -> Unit,
|
||||
) {
|
|
@ -99,7 +99,7 @@ fun HomeScreen(onPlaylistUrl: (String) -> Unit) {
|
|||
host {
|
||||
val (tabIndex, onTabChanged) = rememberPreference(
|
||||
homeScreenTabIndexKey,
|
||||
defaultValue = 1
|
||||
defaultValue = 0
|
||||
)
|
||||
|
||||
Scaffold(
|
||||
|
@ -124,13 +124,13 @@ fun HomeScreen(onPlaylistUrl: (String) -> Unit) {
|
|||
onArtistClick = { artistRoute(it) },
|
||||
onPlaylistClick = { playlistRoute(it) },
|
||||
)
|
||||
1 -> HomeSongList()
|
||||
2 -> HomePlaylistList(
|
||||
1 -> HomeSongs()
|
||||
2 -> HomePlaylists(
|
||||
onBuiltInPlaylist = { builtInPlaylistRoute(it) },
|
||||
onPlaylistClick = { localPlaylistRoute(it.id) }
|
||||
)
|
||||
3 -> HomeArtistList(onArtistClick = { artistRoute(it.id) })
|
||||
4 -> HomeAlbumList(onAlbumClick = { albumRoute(it.id) })
|
||||
4 -> HomeAlbums(onAlbumClick = { albumRoute(it.id) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ import kotlinx.coroutines.flow.flowOn
|
|||
@ExperimentalFoundationApi
|
||||
@ExperimentalAnimationApi
|
||||
@Composable
|
||||
fun HomeSongList() {
|
||||
fun HomeSongs() {
|
||||
val (colorPalette, typography, thumbnailShape) = LocalAppearance.current
|
||||
val binder = LocalPlayerServiceBinder.current
|
||||
|
|
@ -97,9 +97,7 @@ fun QuickPicks(
|
|||
stateSaver = resultSaver(nullableSaver(InnertubeRelatedPageSaver)),
|
||||
trending?.id
|
||||
) {
|
||||
trending?.id?.let { trendingVideoId ->
|
||||
value = Innertube.relatedPage(NextBody(videoId = trendingVideoId))
|
||||
}
|
||||
value = Innertube.relatedPage(NextBody(videoId = (trending?.id ?: "J7p4bzqLvCw")))
|
||||
}
|
||||
|
||||
val songThumbnailSizeDp = Dimensions.thumbnails.song
|
||||
|
|
|
@ -29,7 +29,7 @@ fun LocalPlaylistScreen(playlistId: Long) {
|
|||
}
|
||||
) { currentTabIndex ->
|
||||
saveableStateHolder.SaveableStateProvider(key = currentTabIndex) {
|
||||
LocalPlaylistSongList(
|
||||
LocalPlaylistSongs(
|
||||
playlistId = playlistId,
|
||||
onDelete = pop
|
||||
)
|
||||
|
|
|
@ -63,7 +63,7 @@ import kotlinx.coroutines.withContext
|
|||
@ExperimentalAnimationApi
|
||||
@ExperimentalFoundationApi
|
||||
@Composable
|
||||
fun LocalPlaylistSongList(
|
||||
fun LocalPlaylistSongs(
|
||||
playlistId: Long,
|
||||
onDelete: () -> Unit,
|
||||
) {
|
|
@ -41,7 +41,8 @@ import it.vfsfitvnm.vimusic.LocalPlayerAwarePaddingValues
|
|||
import it.vfsfitvnm.vimusic.R
|
||||
import it.vfsfitvnm.vimusic.models.SearchQuery
|
||||
import it.vfsfitvnm.vimusic.query
|
||||
import it.vfsfitvnm.vimusic.savers.SearchQueryListSaver
|
||||
import it.vfsfitvnm.vimusic.savers.SearchQuerySaver
|
||||
import it.vfsfitvnm.vimusic.savers.listSaver
|
||||
import it.vfsfitvnm.vimusic.savers.resultSaver
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.Header
|
||||
import it.vfsfitvnm.vimusic.ui.components.themed.SecondaryTextButton
|
||||
|
@ -72,7 +73,7 @@ fun OnlineSearch(
|
|||
|
||||
val history by produceSaveableState(
|
||||
initialValue = emptyList(),
|
||||
stateSaver = SearchQueryListSaver,
|
||||
stateSaver = listSaver(SearchQuerySaver),
|
||||
key1 = textFieldValue.text
|
||||
) {
|
||||
Database.queries("%${textFieldValue.text}%")
|
||||
|
@ -84,7 +85,7 @@ fun OnlineSearch(
|
|||
val suggestionsResult by produceSaveableOneShotState(
|
||||
initialValue = null,
|
||||
stateSaver = resultSaver(autoSaver<List<String>?>()),
|
||||
key1 = textFieldValue.text
|
||||
textFieldValue.text
|
||||
) {
|
||||
if (textFieldValue.text.isNotEmpty()) {
|
||||
value = Innertube.searchSuggestions(SearchSuggestionsBody(input = textFieldValue.text))
|
||||
|
|
|
@ -51,30 +51,6 @@ 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,
|
||||
|
|
Loading…
Reference in a new issue