Fix #438
This commit is contained in:
@@ -29,8 +29,12 @@ import androidx.compose.foundation.rememberScrollState
|
|||||||
import androidx.compose.foundation.text.BasicText
|
import androidx.compose.foundation.text.BasicText
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
|
import androidx.compose.runtime.mutableStateOf
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
|
import androidx.compose.runtime.saveable.rememberSaveable
|
||||||
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.graphics.ColorFilter
|
import androidx.compose.ui.graphics.ColorFilter
|
||||||
@@ -66,8 +70,6 @@ import it.vfsfitvnm.vimusic.utils.SnapLayoutInfoProvider
|
|||||||
import it.vfsfitvnm.vimusic.utils.asMediaItem
|
import it.vfsfitvnm.vimusic.utils.asMediaItem
|
||||||
import it.vfsfitvnm.vimusic.utils.center
|
import it.vfsfitvnm.vimusic.utils.center
|
||||||
import it.vfsfitvnm.vimusic.utils.forcePlay
|
import it.vfsfitvnm.vimusic.utils.forcePlay
|
||||||
import it.vfsfitvnm.vimusic.utils.produceSaveableOneShotState
|
|
||||||
import it.vfsfitvnm.vimusic.utils.produceSaveableState
|
|
||||||
import it.vfsfitvnm.vimusic.utils.secondary
|
import it.vfsfitvnm.vimusic.utils.secondary
|
||||||
import it.vfsfitvnm.vimusic.utils.semiBold
|
import it.vfsfitvnm.vimusic.utils.semiBold
|
||||||
import it.vfsfitvnm.youtubemusic.Innertube
|
import it.vfsfitvnm.youtubemusic.Innertube
|
||||||
@@ -92,22 +94,25 @@ fun QuickPicks(
|
|||||||
val menuState = LocalMenuState.current
|
val menuState = LocalMenuState.current
|
||||||
val windowInsets = LocalPlayerAwareWindowInsets.current
|
val windowInsets = LocalPlayerAwareWindowInsets.current
|
||||||
|
|
||||||
val trending by produceSaveableState(
|
var trending by rememberSaveable(stateSaver = nullableSaver(DetailedSongSaver)) {
|
||||||
initialValue = null,
|
mutableStateOf(null)
|
||||||
stateSaver = nullableSaver(DetailedSongSaver),
|
}
|
||||||
) {
|
|
||||||
|
var relatedPageResult by rememberSaveable(stateSaver = resultSaver(nullableSaver(InnertubeRelatedPageSaver))) {
|
||||||
|
mutableStateOf(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
LaunchedEffect(Unit) {
|
||||||
Database.trending()
|
Database.trending()
|
||||||
.flowOn(Dispatchers.IO)
|
.flowOn(Dispatchers.IO)
|
||||||
.distinctUntilChanged()
|
.distinctUntilChanged()
|
||||||
.collect { value = it }
|
.collect { song ->
|
||||||
}
|
if ((song == null && relatedPageResult == null) || trending?.id != song?.id) {
|
||||||
|
relatedPageResult =
|
||||||
val relatedPageResult by produceSaveableOneShotState(
|
Innertube.relatedPage(NextBody(videoId = (song?.id ?: "J7p4bzqLvCw")))
|
||||||
initialValue = null,
|
}
|
||||||
stateSaver = resultSaver(nullableSaver(InnertubeRelatedPageSaver)),
|
trending = song
|
||||||
trending?.id
|
}
|
||||||
) {
|
|
||||||
value = Innertube.relatedPage(NextBody(videoId = (trending?.id ?: "J7p4bzqLvCw")))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val songThumbnailSizeDp = Dimensions.thumbnails.song
|
val songThumbnailSizeDp = Dimensions.thumbnails.song
|
||||||
@@ -124,7 +129,7 @@ fun QuickPicks(
|
|||||||
val snapLayoutInfoProvider = remember(quickPicksLazyGridState) {
|
val snapLayoutInfoProvider = remember(quickPicksLazyGridState) {
|
||||||
SnapLayoutInfoProvider(
|
SnapLayoutInfoProvider(
|
||||||
lazyGridState = quickPicksLazyGridState,
|
lazyGridState = quickPicksLazyGridState,
|
||||||
positionInLayout = {layoutSize, itemSize ->
|
positionInLayout = { layoutSize, itemSize ->
|
||||||
(layoutSize * quickPicksLazyGridItemWidthFactor / 2f - itemSize / 2f)
|
(layoutSize * quickPicksLazyGridItemWidthFactor / 2f - itemSize / 2f)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@@ -172,13 +177,13 @@ fun QuickPicks(
|
|||||||
thumbnailSizePx = songThumbnailSizePx,
|
thumbnailSizePx = songThumbnailSizePx,
|
||||||
thumbnailSizeDp = songThumbnailSizeDp,
|
thumbnailSizeDp = songThumbnailSizeDp,
|
||||||
trailingContent = {
|
trailingContent = {
|
||||||
Image(
|
Image(
|
||||||
painter = painterResource(R.drawable.star),
|
painter = painterResource(R.drawable.star),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
colorFilter = ColorFilter.tint(colorPalette.accent),
|
colorFilter = ColorFilter.tint(colorPalette.accent),
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(16.dp)
|
.size(16.dp)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.combinedClickable(
|
.combinedClickable(
|
||||||
@@ -211,7 +216,8 @@ fun QuickPicks(
|
|||||||
}
|
}
|
||||||
|
|
||||||
items(
|
items(
|
||||||
items = related.songs?.dropLast(if (trending == null) 0 else 1) ?: emptyList(),
|
items = related.songs?.dropLast(if (trending == null) 0 else 1)
|
||||||
|
?: emptyList(),
|
||||||
key = Innertube.SongItem::key
|
key = Innertube.SongItem::key
|
||||||
) { song ->
|
) { song ->
|
||||||
SongItem(
|
SongItem(
|
||||||
|
|||||||
Reference in New Issue
Block a user