mirror of
https://github.com/kalarina-bit/Fogwave.git
synced 2026-11-22 08:06:09 +00:00
Add station-colored fog, misty home backdrop and logo fitting; bring back next in mini player
This commit is contained in:
@@ -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
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -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
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -25,6 +25,7 @@ import androidx.compose.foundation.layout.widthIn
|
|||||||
import androidx.compose.foundation.shape.CircleShape
|
import androidx.compose.foundation.shape.CircleShape
|
||||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||||
import androidx.compose.material3.CircularProgressIndicator
|
import androidx.compose.material3.CircularProgressIndicator
|
||||||
|
import androidx.compose.material3.IconButton
|
||||||
import androidx.compose.material3.MaterialTheme
|
import androidx.compose.material3.MaterialTheme
|
||||||
import androidx.compose.material3.Text
|
import androidx.compose.material3.Text
|
||||||
import androidx.compose.material3.ripple
|
import androidx.compose.material3.ripple
|
||||||
@@ -61,6 +62,7 @@ fun MiniPlayer(
|
|||||||
playerState: PlayerState,
|
playerState: PlayerState,
|
||||||
trackTitle: String?,
|
trackTitle: String?,
|
||||||
onTogglePlay: () -> Unit,
|
onTogglePlay: () -> Unit,
|
||||||
|
onNext: () -> Unit,
|
||||||
onOpenNowPlaying: () -> Unit,
|
onOpenNowPlaying: () -> Unit,
|
||||||
onHide: () -> Unit,
|
onHide: () -> Unit,
|
||||||
modifier: Modifier = Modifier
|
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"),
|
.testTag("mini_player"),
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ import androidx.compose.ui.draw.drawBehind
|
|||||||
import androidx.compose.ui.draw.scale
|
import androidx.compose.ui.draw.scale
|
||||||
import androidx.compose.ui.draw.shadow
|
import androidx.compose.ui.draw.shadow
|
||||||
import androidx.compose.ui.geometry.Offset
|
import androidx.compose.ui.geometry.Offset
|
||||||
|
import androidx.compose.ui.graphics.Brush
|
||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
|
||||||
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
|
||||||
@@ -121,6 +122,11 @@ fun NowPlayingSheet(
|
|||||||
onDismiss = { currentOnClose() }
|
onDismiss = { currentOnClose() }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
val accent by animateColorAsState(
|
||||||
|
targetValue = rememberStationArt(station).accentOr(colors.accentLavender),
|
||||||
|
animationSpec = tween(700),
|
||||||
|
label = "page_accent"
|
||||||
|
)
|
||||||
val discScale by animateFloatAsState(
|
val discScale by animateFloatAsState(
|
||||||
targetValue = if (isPlaying) 1f else 0.94f,
|
targetValue = if (isPlaying) 1f else 0.94f,
|
||||||
animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy),
|
animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy),
|
||||||
@@ -140,7 +146,7 @@ fun NowPlayingSheet(
|
|||||||
val isTablet = maxWidth > 600.dp
|
val isTablet = maxWidth > 600.dp
|
||||||
val pageWidth = if (isTablet) Modifier.widthIn(max = 560.dp) else Modifier.fillMaxWidth()
|
val pageWidth = if (isTablet) Modifier.widthIn(max = 560.dp) else Modifier.fillMaxWidth()
|
||||||
|
|
||||||
Column(
|
Box(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.align(Alignment.TopCenter)
|
.align(Alignment.TopCenter)
|
||||||
.then(sheetModifier)
|
.then(sheetModifier)
|
||||||
@@ -150,13 +156,42 @@ fun NowPlayingSheet(
|
|||||||
.background(colors.background)
|
.background(colors.background)
|
||||||
// Swallow taps so nothing underneath reacts to them.
|
// Swallow taps so nothing underneath reacts to them.
|
||||||
.pointerInput(Unit) { detectTapGestures { } }
|
.pointerInput(Unit) { detectTapGestures { } }
|
||||||
|
.testTag("now_playing_sheet")
|
||||||
|
) {
|
||||||
|
// Fog in the station's color drifts behind the disc and fades into the page.
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth()
|
||||||
|
.height(620.dp)
|
||||||
|
) {
|
||||||
|
FogLayer(
|
||||||
|
tint = accent,
|
||||||
|
intensity = if (isPlaying) 0.9f else 0.45f,
|
||||||
|
modifier = Modifier.matchParentSize()
|
||||||
|
)
|
||||||
|
Box(
|
||||||
|
modifier = Modifier
|
||||||
|
.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
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Column(
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxSize()
|
||||||
// The page scrolls; drags the content cannot use pull it down to close.
|
// The page scrolls; drags the content cannot use pull it down to close.
|
||||||
.nestedScroll(drag.nestedScrollConnection)
|
.nestedScroll(drag.nestedScrollConnection)
|
||||||
.verticalScroll(rememberScrollState())
|
.verticalScroll(rememberScrollState())
|
||||||
.statusBarsPadding()
|
.statusBarsPadding()
|
||||||
.navigationBarsPadding()
|
.navigationBarsPadding()
|
||||||
.padding(bottom = 24.dp)
|
.padding(bottom = 24.dp),
|
||||||
.testTag("now_playing_sheet"),
|
|
||||||
horizontalAlignment = Alignment.CenterHorizontally
|
horizontalAlignment = Alignment.CenterHorizontally
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
@@ -187,6 +222,7 @@ fun NowPlayingSheet(
|
|||||||
StationDisc(
|
StationDisc(
|
||||||
station = station,
|
station = station,
|
||||||
isPlaying = isPlaying,
|
isPlaying = isPlaying,
|
||||||
|
glow = false,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(top = 12.dp, bottom = 20.dp)
|
.padding(top = 12.dp, bottom = 20.dp)
|
||||||
.fillMaxWidth(if (isTablet) 0.6f else 0.74f)
|
.fillMaxWidth(if (isTablet) 0.6f else 0.74f)
|
||||||
@@ -382,6 +418,7 @@ fun NowPlayingSheet(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Lower card of the player: track history, recent and similar stations, station info. */
|
/** Lower card of the player: track history, recent and similar stations, station info. */
|
||||||
|
|||||||
@@ -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<Int, StationArt>()
|
||||||
|
|
||||||
|
@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
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
package cc.skysparkle.fogwave.ui.components
|
package cc.skysparkle.fogwave.ui.components
|
||||||
|
|
||||||
|
import androidx.compose.animation.animateColorAsState
|
||||||
import androidx.compose.animation.core.Animatable
|
import androidx.compose.animation.core.Animatable
|
||||||
import androidx.compose.animation.core.LinearEasing
|
import androidx.compose.animation.core.LinearEasing
|
||||||
import androidx.compose.animation.core.tween
|
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.foundation.shape.CircleShape
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
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.Color
|
||||||
import androidx.compose.ui.graphics.StrokeCap
|
import androidx.compose.ui.graphics.StrokeCap
|
||||||
import androidx.compose.ui.graphics.drawscope.Stroke
|
import androidx.compose.ui.graphics.drawscope.Stroke
|
||||||
|
import androidx.compose.ui.graphics.graphicsLayer
|
||||||
import androidx.compose.ui.layout.ContentScale
|
import androidx.compose.ui.layout.ContentScale
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.unit.Dp
|
import androidx.compose.ui.unit.Dp
|
||||||
@@ -38,8 +41,8 @@ private const val ARC_SWEEP = 280f
|
|||||||
private const val TURN_MILLIS = 14_000
|
private const val TURN_MILLIS = 14_000
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Round station artwork wrapped in a ring. Live radio has no track progress, so the arc slowly
|
* Round station artwork wrapped in a ring in the station's own color. Live radio has no track
|
||||||
* circles while the station plays and rests where it was when playback stops.
|
* progress, so the arc slowly circles while the station plays and rests where it was when it stops.
|
||||||
*/
|
*/
|
||||||
@Composable
|
@Composable
|
||||||
fun StationDisc(
|
fun StationDisc(
|
||||||
@@ -51,6 +54,12 @@ fun StationDisc(
|
|||||||
glow: Boolean = true
|
glow: Boolean = true
|
||||||
) {
|
) {
|
||||||
val colors = LocalGeoColors.current
|
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) }
|
val rotation = remember { Animatable(0f) }
|
||||||
|
|
||||||
LaunchedEffect(isPlaying) {
|
LaunchedEffect(isPlaying) {
|
||||||
@@ -73,7 +82,7 @@ fun StationDisc(
|
|||||||
if (glow) {
|
if (glow) {
|
||||||
drawCircle(
|
drawCircle(
|
||||||
brush = Brush.radialGradient(
|
brush = Brush.radialGradient(
|
||||||
colors = listOf(colors.accentLavender.copy(alpha = 0.28f), Color.Transparent),
|
colors = listOf(accent.copy(alpha = 0.28f), Color.Transparent),
|
||||||
center = center,
|
center = center,
|
||||||
radius = radius * 1.25f
|
radius = radius * 1.25f
|
||||||
),
|
),
|
||||||
@@ -91,7 +100,7 @@ fun StationDisc(
|
|||||||
|
|
||||||
val start = -90f + rotation.value
|
val start = -90f + rotation.value
|
||||||
drawArc(
|
drawArc(
|
||||||
color = colors.primary,
|
color = accent,
|
||||||
startAngle = start,
|
startAngle = start,
|
||||||
sweepAngle = ARC_SWEEP,
|
sweepAngle = ARC_SWEEP,
|
||||||
useCenter = false,
|
useCenter = false,
|
||||||
@@ -105,7 +114,7 @@ fun StationDisc(
|
|||||||
center.x + radius * cos(end).toFloat(),
|
center.x + radius * cos(end).toFloat(),
|
||||||
center.y + radius * sin(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)
|
drawCircle(color = Color.White, radius = stroke * 0.8f, center = knob)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,12 +127,23 @@ fun StationDisc(
|
|||||||
.border(1.dp, colors.outlineVariant, CircleShape),
|
.border(1.dp, colors.outlineVariant, CircleShape),
|
||||||
contentAlignment = Alignment.Center
|
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(
|
Image(
|
||||||
painter = painterResource(id = station.iconResId),
|
painter = painterResource(id = station.iconResId),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
contentScale = ContentScale.Fit,
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -105,6 +105,7 @@ fun StationThumb(
|
|||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
cornerRadius: Dp = 12.dp
|
cornerRadius: Dp = 12.dp
|
||||||
) {
|
) {
|
||||||
|
val art = rememberStationArt(station)
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.size(size)
|
.size(size)
|
||||||
@@ -115,7 +116,17 @@ fun StationThumb(
|
|||||||
painter = painterResource(id = station.iconResId),
|
painter = painterResource(id = station.iconResId),
|
||||||
contentDescription = null,
|
contentDescription = null,
|
||||||
contentScale = ContentScale.Crop,
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package cc.skysparkle.fogwave.ui.screens
|
|||||||
|
|
||||||
import androidx.activity.compose.BackHandler
|
import androidx.activity.compose.BackHandler
|
||||||
import androidx.compose.animation.AnimatedContent
|
import androidx.compose.animation.AnimatedContent
|
||||||
|
import androidx.compose.animation.animateColorAsState
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.ExitTransition
|
import androidx.compose.animation.ExitTransition
|
||||||
import androidx.compose.animation.ExperimentalAnimationApi
|
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.navigationBarsPadding
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.lazy.LazyColumn
|
import androidx.compose.foundation.lazy.LazyColumn
|
||||||
|
import androidx.compose.foundation.lazy.LazyListState
|
||||||
import androidx.compose.foundation.lazy.items
|
import androidx.compose.foundation.lazy.items
|
||||||
|
import androidx.compose.foundation.lazy.rememberLazyListState
|
||||||
import androidx.compose.foundation.rememberScrollState
|
import androidx.compose.foundation.rememberScrollState
|
||||||
import androidx.compose.foundation.verticalScroll
|
import androidx.compose.foundation.verticalScroll
|
||||||
import androidx.compose.material3.MaterialTheme
|
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.EqualizerSheet
|
||||||
import cc.skysparkle.fogwave.ui.components.FavoritesPanel
|
import cc.skysparkle.fogwave.ui.components.FavoritesPanel
|
||||||
import cc.skysparkle.fogwave.ui.components.GenreCarousel
|
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.MiniPlayer
|
||||||
import cc.skysparkle.fogwave.ui.components.NavigationTabs
|
import cc.skysparkle.fogwave.ui.components.NavigationTabs
|
||||||
import cc.skysparkle.fogwave.ui.components.NowPlayingSheet
|
import cc.skysparkle.fogwave.ui.components.NowPlayingSheet
|
||||||
import cc.skysparkle.fogwave.ui.components.SectionHeader
|
import cc.skysparkle.fogwave.ui.components.SectionHeader
|
||||||
import cc.skysparkle.fogwave.ui.components.StationRow
|
import cc.skysparkle.fogwave.ui.components.StationRow
|
||||||
import cc.skysparkle.fogwave.ui.components.TopBrandBar
|
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.components.stationDescription
|
||||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||||
import cc.skysparkle.fogwave.ui.viewmodel.RadioViewModel
|
import cc.skysparkle.fogwave.ui.viewmodel.RadioViewModel
|
||||||
@@ -109,6 +115,13 @@ fun HomeScreen(
|
|||||||
BatteryOptimizationDialog(onDismiss = { viewModel.dismissBatteryOptimizationPrompt() })
|
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
|
val density = LocalDensity.current
|
||||||
var dockHeight by remember { mutableStateOf(160.dp) }
|
var dockHeight by remember { mutableStateOf(160.dp) }
|
||||||
val scrollBottomPadding = dockHeight + 16.dp
|
val scrollBottomPadding = dockHeight + 16.dp
|
||||||
@@ -118,6 +131,19 @@ fun HomeScreen(
|
|||||||
.fillMaxSize()
|
.fillMaxSize()
|
||||||
.background(LocalGeoColors.current.background)
|
.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()) {
|
Column(modifier = Modifier.fillMaxSize()) {
|
||||||
TopBrandBar(
|
TopBrandBar(
|
||||||
showSearch = uiState.selectedTab == AppTab.RADIO,
|
showSearch = uiState.selectedTab == AppTab.RADIO,
|
||||||
@@ -144,6 +170,7 @@ fun HomeScreen(
|
|||||||
) { tab ->
|
) { tab ->
|
||||||
when (tab) {
|
when (tab) {
|
||||||
AppTab.RADIO -> RadioTab(
|
AppTab.RADIO -> RadioTab(
|
||||||
|
listState = radioListState,
|
||||||
stations = uiState.stations,
|
stations = uiState.stations,
|
||||||
currentStation = uiState.currentStation,
|
currentStation = uiState.currentStation,
|
||||||
isPlaying = isPlaying,
|
isPlaying = isPlaying,
|
||||||
@@ -202,6 +229,7 @@ fun HomeScreen(
|
|||||||
playerState = uiState.playerState,
|
playerState = uiState.playerState,
|
||||||
trackTitle = uiState.nowPlayingTitle,
|
trackTitle = uiState.nowPlayingTitle,
|
||||||
onTogglePlay = { viewModel.togglePlay() },
|
onTogglePlay = { viewModel.togglePlay() },
|
||||||
|
onNext = { viewModel.nextStation() },
|
||||||
onOpenNowPlaying = { viewModel.openNowPlaying() },
|
onOpenNowPlaying = { viewModel.openNowPlaying() },
|
||||||
onHide = { viewModel.hideMiniPlayer() }
|
onHide = { viewModel.hideMiniPlayer() }
|
||||||
)
|
)
|
||||||
@@ -279,6 +307,7 @@ fun HomeScreen(
|
|||||||
/** Genre cards on top, then the (filtered) station list. */
|
/** Genre cards on top, then the (filtered) station list. */
|
||||||
@Composable
|
@Composable
|
||||||
private fun RadioTab(
|
private fun RadioTab(
|
||||||
|
listState: LazyListState,
|
||||||
stations: List<RadioStation>,
|
stations: List<RadioStation>,
|
||||||
currentStation: RadioStation?,
|
currentStation: RadioStation?,
|
||||||
isPlaying: Boolean,
|
isPlaying: Boolean,
|
||||||
@@ -299,6 +328,7 @@ private fun RadioTab(
|
|||||||
}
|
}
|
||||||
|
|
||||||
LazyColumn(
|
LazyColumn(
|
||||||
|
state = listState,
|
||||||
contentPadding = PaddingValues(top = 4.dp, bottom = bottomContentPadding),
|
contentPadding = PaddingValues(top = 4.dp, bottom = bottomContentPadding),
|
||||||
modifier = Modifier.fillMaxSize()
|
modifier = Modifier.fillMaxSize()
|
||||||
) {
|
) {
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 63 KiB |
Reference in New Issue
Block a user