Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
127 changes: 120 additions & 7 deletions app/src/main/java/btm/m/auraplayer/ui/LibraryPages.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.layout.LayoutCoordinates
import androidx.compose.ui.layout.layout
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.layout.positionInWindow
import androidx.compose.ui.platform.LocalContext
Expand Down Expand Up @@ -1101,6 +1102,75 @@ private fun BlurredPlaylistCoverBackdrop(
}
}

/**
* Covers the strip that PullToRefresh opens above the playlist hero while the user pulls down.
*
* It lives *under* PullToRefresh so the refresh indicator stays on top, and it paints exactly one
* copy of the artwork: the same blurred cover, bottom-aligned with the hero and scaled up so its
* top edge reaches the window top. `PlaylistHeroHeader` hides its own backdrop as soon as this
* layer is active, so the two never end up drawn together at different scales.
*/
@Composable
private fun PlaylistHeroStretchBackdrop(
coverUri: String,
bannerTheme: HomeBannerTheme,
pageTopWindow: State<Float>,
heroTopWindow: State<Float>,
heroHeightPx: State<Float>,
modifier: Modifier = Modifier,
) {
val heroHeight = heroHeightPx.value
if (heroHeight <= 0f) return
val heroHeightDp = with(LocalDensity.current) { heroHeight.toDp() }

Box(
modifier
.fillMaxWidth()
.layout { measurable, constraints ->
val gap = (heroTopWindow.value - pageTopWindow.value).coerceAtLeast(0f)
val height = (gap + heroHeight).roundToInt()
.coerceIn(0, constraints.maxHeight)
if (height == 0) {
layout(constraints.maxWidth, 0) {}
} else {
val placeable = measurable.measure(
Constraints.fixed(constraints.maxWidth, height),
)
layout(constraints.maxWidth, height) { placeable.place(0, 0) }
}
}
.clipToBounds(),
) {
Box(
Modifier
.fillMaxWidth()
.height(heroHeightDp)
.graphicsLayer {
val gap = (heroTopWindow.value - pageTopWindow.value).coerceAtLeast(0f)
if (gap > 0f && size.height > 0f) {
val scale = (size.height + gap) / size.height
scaleX = scale
scaleY = scale
transformOrigin = TransformOrigin(0.5f, 1f)
translationY = gap
}
},
) {
ImmersiveBannerSurfaceBackdrop(
bannerTheme = bannerTheme,
backgroundStyle = HomeBackgroundStyle.COLOR,
modifier = Modifier.matchParentSize(),
) {
BlurredPlaylistCoverBackdrop(
coverUri = coverUri,
bannerTheme = bannerTheme,
modifier = Modifier.fillMaxSize(),
)
}
}
}
}

@Composable
private fun PlaylistHeroHeader(
title: String,
Expand All @@ -1110,6 +1180,8 @@ private fun PlaylistHeroHeader(
immersiveTopPadding: Dp,
pageMargin: Dp,
playEnabled: Boolean,
pageTopWindow: State<Float>,
heroTopWindow: State<Float>,
onPlay: () -> Unit,
onShuffle: () -> Unit,
) {
Expand All @@ -1129,16 +1201,29 @@ private fun PlaylistHeroHeader(
val topPad = immersiveTopPadding + 10.dp

Box(Modifier.fillMaxWidth()) {
ImmersiveBannerSurfaceBackdrop(
bannerTheme = bannerTheme,
backgroundStyle = HomeBackgroundStyle.COLOR,
modifier = Modifier.matchParentSize(),
// While PullToRefresh pulls down, PlaylistHeroStretchBackdrop paints the artwork from the
// page top down to the hero's bottom edge. As soon as that layer takes over, step aside
// completely: keeping both copies on screen shows the same cover at two different scales,
// which reads as a doubled, misaligned image right at the seam.
Box(
Modifier
.matchParentSize()
.graphicsLayer {
val gap = heroTopWindow.value - pageTopWindow.value
alpha = if (gap > 0.5f) 0f else 1f
},
) {
BlurredPlaylistCoverBackdrop(
coverUri = coverUri,
ImmersiveBannerSurfaceBackdrop(
bannerTheme = bannerTheme,
backgroundStyle = HomeBackgroundStyle.COLOR,
modifier = Modifier.fillMaxSize(),
)
) {
BlurredPlaylistCoverBackdrop(
coverUri = coverUri,
bannerTheme = bannerTheme,
modifier = Modifier.fillMaxSize(),
)
}
}
Row(
modifier = Modifier
Expand Down Expand Up @@ -1440,6 +1525,12 @@ internal fun CollectionPage(
val displayTracks = if (isDraggingOrSettling) orderedTracks else filteredTracks
val pullToRefreshState = rememberPullToRefreshState()
var isRefreshing by remember(collection.key) { mutableStateOf(false) }
// Window-space anchors for the pull-to-refresh stretch effect. Written during layout and
// read inside PlaylistHeroStretchBackdrop / the hero's graphicsLayer only, so pulling never
// recomposes this page.
val pageTopWindow = remember { mutableFloatStateOf(0f) }
val heroTopWindow = remember { mutableFloatStateOf(0f) }
val heroHeightPx = remember { mutableFloatStateOf(0f) }

LaunchedEffect(isRefreshing) {
if (!isRefreshing) return@LaunchedEffect
Expand All @@ -1465,6 +1556,18 @@ internal fun CollectionPage(
}
}

Box(
Modifier
.fillMaxSize()
.onGloballyPositioned { pageTopWindow.floatValue = it.positionInWindow().y },
) {
PlaylistHeroStretchBackdrop(
coverUri = coverUri,
bannerTheme = resolvedTheme,
pageTopWindow = pageTopWindow,
heroTopWindow = heroTopWindow,
heroHeightPx = heroHeightPx,
)
PullToRefresh(
isRefreshing = isRefreshing,
onRefresh = { if (draggingKey == null) isRefreshing = true },
Expand Down Expand Up @@ -1494,6 +1597,12 @@ internal fun CollectionPage(
userScrollEnabled = draggingKey == null,
) {
item("playlist_hero") {
Box(
Modifier.onGloballyPositioned { coords ->
heroTopWindow.floatValue = coords.positionInWindow().y
heroHeightPx.floatValue = coords.size.height.toFloat()
},
) {
PlaylistHeroHeader(
title = collection.title,
coverUri = coverUri,
Expand All @@ -1502,9 +1611,12 @@ internal fun CollectionPage(
immersiveTopPadding = activeTopPadding,
pageMargin = pageMargin,
playEnabled = displayTracks.isNotEmpty(),
pageTopWindow = pageTopWindow,
heroTopWindow = heroTopWindow,
onPlay = { model.playCollection(displayTracks, content = if (filtering) null else cloud) },
onShuffle = { model.playCollection(displayTracks, content = if (filtering) null else cloud, shuffle = true) },
)
}
}
if (displayTracks.isEmpty() && (cloud == null || !cloud.loading && !cloud.failed && !cloud.hasMore)) item {
Box(Modifier.padding(horizontal = pageMargin)) { EmptyState(tr("no_songs", "没有找到歌曲")) }
Expand Down Expand Up @@ -1778,6 +1890,7 @@ internal fun CollectionPage(
}
}
}
}
if (addToPlaylist && localPlaylist != null) PlaylistSongPicker(model, localPlaylist, onDismissAddToPlaylist)
}

Expand Down