diff --git a/app/src/main/java/cc/skysparkle/fogwave/ui/components/FogLayer.kt b/app/src/main/java/cc/skysparkle/fogwave/ui/components/FogLayer.kt new file mode 100644 index 0000000..2d7803a --- /dev/null +++ b/app/src/main/java/cc/skysparkle/fogwave/ui/components/FogLayer.kt @@ -0,0 +1,92 @@ +package cc.skysparkle.fogwave.ui.components + +import androidx.compose.animation.core.LinearEasing +import androidx.compose.animation.core.RepeatMode +import androidx.compose.animation.core.animateFloat +import androidx.compose.animation.core.infiniteRepeatable +import androidx.compose.animation.core.rememberInfiniteTransition +import androidx.compose.animation.core.tween +import androidx.compose.foundation.Canvas +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.drawscope.DrawScope +import androidx.compose.ui.graphics.lerp +import kotlin.math.PI +import kotlin.math.cos +import kotlin.math.max +import kotlin.math.sin + +/** One drifting patch of mist: where it rests, how far and how it wanders, and how big it is. */ +private class Wisp( + val x: Float, + val y: Float, + val dx: Float, + val dy: Float, + val phase: Float, + val radius: Float, + val alpha: Float, + val mix: Float +) + +private val Wisps = listOf( + Wisp(x = 0.18f, y = 0.30f, dx = 0.10f, dy = 0.05f, phase = 0.0f, radius = 0.62f, alpha = 0.55f, mix = 0.0f), + Wisp(x = 0.82f, y = 0.42f, dx = 0.08f, dy = 0.07f, phase = 1.9f, radius = 0.55f, alpha = 0.45f, mix = 0.35f), + Wisp(x = 0.50f, y = 0.70f, dx = 0.14f, dy = 0.04f, phase = 3.7f, radius = 0.70f, alpha = 0.35f, mix = 0.15f), + Wisp(x = 0.35f, y = 0.55f, dx = 0.06f, dy = 0.08f, phase = 5.1f, radius = 0.38f, alpha = 0.22f, mix = 0.8f) +) + +/** + * Slowly drifting colored fog — Fogwave's signature backdrop. [tint] is usually the playing + * station's color. Only the draw phase reads the animation, so the fog never recomposes anything. + */ +@Composable +fun FogLayer( + tint: Color, + modifier: Modifier = Modifier, + intensity: Float = 1f +) { + val transition = rememberInfiniteTransition(label = "fog") + val t by transition.animateFloat( + initialValue = 0f, + targetValue = (2 * PI).toFloat(), + animationSpec = infiniteRepeatable(tween(28_000, easing = LinearEasing), RepeatMode.Restart), + label = "fog_t" + ) + val breathe by transition.animateFloat( + initialValue = 0.85f, + targetValue = 1f, + animationSpec = infiniteRepeatable(tween(6_000), RepeatMode.Reverse), + label = "fog_breathe" + ) + + Canvas(modifier = modifier) { + Wisps.forEach { wisp -> drawWisp(wisp, t, breathe * intensity, tint) } + } +} + +private fun DrawScope.drawWisp(wisp: Wisp, time: Float, intensity: Float, tint: Color) { + val unit = max(size.width, size.height) + val center = Offset( + x = size.width * (wisp.x + wisp.dx * sin(time + wisp.phase)), + y = size.height * (wisp.y + wisp.dy * cos(time * 2f + wisp.phase)) + ) + val radius = unit * wisp.radius + // Part of the mist is paler, so the fog is not a flat single-color glow. + val color = lerp(tint, Color(0xFFDDE6FF), wisp.mix) + val a = (wisp.alpha * intensity).coerceIn(0f, 1f) + drawCircle( + brush = Brush.radialGradient( + 0f to color.copy(alpha = a), + 0.45f to color.copy(alpha = a * 0.35f), + 1f to Color.Transparent, + center = center, + radius = radius + ), + radius = radius, + center = center + ) +} diff --git a/app/src/main/java/cc/skysparkle/fogwave/ui/components/HomeBackdrop.kt b/app/src/main/java/cc/skysparkle/fogwave/ui/components/HomeBackdrop.kt new file mode 100644 index 0000000..883930e --- /dev/null +++ b/app/src/main/java/cc/skysparkle/fogwave/ui/components/HomeBackdrop.kt @@ -0,0 +1,79 @@ +package cc.skysparkle.fogwave.ui.components + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Brush +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.graphics.ColorMatrix +import androidx.compose.ui.graphics.graphicsLayer +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.unit.dp +import cc.skysparkle.fogwave.R +import cc.skysparkle.fogwave.ui.theme.LocalGeoColors +import coil.compose.AsyncImage +import coil.request.ImageRequest +import coil.size.Scale + +/** + * Misty peak at the top of the home screen with drifting fog in the playing station's color. + * [visibility] is read in the draw phase (0 = gone, 1 = fully shown) so scrolling never recomposes it. + */ +@Composable +fun HomeBackdrop( + tint: Color, + modifier: Modifier = Modifier, + visibility: () -> Float = { 1f } +) { + val context = LocalContext.current + val background = LocalGeoColors.current.background + val request = remember(context) { + ImageRequest.Builder(context) + .data(R.drawable.bg_misty_mountain) + .scale(Scale.FILL) + .crossfade(300) + .build() + } + // Cool, slightly desaturated photo so the colored fog and the UI stay in front. + val muted = remember { + ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(0.35f) }) + } + + Box( + modifier = modifier + .fillMaxWidth() + .height(420.dp) + .graphicsLayer { alpha = visibility().coerceIn(0f, 1f) } + ) { + AsyncImage( + model = request, + contentDescription = null, + contentScale = ContentScale.Crop, + alignment = Alignment.TopCenter, + colorFilter = muted, + alpha = 0.5f, + modifier = Modifier.fillMaxSize() + ) + FogLayer(tint = tint, intensity = 0.6f, modifier = Modifier.fillMaxSize()) + Box( + modifier = Modifier + .fillMaxSize() + .background( + Brush.verticalGradient( + 0f to background.copy(alpha = 0.45f), + 0.35f to background.copy(alpha = 0.15f), + 0.7f to background.copy(alpha = 0.7f), + 1f to background + ) + ) + ) + } +} diff --git a/app/src/main/java/cc/skysparkle/fogwave/ui/components/MiniPlayer.kt b/app/src/main/java/cc/skysparkle/fogwave/ui/components/MiniPlayer.kt index b2ca3ad..84e1479 100644 --- a/app/src/main/java/cc/skysparkle/fogwave/ui/components/MiniPlayer.kt +++ b/app/src/main/java/cc/skysparkle/fogwave/ui/components/MiniPlayer.kt @@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.widthIn import androidx.compose.foundation.shape.CircleShape import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.material3.ripple @@ -61,6 +62,7 @@ fun MiniPlayer( playerState: PlayerState, trackTitle: String?, onTogglePlay: () -> Unit, + onNext: () -> Unit, onOpenNowPlaying: () -> Unit, onHide: () -> Unit, modifier: Modifier = Modifier @@ -146,7 +148,7 @@ fun MiniPlayer( } } ) - .padding(start = 8.dp, end = 12.dp, top = 8.dp, bottom = 8.dp) + .padding(start = 8.dp, end = 4.dp, top = 8.dp, bottom = 8.dp) .testTag("mini_player"), verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.spacedBy(12.dp) @@ -211,6 +213,20 @@ fun MiniPlayer( ) } } + + IconButton( + onClick = onNext, + modifier = Modifier + .size(40.dp) + .testTag("mini_next_btn") + ) { + AppIcon( + resId = R.drawable.ic_skip_next, + contentDescription = stringResource(R.string.next_station_content_desc), + tint = colors.onSurfaceVariant, + size = 22.dp + ) + } } } } diff --git a/app/src/main/java/cc/skysparkle/fogwave/ui/components/NowPlayingSheet.kt b/app/src/main/java/cc/skysparkle/fogwave/ui/components/NowPlayingSheet.kt index bd060b9..20b29fe 100644 --- a/app/src/main/java/cc/skysparkle/fogwave/ui/components/NowPlayingSheet.kt +++ b/app/src/main/java/cc/skysparkle/fogwave/ui/components/NowPlayingSheet.kt @@ -53,6 +53,7 @@ import androidx.compose.ui.draw.drawBehind import androidx.compose.ui.draw.scale import androidx.compose.ui.draw.shadow import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.input.nestedscroll.NestedScrollConnection import androidx.compose.ui.input.nestedscroll.NestedScrollSource @@ -121,6 +122,11 @@ fun NowPlayingSheet( onDismiss = { currentOnClose() } ) } + val accent by animateColorAsState( + targetValue = rememberStationArt(station).accentOr(colors.accentLavender), + animationSpec = tween(700), + label = "page_accent" + ) val discScale by animateFloatAsState( targetValue = if (isPlaying) 1f else 0.94f, animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy), @@ -140,7 +146,7 @@ fun NowPlayingSheet( val isTablet = maxWidth > 600.dp val pageWidth = if (isTablet) Modifier.widthIn(max = 560.dp) else Modifier.fillMaxWidth() - Column( + Box( modifier = Modifier .align(Alignment.TopCenter) .then(sheetModifier) @@ -150,235 +156,266 @@ fun NowPlayingSheet( .background(colors.background) // Swallow taps so nothing underneath reacts to them. .pointerInput(Unit) { detectTapGestures { } } - // The page scrolls; drags the content cannot use pull it down to close. - .nestedScroll(drag.nestedScrollConnection) - .verticalScroll(rememberScrollState()) - .statusBarsPadding() - .navigationBarsPadding() - .padding(bottom = 24.dp) - .testTag("now_playing_sheet"), - horizontalAlignment = Alignment.CenterHorizontally + .testTag("now_playing_sheet") ) { - Row( + // Fog in the station's color drifts behind the disc and fades into the page. + Box( modifier = Modifier .fillMaxWidth() - .padding(horizontal = 8.dp, vertical = 4.dp), - verticalAlignment = Alignment.CenterVertically + .height(620.dp) ) { - IconButton(onClick = onClose, modifier = Modifier.testTag("np_close_btn")) { - AppIcon( - resId = R.drawable.ic_chevron_left, - contentDescription = stringResource(R.string.back_content_desc), - tint = colors.onSurface, - size = 26.dp - ) - } - Spacer(modifier = Modifier.weight(1f)) - IconButton(onClick = onOpenEqualizer, modifier = Modifier.testTag("np_equalizer_toggle")) { - AppIcon( - resId = R.drawable.ic_equalizer, - contentDescription = stringResource(R.string.equalizer_content_desc), - tint = if (audioEffects.equalizerEnabled) colors.primary else colors.onSurface, - size = 22.dp - ) - } - } - - StationDisc( - station = station, - isPlaying = isPlaying, - modifier = Modifier - .padding(top = 12.dp, bottom = 20.dp) - .fillMaxWidth(if (isTablet) 0.6f else 0.74f) - .scale(discScale) - ) - - Row( - modifier = Modifier - .fillMaxWidth() - .padding(horizontal = 24.dp), - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(4.dp) - ) { - Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) { - LiveLabel(active = isPlaying) - Text( - text = station.name, - style = MaterialTheme.typography.headlineSmall.copy( - fontWeight = FontWeight.ExtraBold, - fontSize = 22.sp, - letterSpacing = (-0.4).sp, - color = colors.deepPurple - ), - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) - Text( - text = "${station.bitrate} • ${stationGenres(station)}", - style = MaterialTheme.typography.bodySmall.copy( - fontSize = 12.sp, - color = colors.onSurfaceVariant - ), - maxLines = 1, - overflow = TextOverflow.Ellipsis - ) - } - - IconButton( - onClick = { context.shareStation(station, trackTitle) }, - modifier = Modifier.testTag("np_share_btn") - ) { - AppIcon( - resId = R.drawable.ic_share, - contentDescription = stringResource(R.string.share_content_desc), - tint = colors.onSurface, - size = 21.dp - ) - } - - val favScale by animateFloatAsState( - targetValue = if (isFavorite) 1.15f else 1f, - animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy), - label = "fav_scale" + FogLayer( + tint = accent, + intensity = if (isPlaying) 0.9f else 0.45f, + modifier = Modifier.matchParentSize() ) - IconButton( - onClick = onToggleFavorite, - modifier = Modifier - .scale(favScale) - .testTag("np_favorite_toggle") - ) { - AppIcon( - resId = if (isFavorite) R.drawable.ic_heart_fill else R.drawable.ic_heart_outline, - contentDescription = stringResource( - if (isFavorite) R.string.remove_from_favorites else R.string.add_to_favorites - ), - tint = if (isFavorite) colors.redFavorite else colors.onSurface, - size = 22.dp - ) - } - } - - Spacer(modifier = Modifier.height(22.dp)) - - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(6.dp) - ) { - AppIcon(resId = R.drawable.ic_music_note, tint = colors.onSurfaceVariant, size = 13.dp) - Text( - text = stringResource(R.string.now_playing_label), - style = MaterialTheme.typography.labelSmall.copy( - fontWeight = FontWeight.SemiBold, - fontSize = 10.5.sp, - letterSpacing = 1.2.sp, - color = colors.onSurfaceVariant - ) - ) - } - - Spacer(modifier = Modifier.height(6.dp)) - - Text( - text = when { - isError -> playerState.message - isConnecting -> stringResource(R.string.player_connecting) - !isPlaying -> stringResource(R.string.player_stopped) - else -> trackTitle ?: stationDescription(station) - }, - style = MaterialTheme.typography.titleMedium.copy( - fontWeight = FontWeight.SemiBold, - fontSize = 16.sp, - lineHeight = 21.sp, - textAlign = TextAlign.Center, - color = if (isError) colors.redFavorite else colors.onSurface - ), - maxLines = 2, - overflow = TextOverflow.Ellipsis, - modifier = Modifier - .padding(horizontal = 32.dp) - .heightIn(min = 42.dp) - .testTag("np_track_title") - ) - - Spacer(modifier = Modifier.height(18.dp)) - - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.spacedBy(28.dp) - ) { - IconButton( - onClick = onPrevious, - modifier = Modifier - .size(52.dp) - .testTag("np_prev_btn") - ) { - AppIcon( - resId = R.drawable.ic_skip_previous, - contentDescription = stringResource(R.string.previous_station_content_desc), - tint = colors.onSurface, - size = 28.dp - ) - } - Box( modifier = Modifier - .size(76.dp) - .shadow(14.dp, CircleShape, ambientColor = colors.accentLavender, spotColor = colors.accentLavender) - .clip(CircleShape) - .background(colors.accentLavender) - .clickable { onTogglePlay() } - .testTag("np_play_btn"), - contentAlignment = Alignment.Center - ) { - if (isConnecting) { - val connecting = stringResource(R.string.player_connecting) - CircularProgressIndicator( - modifier = Modifier - .size(32.dp) - .semantics { contentDescription = connecting }, - color = colors.onAccentLavender, - strokeWidth = 3.dp + .matchParentSize() + .background( + Brush.verticalGradient( + 0f to colors.background.copy(alpha = 0.35f), + 0.3f to Color.Transparent, + 0.75f to colors.background.copy(alpha = 0.6f), + 1f to colors.background + ) ) - } else { + ) + } + + Column( + modifier = Modifier + .fillMaxSize() + // The page scrolls; drags the content cannot use pull it down to close. + .nestedScroll(drag.nestedScrollConnection) + .verticalScroll(rememberScrollState()) + .statusBarsPadding() + .navigationBarsPadding() + .padding(bottom = 24.dp), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 8.dp, vertical = 4.dp), + verticalAlignment = Alignment.CenterVertically + ) { + IconButton(onClick = onClose, modifier = Modifier.testTag("np_close_btn")) { AppIcon( - resId = if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play, - contentDescription = stringResource( - if (isPlaying) R.string.pause_content_desc else R.string.play_content_desc - ), - tint = colors.onAccentLavender, - size = 32.dp + resId = R.drawable.ic_chevron_left, + contentDescription = stringResource(R.string.back_content_desc), + tint = colors.onSurface, + size = 26.dp + ) + } + Spacer(modifier = Modifier.weight(1f)) + IconButton(onClick = onOpenEqualizer, modifier = Modifier.testTag("np_equalizer_toggle")) { + AppIcon( + resId = R.drawable.ic_equalizer, + contentDescription = stringResource(R.string.equalizer_content_desc), + tint = if (audioEffects.equalizerEnabled) colors.primary else colors.onSurface, + size = 22.dp ) } } - IconButton( - onClick = onNext, + StationDisc( + station = station, + isPlaying = isPlaying, + glow = false, modifier = Modifier - .size(52.dp) - .testTag("np_next_btn") + .padding(top = 12.dp, bottom = 20.dp) + .fillMaxWidth(if (isTablet) 0.6f else 0.74f) + .scale(discScale) + ) + + Row( + modifier = Modifier + .fillMaxWidth() + .padding(horizontal = 24.dp), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(4.dp) ) { - AppIcon( - resId = R.drawable.ic_skip_next, - contentDescription = stringResource(R.string.next_station_content_desc), - tint = colors.onSurface, - size = 28.dp + Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) { + LiveLabel(active = isPlaying) + Text( + text = station.name, + style = MaterialTheme.typography.headlineSmall.copy( + fontWeight = FontWeight.ExtraBold, + fontSize = 22.sp, + letterSpacing = (-0.4).sp, + color = colors.deepPurple + ), + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + Text( + text = "${station.bitrate} • ${stationGenres(station)}", + style = MaterialTheme.typography.bodySmall.copy( + fontSize = 12.sp, + color = colors.onSurfaceVariant + ), + maxLines = 1, + overflow = TextOverflow.Ellipsis + ) + } + + IconButton( + onClick = { context.shareStation(station, trackTitle) }, + modifier = Modifier.testTag("np_share_btn") + ) { + AppIcon( + resId = R.drawable.ic_share, + contentDescription = stringResource(R.string.share_content_desc), + tint = colors.onSurface, + size = 21.dp + ) + } + + val favScale by animateFloatAsState( + targetValue = if (isFavorite) 1.15f else 1f, + animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy), + label = "fav_scale" + ) + IconButton( + onClick = onToggleFavorite, + modifier = Modifier + .scale(favScale) + .testTag("np_favorite_toggle") + ) { + AppIcon( + resId = if (isFavorite) R.drawable.ic_heart_fill else R.drawable.ic_heart_outline, + contentDescription = stringResource( + if (isFavorite) R.string.remove_from_favorites else R.string.add_to_favorites + ), + tint = if (isFavorite) colors.redFavorite else colors.onSurface, + size = 22.dp + ) + } + } + + Spacer(modifier = Modifier.height(22.dp)) + + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(6.dp) + ) { + AppIcon(resId = R.drawable.ic_music_note, tint = colors.onSurfaceVariant, size = 13.dp) + Text( + text = stringResource(R.string.now_playing_label), + style = MaterialTheme.typography.labelSmall.copy( + fontWeight = FontWeight.SemiBold, + fontSize = 10.5.sp, + letterSpacing = 1.2.sp, + color = colors.onSurfaceVariant + ) ) } + + Spacer(modifier = Modifier.height(6.dp)) + + Text( + text = when { + isError -> playerState.message + isConnecting -> stringResource(R.string.player_connecting) + !isPlaying -> stringResource(R.string.player_stopped) + else -> trackTitle ?: stationDescription(station) + }, + style = MaterialTheme.typography.titleMedium.copy( + fontWeight = FontWeight.SemiBold, + fontSize = 16.sp, + lineHeight = 21.sp, + textAlign = TextAlign.Center, + color = if (isError) colors.redFavorite else colors.onSurface + ), + maxLines = 2, + overflow = TextOverflow.Ellipsis, + modifier = Modifier + .padding(horizontal = 32.dp) + .heightIn(min = 42.dp) + .testTag("np_track_title") + ) + + Spacer(modifier = Modifier.height(18.dp)) + + Row( + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.spacedBy(28.dp) + ) { + IconButton( + onClick = onPrevious, + modifier = Modifier + .size(52.dp) + .testTag("np_prev_btn") + ) { + AppIcon( + resId = R.drawable.ic_skip_previous, + contentDescription = stringResource(R.string.previous_station_content_desc), + tint = colors.onSurface, + size = 28.dp + ) + } + + Box( + modifier = Modifier + .size(76.dp) + .shadow(14.dp, CircleShape, ambientColor = colors.accentLavender, spotColor = colors.accentLavender) + .clip(CircleShape) + .background(colors.accentLavender) + .clickable { onTogglePlay() } + .testTag("np_play_btn"), + contentAlignment = Alignment.Center + ) { + if (isConnecting) { + val connecting = stringResource(R.string.player_connecting) + CircularProgressIndicator( + modifier = Modifier + .size(32.dp) + .semantics { contentDescription = connecting }, + color = colors.onAccentLavender, + strokeWidth = 3.dp + ) + } else { + AppIcon( + resId = if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play, + contentDescription = stringResource( + if (isPlaying) R.string.pause_content_desc else R.string.play_content_desc + ), + tint = colors.onAccentLavender, + size = 32.dp + ) + } + } + + IconButton( + onClick = onNext, + modifier = Modifier + .size(52.dp) + .testTag("np_next_btn") + ) { + AppIcon( + resId = R.drawable.ic_skip_next, + contentDescription = stringResource(R.string.next_station_content_desc), + tint = colors.onSurface, + size = 28.dp + ) + } + } + + Spacer(modifier = Modifier.height(28.dp)) + + ExtraPanel( + station = station, + playerState = playerState, + trackTitle = trackTitle, + trackHistory = trackHistory, + activeExtraTab = activeExtraTab, + onSelectExtraTab = onSelectExtraTab, + recents = recents, + similarStations = similarStations, + onSelectStation = onSelectStation + ) } - - Spacer(modifier = Modifier.height(28.dp)) - - ExtraPanel( - station = station, - playerState = playerState, - trackTitle = trackTitle, - trackHistory = trackHistory, - activeExtraTab = activeExtraTab, - onSelectExtraTab = onSelectExtraTab, - recents = recents, - similarStations = similarStations, - onSelectStation = onSelectStation - ) } } } diff --git a/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationArt.kt b/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationArt.kt new file mode 100644 index 0000000..b344e1a --- /dev/null +++ b/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationArt.kt @@ -0,0 +1,132 @@ +package cc.skysparkle.fogwave.ui.components + +import android.content.res.Resources +import android.graphics.BitmapFactory +import androidx.compose.runtime.Composable +import androidx.compose.runtime.Immutable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.produceState +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalContext +import androidx.core.graphics.ColorUtils +import cc.skysparkle.fogwave.data.model.RadioStation +import java.util.concurrent.ConcurrentHashMap +import kotlin.math.abs +import kotlin.math.atan2 +import kotlin.math.cos +import kotlin.math.sin +import kotlin.math.sqrt +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.withContext + +/** + * What the UI needs to know about a station logo: its brand color (for the fog and the ring) + * and where the visible part of the logo sits, so wide wordmarks can be enlarged inside a circle. + */ +@Immutable +data class StationArt( + val accent: Color?, + val left: Float = 0f, + val top: Float = 0f, + val right: Float = 1f, + val bottom: Float = 1f +) { + /** Logos with their own square background are shown edge to edge instead of being shrunk. */ + val isFullBleed: Boolean get() = right - left > 0.97f && bottom - top > 0.97f + + /** Scale that fits the visible part of the logo into a circle of [fill] of its diameter. */ + fun circleScale(fill: Float = 0.86f): Float { + if (isFullBleed) return 1f + val w = right - left + val h = bottom - top + return (fill / sqrt(w * w + h * h)).coerceIn(0.5f, 1.7f) + } + + /** Scale that fits the visible part of the logo into [fill] of a square tile. */ + fun squareScale(fill: Float = 0.84f): Float { + if (isFullBleed) return 1f + return minOf(fill / (right - left), fill / (bottom - top)).coerceIn(1f, 1.5f) + } + + val centerX: Float get() = (left + right) / 2f + val centerY: Float get() = (top + bottom) / 2f +} + +private val cache = ConcurrentHashMap() + +@Composable +fun rememberStationArt(station: RadioStation): StationArt? { + val resources = LocalContext.current.resources + val art by produceState(initialValue = cache[station.iconResId], station.iconResId) { + value = cache[station.iconResId] ?: withContext(Dispatchers.Default) { + analyzeLogo(resources, station.iconResId).also { cache[station.iconResId] = it } + } + } + return art +} + +private fun analyzeLogo(resources: Resources, resId: Int): StationArt { + val options = BitmapFactory.Options().apply { inSampleSize = 4 } + val bitmap = BitmapFactory.decodeResource(resources, resId, options) ?: return StationArt(accent = null) + val w = bitmap.width + val h = bitmap.height + val pixels = IntArray(w * h) + bitmap.getPixels(pixels, 0, w, 0, 0, w, h) + bitmap.recycle() + + var minX = w + var minY = h + var maxX = -1 + var maxY = -1 + // Hue is averaged on the circle, weighted by how vivid each pixel is. + var hueX = 0.0 + var hueY = 0.0 + var weight = 0.0 + var opaque = 0 + val hsl = FloatArray(3) + + for (y in 0 until h) { + for (x in 0 until w) { + val c = pixels[y * w + x] + val alpha = c ushr 24 + if (alpha <= 24) continue + if (x < minX) minX = x + if (x > maxX) maxX = x + if (y < minY) minY = y + if (y > maxY) maxY = y + opaque++ + + ColorUtils.colorToHSL(c, hsl) + val vivid = hsl[1] * (1f - abs(hsl[2] - 0.5f) * 2f) + if (vivid < 0.25f) continue + val wgt = vivid.toDouble() * (alpha / 255.0) + val rad = Math.toRadians(hsl[0].toDouble()) + hueX += cos(rad) * wgt + hueY += sin(rad) * wgt + weight += wgt + } + } + + if (maxX < 0) return StationArt(accent = null) + + // Mostly black, white or grey logos keep the app's own blue. + val accent = if (opaque > 0 && weight / opaque > 0.08) { + var hue = Math.toDegrees(atan2(hueY, hueX)).toFloat() + if (hue < 0f) hue += 360f + // Same saturation and lightness for every station, so only the hue changes. + Color(ColorUtils.HSLToColor(floatArrayOf(hue, 0.78f, 0.6f))) + } else { + null + } + + return StationArt( + accent = accent, + left = minX / w.toFloat(), + top = minY / h.toFloat(), + right = (maxX + 1) / w.toFloat(), + bottom = (maxY + 1) / h.toFloat() + ) +} + +/** Station color, or the app accent when the logo has none. */ +fun StationArt?.accentOr(fallback: Color): Color = this?.accent ?: fallback diff --git a/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationDisc.kt b/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationDisc.kt index 9261f86..7b0474b 100644 --- a/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationDisc.kt +++ b/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationDisc.kt @@ -1,5 +1,6 @@ package cc.skysparkle.fogwave.ui.components +import androidx.compose.animation.animateColorAsState import androidx.compose.animation.core.Animatable import androidx.compose.animation.core.LinearEasing import androidx.compose.animation.core.tween @@ -14,6 +15,7 @@ import androidx.compose.foundation.layout.padding import androidx.compose.foundation.shape.CircleShape import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.getValue import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -24,6 +26,7 @@ import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.StrokeCap import androidx.compose.ui.graphics.drawscope.Stroke +import androidx.compose.ui.graphics.graphicsLayer import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.Dp @@ -38,8 +41,8 @@ private const val ARC_SWEEP = 280f private const val TURN_MILLIS = 14_000 /** - * Round station artwork wrapped in a ring. Live radio has no track progress, so the arc slowly - * circles while the station plays and rests where it was when playback stops. + * Round station artwork wrapped in a ring in the station's own color. Live radio has no track + * progress, so the arc slowly circles while the station plays and rests where it was when it stops. */ @Composable fun StationDisc( @@ -51,6 +54,12 @@ fun StationDisc( glow: Boolean = true ) { val colors = LocalGeoColors.current + val art = rememberStationArt(station) + val accent by animateColorAsState( + targetValue = art.accentOr(colors.primary), + animationSpec = tween(600), + label = "disc_accent" + ) val rotation = remember { Animatable(0f) } LaunchedEffect(isPlaying) { @@ -73,7 +82,7 @@ fun StationDisc( if (glow) { drawCircle( brush = Brush.radialGradient( - colors = listOf(colors.accentLavender.copy(alpha = 0.28f), Color.Transparent), + colors = listOf(accent.copy(alpha = 0.28f), Color.Transparent), center = center, radius = radius * 1.25f ), @@ -91,7 +100,7 @@ fun StationDisc( val start = -90f + rotation.value drawArc( - color = colors.primary, + color = accent, startAngle = start, sweepAngle = ARC_SWEEP, useCenter = false, @@ -105,7 +114,7 @@ fun StationDisc( center.x + radius * cos(end).toFloat(), center.y + radius * sin(end).toFloat() ) - drawCircle(color = colors.accentLavender, radius = stroke * 1.9f, center = knob) + drawCircle(color = accent, radius = stroke * 1.9f, center = knob) drawCircle(color = Color.White, radius = stroke * 0.8f, center = knob) } @@ -118,12 +127,23 @@ fun StationDisc( .border(1.dp, colors.outlineVariant, CircleShape), contentAlignment = Alignment.Center ) { - // Slightly larger than the inscribed square, so only the logo's corners get clipped. + // Wide wordmarks are enlarged and centered so they span the circle instead of + // floating small in the middle; square logos fill it edge to edge. Image( painter = painterResource(id = station.iconResId), contentDescription = null, contentScale = ContentScale.Fit, - modifier = Modifier.fillMaxSize(0.78f) + modifier = Modifier + .fillMaxSize() + .graphicsLayer { + val scale = art?.circleScale() ?: 0.78f + scaleX = scale + scaleY = scale + if (art != null) { + translationX = (0.5f - art.centerX) * size.width * scale + translationY = (0.5f - art.centerY) * size.height * scale + } + } ) } } diff --git a/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationRow.kt b/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationRow.kt index 27bc48b..a9d0ce0 100644 --- a/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationRow.kt +++ b/app/src/main/java/cc/skysparkle/fogwave/ui/components/StationRow.kt @@ -105,6 +105,7 @@ fun StationThumb( modifier: Modifier = Modifier, cornerRadius: Dp = 12.dp ) { + val art = rememberStationArt(station) Box( modifier = modifier .size(size) @@ -115,7 +116,17 @@ fun StationThumb( painter = painterResource(id = station.iconResId), contentDescription = null, contentScale = ContentScale.Crop, - modifier = Modifier.matchParentSize() + modifier = Modifier + .matchParentSize() + .graphicsLayer { + if (art != null) { + val scale = art.squareScale() + scaleX = scale + scaleY = scale + translationX = (0.5f - art.centerX) * this.size.width * scale + translationY = (0.5f - art.centerY) * this.size.height * scale + } + } ) } } diff --git a/app/src/main/java/cc/skysparkle/fogwave/ui/screens/HomeScreen.kt b/app/src/main/java/cc/skysparkle/fogwave/ui/screens/HomeScreen.kt index 3ac30fb..dd19b27 100644 --- a/app/src/main/java/cc/skysparkle/fogwave/ui/screens/HomeScreen.kt +++ b/app/src/main/java/cc/skysparkle/fogwave/ui/screens/HomeScreen.kt @@ -2,6 +2,7 @@ package cc.skysparkle.fogwave.ui.screens import androidx.activity.compose.BackHandler import androidx.compose.animation.AnimatedContent +import androidx.compose.animation.animateColorAsState import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.ExitTransition import androidx.compose.animation.ExperimentalAnimationApi @@ -28,7 +29,9 @@ import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.navigationBarsPadding import androidx.compose.foundation.layout.padding import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.LazyListState import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material3.MaterialTheme @@ -60,12 +63,15 @@ import cc.skysparkle.fogwave.ui.components.BatteryOptimizationDialog import cc.skysparkle.fogwave.ui.components.EqualizerSheet import cc.skysparkle.fogwave.ui.components.FavoritesPanel import cc.skysparkle.fogwave.ui.components.GenreCarousel +import cc.skysparkle.fogwave.ui.components.HomeBackdrop import cc.skysparkle.fogwave.ui.components.MiniPlayer import cc.skysparkle.fogwave.ui.components.NavigationTabs import cc.skysparkle.fogwave.ui.components.NowPlayingSheet import cc.skysparkle.fogwave.ui.components.SectionHeader import cc.skysparkle.fogwave.ui.components.StationRow import cc.skysparkle.fogwave.ui.components.TopBrandBar +import cc.skysparkle.fogwave.ui.components.accentOr +import cc.skysparkle.fogwave.ui.components.rememberStationArt import cc.skysparkle.fogwave.ui.components.stationDescription import cc.skysparkle.fogwave.ui.theme.LocalGeoColors import cc.skysparkle.fogwave.ui.viewmodel.RadioViewModel @@ -109,6 +115,13 @@ fun HomeScreen( BatteryOptimizationDialog(onDismiss = { viewModel.dismissBatteryOptimizationPrompt() }) } + val radioListState = rememberLazyListState() + val accent by animateColorAsState( + targetValue = uiState.currentStation?.let { rememberStationArt(it) }.accentOr(LocalGeoColors.current.accentLavender), + animationSpec = tween(700), + label = "home_accent" + ) + val density = LocalDensity.current var dockHeight by remember { mutableStateOf(160.dp) } val scrollBottomPadding = dockHeight + 16.dp @@ -118,6 +131,19 @@ fun HomeScreen( .fillMaxSize() .background(LocalGeoColors.current.background) ) { + HomeBackdrop( + tint = accent, + visibility = { + if (uiState.selectedTab != AppTab.RADIO) { + 0.55f + } else if (radioListState.firstVisibleItemIndex > 0) { + 0.3f + } else { + 1f - radioListState.firstVisibleItemScrollOffset / with(density) { 420.dp.toPx() } * 0.7f + } + } + ) + Column(modifier = Modifier.fillMaxSize()) { TopBrandBar( showSearch = uiState.selectedTab == AppTab.RADIO, @@ -144,6 +170,7 @@ fun HomeScreen( ) { tab -> when (tab) { AppTab.RADIO -> RadioTab( + listState = radioListState, stations = uiState.stations, currentStation = uiState.currentStation, isPlaying = isPlaying, @@ -202,6 +229,7 @@ fun HomeScreen( playerState = uiState.playerState, trackTitle = uiState.nowPlayingTitle, onTogglePlay = { viewModel.togglePlay() }, + onNext = { viewModel.nextStation() }, onOpenNowPlaying = { viewModel.openNowPlaying() }, onHide = { viewModel.hideMiniPlayer() } ) @@ -279,6 +307,7 @@ fun HomeScreen( /** Genre cards on top, then the (filtered) station list. */ @Composable private fun RadioTab( + listState: LazyListState, stations: List, currentStation: RadioStation?, isPlaying: Boolean, @@ -299,6 +328,7 @@ private fun RadioTab( } LazyColumn( + state = listState, contentPadding = PaddingValues(top = 4.dp, bottom = bottomContentPadding), modifier = Modifier.fillMaxSize() ) { diff --git a/app/src/main/res/drawable-nodpi/bg_misty_mountain.webp b/app/src/main/res/drawable-nodpi/bg_misty_mountain.webp new file mode 100644 index 0000000..bb5740a Binary files /dev/null and b/app/src/main/res/drawable-nodpi/bg_misty_mountain.webp differ