mirror of
https://github.com/kalarina-bit/Fogwave.git
synced 2026-11-22 08:06:09 +00:00
Redesign UI: genre cards, search, station disc player and track history
This commit is contained in:
@@ -29,20 +29,6 @@ enum class Genre(@param:StringRes val labelRes: Int) {
|
||||
LATVIAN(R.string.genre_latvian)
|
||||
}
|
||||
|
||||
enum class ViewMode {
|
||||
ICONS,
|
||||
TILES,
|
||||
LIST,
|
||||
DETAILS
|
||||
}
|
||||
|
||||
enum class IconSizeStep(val sizeDp: Int) {
|
||||
S(64),
|
||||
M(96),
|
||||
L(132),
|
||||
XL(176)
|
||||
}
|
||||
|
||||
enum class AppTab(@param:StringRes val titleRes: Int) {
|
||||
RADIO(R.string.tab_radio),
|
||||
FAVORITES(R.string.tab_favorites),
|
||||
@@ -50,7 +36,20 @@ enum class AppTab(@param:StringRes val titleRes: Int) {
|
||||
}
|
||||
|
||||
enum class ExtraPlayerTab(@param:StringRes val titleRes: Int) {
|
||||
HISTORY(R.string.extra_tab_history),
|
||||
RECENT(R.string.extra_tab_recent),
|
||||
SIMILAR(R.string.extra_tab_similar),
|
||||
INFO(R.string.extra_tab_info)
|
||||
}
|
||||
|
||||
/** A song the station announced while it was playing during this session. */
|
||||
@Immutable
|
||||
data class TrackEntry(
|
||||
val stationId: String,
|
||||
val title: String,
|
||||
val startedAtMillis: Long
|
||||
) {
|
||||
/** Streams usually send "Artist - Title"; the halves are shown on separate lines. */
|
||||
val song: String get() = title.substringAfter(" - ", title).trim()
|
||||
val artist: String? get() = title.substringBefore(" - ", "").trim().ifEmpty { null }
|
||||
}
|
||||
|
||||
@@ -4,9 +4,7 @@ import android.content.Context
|
||||
import androidx.core.content.edit
|
||||
import cc.skysparkle.fogwave.R
|
||||
import cc.skysparkle.fogwave.data.model.Genre
|
||||
import cc.skysparkle.fogwave.data.model.IconSizeStep
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
import cc.skysparkle.fogwave.data.model.ViewMode
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
@@ -158,12 +156,6 @@ class RadioRepository(context: Context) {
|
||||
private val _recentsFlow = MutableStateFlow<List<String>>(loadRecents())
|
||||
val recentsFlow: StateFlow<List<String>> = _recentsFlow.asStateFlow()
|
||||
|
||||
private val _viewModeFlow = MutableStateFlow(loadViewMode())
|
||||
val viewModeFlow: StateFlow<ViewMode> = _viewModeFlow.asStateFlow()
|
||||
|
||||
private val _sizeStepFlow = MutableStateFlow(loadSizeStep())
|
||||
val sizeStepFlow: StateFlow<IconSizeStep> = _sizeStepFlow.asStateFlow()
|
||||
|
||||
private val _seenFavoritesFlow = MutableStateFlow(loadSeenFavorites())
|
||||
val seenFavoritesFlow: StateFlow<Set<String>> = _seenFavoritesFlow.asStateFlow()
|
||||
|
||||
@@ -262,34 +254,6 @@ class RadioRepository(context: Context) {
|
||||
prefs.edit { putString("recents", arr.toString()) }
|
||||
}
|
||||
|
||||
private fun loadViewMode(): ViewMode {
|
||||
val mode = prefs.getString("view_mode", ViewMode.ICONS.name) ?: ViewMode.ICONS.name
|
||||
return try {
|
||||
ViewMode.valueOf(mode)
|
||||
} catch (_: Exception) {
|
||||
ViewMode.ICONS
|
||||
}
|
||||
}
|
||||
|
||||
fun setViewMode(mode: ViewMode) {
|
||||
_viewModeFlow.value = mode
|
||||
prefs.edit { putString("view_mode", mode.name) }
|
||||
}
|
||||
|
||||
private fun loadSizeStep(): IconSizeStep {
|
||||
val step = prefs.getString("size_step", IconSizeStep.M.name) ?: IconSizeStep.M.name
|
||||
return try {
|
||||
IconSizeStep.valueOf(step)
|
||||
} catch (_: Exception) {
|
||||
IconSizeStep.M
|
||||
}
|
||||
}
|
||||
|
||||
fun setSizeStep(step: IconSizeStep) {
|
||||
_sizeStepFlow.value = step
|
||||
prefs.edit { putString("size_step", step.name) }
|
||||
}
|
||||
|
||||
fun hasSeenBatteryOptimizationPrompt(): Boolean {
|
||||
return prefs.getBoolean("seen_battery_optimization_prompt", false)
|
||||
}
|
||||
|
||||
@@ -30,6 +30,10 @@ class RadioPlayerManager(private val context: Context) {
|
||||
private val _currentMediaId = MutableStateFlow<String?>(null)
|
||||
val currentMediaId: StateFlow<String?> = _currentMediaId.asStateFlow()
|
||||
|
||||
/** Song announced by the stream (ICY / ID3 metadata), or null when the station sends none. */
|
||||
private val _nowPlayingTitle = MutableStateFlow<String?>(null)
|
||||
val nowPlayingTitle: StateFlow<String?> = _nowPlayingTitle.asStateFlow()
|
||||
|
||||
private var currentStation: RadioStation? = null
|
||||
private var pendingStation: RadioStation? = null
|
||||
|
||||
@@ -41,6 +45,7 @@ class RadioPlayerManager(private val context: Context) {
|
||||
override fun onEvents(player: Player, events: Player.Events) {
|
||||
_playerState.value = deriveState(player)
|
||||
_currentMediaId.value = player.currentMediaItem?.mediaId
|
||||
_nowPlayingTitle.value = streamTitle(player)
|
||||
}
|
||||
|
||||
override fun onPlayerError(error: PlaybackException) {
|
||||
@@ -85,6 +90,7 @@ class RadioPlayerManager(private val context: Context) {
|
||||
} else {
|
||||
_playerState.value = deriveState(c)
|
||||
_currentMediaId.value = c.currentMediaItem?.mediaId
|
||||
_nowPlayingTitle.value = streamTitle(c)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e(TAG, "Failed to connect to FogwavePlaybackService", e)
|
||||
@@ -125,6 +131,14 @@ class RadioPlayerManager(private val context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
// Stream metadata replaces the item's own title; the station name itself is not a song.
|
||||
private fun streamTitle(p: Player): String? {
|
||||
val title = p.mediaMetadata.title?.toString()?.trim()
|
||||
if (title.isNullOrEmpty()) return null
|
||||
if (title == p.currentMediaItem?.mediaMetadata?.title?.toString()?.trim()) return null
|
||||
return title
|
||||
}
|
||||
|
||||
private fun errorMessage(error: PlaybackException): String = context.getString(
|
||||
when (error.errorCode) {
|
||||
PlaybackException.ERROR_CODE_IO_NETWORK_CONNECTION_FAILED,
|
||||
@@ -144,6 +158,7 @@ class RadioPlayerManager(private val context: Context) {
|
||||
return
|
||||
}
|
||||
_playerState.value = PlayerState.Connecting
|
||||
_nowPlayingTitle.value = null
|
||||
try {
|
||||
c.setMediaItem(station.toMediaItem(context))
|
||||
c.prepare()
|
||||
|
||||
@@ -101,7 +101,7 @@ fun EqualizerSheet(
|
||||
text = if (audioEffects.equalizerEnabled) stringResource(R.string.equalizer_on) else stringResource(R.string.equalizer_off),
|
||||
style = MaterialTheme.typography.labelMedium.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = if (audioEffects.equalizerEnabled) LocalGeoColors.current.liveGreen else LocalGeoColors.current.onSurfaceVariant
|
||||
color = if (audioEffects.equalizerEnabled) LocalGeoColors.current.primary else LocalGeoColors.current.onSurfaceVariant
|
||||
),
|
||||
modifier = Modifier.padding(end = 6.dp)
|
||||
)
|
||||
|
||||
@@ -15,9 +15,6 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.lazy.grid.GridCells
|
||||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
|
||||
import androidx.compose.foundation.lazy.grid.items
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
@@ -33,6 +30,7 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
@@ -40,9 +38,7 @@ import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import cc.skysparkle.fogwave.R
|
||||
import cc.skysparkle.fogwave.data.model.IconSizeStep
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
import cc.skysparkle.fogwave.data.model.ViewMode
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
|
||||
@Composable
|
||||
@@ -50,8 +46,6 @@ fun FavoritesPanel(
|
||||
favorites: List<RadioStation>,
|
||||
currentStation: RadioStation?,
|
||||
isPlaying: Boolean,
|
||||
viewMode: ViewMode,
|
||||
sizeStep: IconSizeStep,
|
||||
onSelectStation: (RadioStation) -> Unit,
|
||||
onBrowseStations: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
@@ -66,68 +60,27 @@ fun FavoritesPanel(
|
||||
return
|
||||
}
|
||||
|
||||
StationCollection(
|
||||
stations = favorites,
|
||||
currentStation = currentStation,
|
||||
isPlaying = isPlaying,
|
||||
viewMode = viewMode,
|
||||
sizeStep = sizeStep,
|
||||
onSelectStation = onSelectStation,
|
||||
bottomContentPadding = bottomContentPadding,
|
||||
LazyColumn(
|
||||
contentPadding = PaddingValues(start = 10.dp, end = 10.dp, top = 8.dp, bottom = bottomContentPadding),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
|
||||
/** The station grid (Icons mode) or list (other modes), shared by the Radio and Favorites tabs. */
|
||||
@Composable
|
||||
fun StationCollection(
|
||||
stations: List<RadioStation>,
|
||||
currentStation: RadioStation?,
|
||||
isPlaying: Boolean,
|
||||
viewMode: ViewMode,
|
||||
sizeStep: IconSizeStep,
|
||||
onSelectStation: (RadioStation) -> Unit,
|
||||
bottomContentPadding: Dp,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val contentPadding = PaddingValues(start = 20.dp, end = 20.dp, top = 8.dp, bottom = bottomContentPadding)
|
||||
when (viewMode) {
|
||||
ViewMode.ICONS -> LazyVerticalGrid(
|
||||
columns = GridCells.Adaptive((sizeStep.sizeDp + 16).dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp),
|
||||
contentPadding = contentPadding,
|
||||
modifier = modifier
|
||||
) {
|
||||
items(stations, key = { it.id }) { station ->
|
||||
val isCur = station.id == currentStation?.id
|
||||
StationItem(
|
||||
station = station,
|
||||
isCurrent = isCur,
|
||||
isPlaying = isCur && isPlaying,
|
||||
viewMode = viewMode,
|
||||
sizeStep = sizeStep,
|
||||
onClick = { onSelectStation(station) }
|
||||
)
|
||||
}
|
||||
) {
|
||||
item(key = "header") {
|
||||
SectionHeader(
|
||||
title = stringResource(R.string.tab_favorites),
|
||||
trailing = pluralStringResource(R.plurals.station_count, favorites.size, favorites.size),
|
||||
modifier = Modifier.padding(start = 10.dp, end = 10.dp, bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
ViewMode.TILES, ViewMode.LIST, ViewMode.DETAILS -> LazyColumn(
|
||||
contentPadding = contentPadding,
|
||||
verticalArrangement = Arrangement.spacedBy(8.dp),
|
||||
modifier = modifier
|
||||
) {
|
||||
items(stations, key = { it.id }) { station ->
|
||||
val isCur = station.id == currentStation?.id
|
||||
StationItem(
|
||||
station = station,
|
||||
isCurrent = isCur,
|
||||
isPlaying = isCur && isPlaying,
|
||||
viewMode = viewMode,
|
||||
sizeStep = sizeStep,
|
||||
onClick = { onSelectStation(station) }
|
||||
)
|
||||
}
|
||||
items(favorites, key = { it.id }) { station ->
|
||||
val isCur = station.id == currentStation?.id
|
||||
StationRow(
|
||||
station = station,
|
||||
isCurrent = isCur,
|
||||
isPlaying = isCur && isPlaying,
|
||||
onClick = { onSelectStation(station) },
|
||||
modifier = Modifier.animateItem()
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
package cc.skysparkle.fogwave.ui.components
|
||||
|
||||
import androidx.compose.animation.core.animateDpAsState
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.lazy.LazyRow
|
||||
import androidx.compose.foundation.lazy.items
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shadow
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.selected
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import cc.skysparkle.fogwave.R
|
||||
import cc.skysparkle.fogwave.data.model.Genre
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
|
||||
/** Two glow colors per card; null is the "All stations" card. */
|
||||
private fun genrePalette(genre: Genre?): Pair<Color, Color> = when (genre) {
|
||||
null -> Color(0xFF3466F6) to Color(0xFF8E5CFF)
|
||||
Genre.HITS -> Color(0xFFFF3D8B) to Color(0xFF7A3CFF)
|
||||
Genre.POP -> Color(0xFFB04DFF) to Color(0xFF3FA9FF)
|
||||
Genre.DANCE -> Color(0xFF00D1FF) to Color(0xFFB13CFF)
|
||||
Genre.OLDIES -> Color(0xFFFFB13D) to Color(0xFFD9488A)
|
||||
Genre.ROCK -> Color(0xFFFF5640) to Color(0xFF5B1FA8)
|
||||
Genre.EASY_LISTENING -> Color(0xFF3DDCB0) to Color(0xFF3466F6)
|
||||
Genre.LITHUANIAN -> Color(0xFFFDB913) to Color(0xFF006A44)
|
||||
Genre.NEWS_TALK -> Color(0xFF8FA6C8) to Color(0xFF2F4B8C)
|
||||
Genre.LATVIAN -> Color(0xFFC8102E) to Color(0xFFE8E8F0)
|
||||
}
|
||||
|
||||
/**
|
||||
* Horizontal row of genre cards in the spirit of the design's smoky category art.
|
||||
* The first card shows every station; tapping the selected genre again clears the filter.
|
||||
*/
|
||||
@Composable
|
||||
fun GenreCarousel(
|
||||
stations: List<RadioStation>,
|
||||
selectedGenre: Genre?,
|
||||
onSelectGenre: (Genre?) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val genres = Genre.entries.filter { g -> stations.any { g in it.genres } }
|
||||
|
||||
LazyRow(
|
||||
modifier = modifier.testTag("genre_carousel"),
|
||||
contentPadding = PaddingValues(horizontal = 20.dp),
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
item(key = "all") {
|
||||
GenreCard(
|
||||
genre = null,
|
||||
title = stringResource(R.string.genre_all),
|
||||
count = stations.size,
|
||||
selected = selectedGenre == null,
|
||||
onClick = { onSelectGenre(null) }
|
||||
)
|
||||
}
|
||||
items(genres, key = { it.name }) { genre ->
|
||||
GenreCard(
|
||||
genre = genre,
|
||||
title = stringResource(genre.labelRes),
|
||||
count = stations.count { genre in it.genres },
|
||||
selected = selectedGenre == genre,
|
||||
onClick = { onSelectGenre(if (selectedGenre == genre) null else genre) }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun GenreCard(
|
||||
genre: Genre?,
|
||||
title: String,
|
||||
count: Int,
|
||||
selected: Boolean,
|
||||
onClick: () -> Unit
|
||||
) {
|
||||
val colors = LocalGeoColors.current
|
||||
val (glowA, glowB) = genrePalette(genre)
|
||||
val borderWidth by animateDpAsState(if (selected) 2.dp else 1.dp, label = "genre_border")
|
||||
val dim by animateFloatAsState(if (selected) 1f else 0.82f, label = "genre_dim")
|
||||
val shape = RoundedCornerShape(20.dp)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(width = 124.dp, height = 156.dp)
|
||||
.clip(shape)
|
||||
.border(borderWidth, if (selected) colors.primary else colors.outlineVariant, shape)
|
||||
.clickable(role = Role.Tab, onClick = onClick)
|
||||
.semantics { this.selected = selected }
|
||||
.testTag("genre_${genre?.name?.lowercase() ?: "all"}")
|
||||
) {
|
||||
Canvas(
|
||||
modifier = Modifier
|
||||
.matchParentSize()
|
||||
.graphicsLayer { alpha = dim }
|
||||
) {
|
||||
drawRect(Color(0xFF0B0D14))
|
||||
// Soft overlapping glows read as colored smoke on the dark card.
|
||||
drawCircle(
|
||||
brush = Brush.radialGradient(
|
||||
colors = listOf(glowA.copy(alpha = 0.9f), Color.Transparent),
|
||||
center = Offset(size.width * 0.25f, size.height * 0.3f),
|
||||
radius = size.width * 0.85f
|
||||
),
|
||||
radius = size.width * 0.85f,
|
||||
center = Offset(size.width * 0.25f, size.height * 0.3f)
|
||||
)
|
||||
drawCircle(
|
||||
brush = Brush.radialGradient(
|
||||
colors = listOf(glowB.copy(alpha = 0.85f), Color.Transparent),
|
||||
center = Offset(size.width * 0.85f, size.height * 0.62f),
|
||||
radius = size.width * 0.75f
|
||||
),
|
||||
radius = size.width * 0.75f,
|
||||
center = Offset(size.width * 0.85f, size.height * 0.62f)
|
||||
)
|
||||
drawCircle(
|
||||
brush = Brush.radialGradient(
|
||||
colors = listOf(Color.White.copy(alpha = 0.22f), Color.Transparent),
|
||||
center = Offset(size.width * 0.55f, size.height * 0.42f),
|
||||
radius = size.width * 0.35f
|
||||
),
|
||||
radius = size.width * 0.35f,
|
||||
center = Offset(size.width * 0.55f, size.height * 0.42f)
|
||||
)
|
||||
drawRect(
|
||||
brush = Brush.verticalGradient(
|
||||
colors = listOf(Color.Transparent, Color.Black.copy(alpha = 0.7f)),
|
||||
startY = size.height * 0.45f,
|
||||
endY = size.height
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.align(Alignment.BottomStart)
|
||||
.padding(12.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
val shadow = Shadow(color = Color.Black.copy(alpha = 0.6f), blurRadius = 8f)
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleSmall.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 14.sp,
|
||||
lineHeight = 17.sp,
|
||||
color = Color.White,
|
||||
shadow = shadow
|
||||
),
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
text = pluralStringResource(R.plurals.station_count, count, count),
|
||||
style = MaterialTheme.typography.labelSmall.copy(
|
||||
fontSize = 11.sp,
|
||||
color = Color.White.copy(alpha = 0.75f),
|
||||
shadow = shadow
|
||||
),
|
||||
maxLines = 1
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animate
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
@@ -26,7 +25,6 @@ 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
|
||||
@@ -40,10 +38,8 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
@@ -63,15 +59,15 @@ private val TABLET_MINI_PLAYER_MAX_WIDTH_DP = 640.dp
|
||||
fun MiniPlayer(
|
||||
station: RadioStation?,
|
||||
playerState: PlayerState,
|
||||
trackTitle: String?,
|
||||
onTogglePlay: () -> Unit,
|
||||
onPrevious: () -> Unit,
|
||||
onNext: () -> Unit,
|
||||
onOpenNowPlaying: () -> Unit,
|
||||
onHide: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
if (station == null) return
|
||||
|
||||
val colors = LocalGeoColors.current
|
||||
val isPlaying = playerState is PlayerState.Playing
|
||||
val isConnecting = playerState is PlayerState.Connecting
|
||||
val isError = playerState is PlayerState.Error
|
||||
@@ -79,7 +75,7 @@ fun MiniPlayer(
|
||||
val subText = when {
|
||||
isError -> playerState.message
|
||||
isConnecting -> stringResource(R.string.player_connecting)
|
||||
isPlaying -> stringResource(R.string.player_on_air)
|
||||
isPlaying && trackTitle != null -> trackTitle
|
||||
else -> stationDescription(station)
|
||||
}
|
||||
|
||||
@@ -107,10 +103,10 @@ fun MiniPlayer(
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.shadow(6.dp, RoundedCornerShape(32.dp))
|
||||
.clip(RoundedCornerShape(32.dp))
|
||||
.background(LocalGeoColors.current.surfaceContainer)
|
||||
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(32.dp))
|
||||
.shadow(12.dp, RoundedCornerShape(28.dp))
|
||||
.clip(RoundedCornerShape(28.dp))
|
||||
.background(colors.surfaceContainerHigh)
|
||||
.border(1.dp, colors.outlineVariant, RoundedCornerShape(28.dp))
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = ripple(bounded = true)
|
||||
@@ -150,107 +146,68 @@ fun MiniPlayer(
|
||||
}
|
||||
}
|
||||
)
|
||||
.padding(start = 10.dp, end = 12.dp, top = 8.dp, bottom = 8.dp)
|
||||
.padding(start = 8.dp, end = 12.dp, top = 8.dp, bottom = 8.dp)
|
||||
.testTag("mini_player"),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(46.dp)
|
||||
.clip(RoundedCornerShape(14.dp))
|
||||
.background(stationTileColor(station))
|
||||
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(14.dp))
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = station.iconResId),
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize()
|
||||
)
|
||||
}
|
||||
StationDisc(
|
||||
station = station,
|
||||
isPlaying = isPlaying,
|
||||
ringWidth = 2.dp,
|
||||
ringGap = 3.dp,
|
||||
glow = false,
|
||||
modifier = Modifier.size(56.dp)
|
||||
)
|
||||
|
||||
Column(
|
||||
modifier = Modifier.weight(1f),
|
||||
verticalArrangement = Arrangement.Center
|
||||
verticalArrangement = Arrangement.spacedBy(1.dp)
|
||||
) {
|
||||
LiveLabel(active = isPlaying)
|
||||
Text(
|
||||
text = station.name,
|
||||
style = MaterialTheme.typography.bodyMedium.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 14.5.sp,
|
||||
color = LocalGeoColors.current.deepPurple
|
||||
fontSize = 15.sp,
|
||||
color = colors.deepPurple
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
|
||||
Text(
|
||||
text = subText,
|
||||
style = MaterialTheme.typography.bodySmall.copy(
|
||||
fontSize = 11.5.sp,
|
||||
color = if (isError) LocalGeoColors.current.redFavorite else (if (isPlaying) LocalGeoColors.current.liveGreen else LocalGeoColors.current.onSurfaceVariant)
|
||||
fontSize = 12.sp,
|
||||
color = if (isError) colors.redFavorite else colors.onSurfaceVariant
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(2.dp)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(48.dp)
|
||||
.shadow(6.dp, CircleShape)
|
||||
.clip(CircleShape)
|
||||
.background(colors.accentLavender)
|
||||
.clickable { onTogglePlay() }
|
||||
.testTag("mini_play_btn"),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
IconButton(
|
||||
onClick = onPrevious,
|
||||
modifier = Modifier
|
||||
.size(36.dp)
|
||||
.testTag("mini_prev_btn")
|
||||
) {
|
||||
AppIcon(
|
||||
resId = R.drawable.ic_chevron_left,
|
||||
contentDescription = stringResource(R.string.previous_station_content_desc),
|
||||
tint = LocalGeoColors.current.onSurfaceVariant,
|
||||
size = 24.dp
|
||||
if (isConnecting) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(22.dp),
|
||||
color = colors.onAccentLavender,
|
||||
strokeWidth = 2.dp
|
||||
)
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(42.dp)
|
||||
.shadow(2.dp, CircleShape)
|
||||
.clip(CircleShape)
|
||||
.background(LocalGeoColors.current.accentLavender)
|
||||
.clickable { onTogglePlay() }
|
||||
.testTag("mini_play_btn"),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
if (isConnecting) {
|
||||
CircularProgressIndicator(
|
||||
modifier = Modifier.size(20.dp),
|
||||
color = LocalGeoColors.current.onAccentLavender,
|
||||
strokeWidth = 2.dp
|
||||
)
|
||||
} else {
|
||||
AppIcon(
|
||||
resId = if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play,
|
||||
contentDescription = if (isPlaying) stringResource(R.string.pause_content_desc) else stringResource(R.string.play_content_desc),
|
||||
tint = LocalGeoColors.current.onAccentLavender,
|
||||
size = 22.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
IconButton(
|
||||
onClick = onNext,
|
||||
modifier = Modifier
|
||||
.size(36.dp)
|
||||
.testTag("mini_next_btn")
|
||||
) {
|
||||
} else {
|
||||
AppIcon(
|
||||
resId = R.drawable.ic_chevron_right,
|
||||
contentDescription = stringResource(R.string.next_station_content_desc),
|
||||
tint = LocalGeoColors.current.onSurfaceVariant,
|
||||
size = 24.dp
|
||||
resId = if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play,
|
||||
contentDescription = if (isPlaying) stringResource(R.string.pause_content_desc) else stringResource(R.string.play_content_desc),
|
||||
tint = colors.onAccentLavender,
|
||||
size = 22.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
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.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import coil.compose.AsyncImage
|
||||
import coil.request.ImageRequest
|
||||
import coil.size.Scale
|
||||
import cc.skysparkle.fogwave.R
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
|
||||
@Composable
|
||||
fun MistyMountainBackground(modifier: Modifier = Modifier) {
|
||||
val context = LocalContext.current
|
||||
val request = remember(context) {
|
||||
ImageRequest.Builder(context)
|
||||
.data(R.drawable.bg_misty_mountain)
|
||||
.scale(Scale.FILL)
|
||||
.crossfade(200)
|
||||
.build()
|
||||
}
|
||||
|
||||
Box(modifier = modifier.fillMaxSize().background(LocalGeoColors.current.background)) {
|
||||
AsyncImage(
|
||||
model = request,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
|
||||
val scrimBase = LocalGeoColors.current.background
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(
|
||||
Brush.verticalGradient(
|
||||
colors = listOf(
|
||||
scrimBase.copy(alpha = 0.62f),
|
||||
scrimBase.copy(alpha = 0.48f),
|
||||
scrimBase.copy(alpha = 0.52f),
|
||||
scrimBase.copy(alpha = 0.78f)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,130 @@
|
||||
package cc.skysparkle.fogwave.ui.components
|
||||
|
||||
import androidx.compose.animation.core.Animatable
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
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.remember
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.geometry.Size
|
||||
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.layout.ContentScale
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
import kotlin.math.cos
|
||||
import kotlin.math.min
|
||||
import kotlin.math.sin
|
||||
|
||||
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.
|
||||
*/
|
||||
@Composable
|
||||
fun StationDisc(
|
||||
station: RadioStation,
|
||||
isPlaying: Boolean,
|
||||
modifier: Modifier = Modifier,
|
||||
ringWidth: Dp = 4.dp,
|
||||
ringGap: Dp = 10.dp,
|
||||
glow: Boolean = true
|
||||
) {
|
||||
val colors = LocalGeoColors.current
|
||||
val rotation = remember { Animatable(0f) }
|
||||
|
||||
LaunchedEffect(isPlaying) {
|
||||
while (isPlaying) {
|
||||
rotation.snapTo(rotation.value % 360f)
|
||||
rotation.animateTo(
|
||||
targetValue = rotation.value + 360f,
|
||||
animationSpec = tween(TURN_MILLIS, easing = LinearEasing)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Box(modifier = modifier.aspectRatio(1f), contentAlignment = Alignment.Center) {
|
||||
Canvas(modifier = Modifier.fillMaxSize()) {
|
||||
val stroke = ringWidth.toPx()
|
||||
val radius = min(size.width, size.height) / 2f - stroke
|
||||
val topLeft = Offset(center.x - radius, center.y - radius)
|
||||
val arcSize = Size(radius * 2, radius * 2)
|
||||
|
||||
if (glow) {
|
||||
drawCircle(
|
||||
brush = Brush.radialGradient(
|
||||
colors = listOf(colors.accentLavender.copy(alpha = 0.28f), Color.Transparent),
|
||||
center = center,
|
||||
radius = radius * 1.25f
|
||||
),
|
||||
radius = radius * 1.25f,
|
||||
center = center
|
||||
)
|
||||
}
|
||||
|
||||
drawCircle(
|
||||
color = colors.outlineVariant,
|
||||
radius = radius,
|
||||
center = center,
|
||||
style = Stroke(width = stroke)
|
||||
)
|
||||
|
||||
val start = -90f + rotation.value
|
||||
drawArc(
|
||||
color = colors.primary,
|
||||
startAngle = start,
|
||||
sweepAngle = ARC_SWEEP,
|
||||
useCenter = false,
|
||||
topLeft = topLeft,
|
||||
size = arcSize,
|
||||
style = Stroke(width = stroke, cap = StrokeCap.Round)
|
||||
)
|
||||
|
||||
val end = Math.toRadians((start + ARC_SWEEP).toDouble())
|
||||
val knob = Offset(
|
||||
center.x + radius * cos(end).toFloat(),
|
||||
center.y + radius * sin(end).toFloat()
|
||||
)
|
||||
drawCircle(color = colors.accentLavender, radius = stroke * 1.9f, center = knob)
|
||||
drawCircle(color = Color.White, radius = stroke * 0.8f, center = knob)
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.padding(ringWidth * 2 + ringGap)
|
||||
.clip(CircleShape)
|
||||
.background(stationTileColor(station))
|
||||
.border(1.dp, colors.outlineVariant, CircleShape),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
// Slightly larger than the inscribed square, so only the logo's corners get clipped.
|
||||
Image(
|
||||
painter = painterResource(id = station.iconResId),
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Fit,
|
||||
modifier = Modifier.fillMaxSize(0.78f)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,462 +0,0 @@
|
||||
package cc.skysparkle.fogwave.ui.components
|
||||
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
import androidx.compose.animation.core.RepeatMode
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.animateFloat
|
||||
import androidx.compose.animation.core.animateFloatAsState
|
||||
import androidx.compose.animation.core.infiniteRepeatable
|
||||
import androidx.compose.animation.core.rememberInfiniteTransition
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.foundation.LocalIndication
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.interaction.collectIsPressedAsState
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
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.draw.shadow
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.Shadow
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import cc.skysparkle.fogwave.data.model.IconSizeStep
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
import cc.skysparkle.fogwave.data.model.ViewMode
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
import coil.compose.AsyncImage
|
||||
|
||||
@Composable
|
||||
fun LiveOnAirDot(modifier: Modifier = Modifier) {
|
||||
val infiniteTransition = rememberInfiniteTransition(label = "pulse")
|
||||
val scale by infiniteTransition.animateFloat(
|
||||
initialValue = 0.8f,
|
||||
targetValue = 1.25f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(900, easing = FastOutSlowInEasing),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
),
|
||||
label = "live_pulse"
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.size(7.dp)
|
||||
.graphicsLayer {
|
||||
scaleX = scale
|
||||
scaleY = scale
|
||||
}
|
||||
.clip(CircleShape)
|
||||
.background(LocalGeoColors.current.liveGreen)
|
||||
)
|
||||
}
|
||||
|
||||
private val GridTextShadow = Shadow(color = Color.Black.copy(alpha = 0.55f), blurRadius = 8f)
|
||||
|
||||
@Composable
|
||||
fun StationItem(
|
||||
station: RadioStation,
|
||||
isCurrent: Boolean,
|
||||
isPlaying: Boolean,
|
||||
viewMode: ViewMode,
|
||||
sizeStep: IconSizeStep,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val interactionSource = remember { MutableInteractionSource() }
|
||||
val pressed by interactionSource.collectIsPressedAsState()
|
||||
val pressScale by animateFloatAsState(
|
||||
targetValue = if (pressed) 0.96f else 1f,
|
||||
animationSpec = spring(dampingRatio = 0.6f, stiffness = Spring.StiffnessMediumLow),
|
||||
label = "station_press"
|
||||
)
|
||||
val cardModifier = modifier.graphicsLayer {
|
||||
scaleX = pressScale
|
||||
scaleY = pressScale
|
||||
}
|
||||
|
||||
when (viewMode) {
|
||||
ViewMode.ICONS -> {
|
||||
StationIconsCard(
|
||||
station = station,
|
||||
isCurrent = isCurrent,
|
||||
isPlaying = isPlaying,
|
||||
sizeDp = sizeStep.sizeDp.dp,
|
||||
onClick = onClick,
|
||||
interactionSource = interactionSource,
|
||||
modifier = cardModifier
|
||||
)
|
||||
}
|
||||
ViewMode.TILES -> {
|
||||
StationTilesCard(
|
||||
station = station,
|
||||
isCurrent = isCurrent,
|
||||
isPlaying = isPlaying,
|
||||
sizeDp = (sizeStep.sizeDp * 0.7f).dp,
|
||||
onClick = onClick,
|
||||
interactionSource = interactionSource,
|
||||
modifier = cardModifier
|
||||
)
|
||||
}
|
||||
ViewMode.LIST -> {
|
||||
StationListRow(
|
||||
station = station,
|
||||
isCurrent = isCurrent,
|
||||
isPlaying = isPlaying,
|
||||
sizeDp = (sizeStep.sizeDp * 0.45f).coerceAtLeast(36f).dp,
|
||||
onClick = onClick,
|
||||
interactionSource = interactionSource,
|
||||
modifier = cardModifier
|
||||
)
|
||||
}
|
||||
ViewMode.DETAILS -> {
|
||||
StationDetailsRow(
|
||||
station = station,
|
||||
isCurrent = isCurrent,
|
||||
isPlaying = isPlaying,
|
||||
sizeDp = (sizeStep.sizeDp * 0.45f).coerceAtLeast(36f).dp,
|
||||
onClick = onClick,
|
||||
interactionSource = interactionSource,
|
||||
modifier = cardModifier
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StationIconsCard(
|
||||
station: RadioStation,
|
||||
isCurrent: Boolean,
|
||||
isPlaying: Boolean,
|
||||
sizeDp: Dp,
|
||||
onClick: () -> Unit,
|
||||
interactionSource: MutableInteractionSource,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.width(sizeDp)
|
||||
.clip(RoundedCornerShape(20.dp))
|
||||
.clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = LocalIndication.current,
|
||||
role = Role.Button,
|
||||
onClick = onClick
|
||||
)
|
||||
.padding(4.dp)
|
||||
.testTag("station_${station.id}"),
|
||||
horizontalAlignment = Alignment.Start
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.aspectRatio(1f)
|
||||
.shadow(if (isCurrent) 4.dp else 1.dp, RoundedCornerShape(22.dp))
|
||||
.clip(RoundedCornerShape(22.dp))
|
||||
.background(stationTileColor(station))
|
||||
.border(
|
||||
width = if (isCurrent) 2.dp else 1.dp,
|
||||
color = if (isCurrent) LocalGeoColors.current.primary else LocalGeoColors.current.outlineVariant,
|
||||
shape = RoundedCornerShape(22.dp)
|
||||
)
|
||||
) {
|
||||
AsyncImage(
|
||||
model = station.iconResId,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize()
|
||||
)
|
||||
}
|
||||
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
if (isCurrent && isPlaying) {
|
||||
LiveOnAirDot()
|
||||
}
|
||||
Text(
|
||||
text = station.name,
|
||||
style = MaterialTheme.typography.titleSmall.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 14.5.sp,
|
||||
lineHeight = 17.sp,
|
||||
color = if (isCurrent) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurface,
|
||||
shadow = GridTextShadow
|
||||
),
|
||||
maxLines = 2,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = stationDescription(station),
|
||||
style = MaterialTheme.typography.bodySmall.copy(
|
||||
fontSize = 11.5.sp,
|
||||
color = LocalGeoColors.current.onSurface.copy(alpha = 0.82f),
|
||||
shadow = GridTextShadow
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StationTilesCard(
|
||||
station: RadioStation,
|
||||
isCurrent: Boolean,
|
||||
isPlaying: Boolean,
|
||||
sizeDp: Dp,
|
||||
onClick: () -> Unit,
|
||||
interactionSource: MutableInteractionSource,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(18.dp))
|
||||
.background(if (isCurrent) LocalGeoColors.current.primaryContainer.copy(alpha = 0.7f) else LocalGeoColors.current.surfaceContainer.copy(alpha = 0.9f))
|
||||
.border(
|
||||
width = if (isCurrent) 1.5.dp else 1.dp,
|
||||
color = if (isCurrent) LocalGeoColors.current.primary else LocalGeoColors.current.outlineVariant,
|
||||
shape = RoundedCornerShape(18.dp)
|
||||
)
|
||||
.clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = LocalIndication.current,
|
||||
role = Role.Button,
|
||||
onClick = onClick
|
||||
)
|
||||
.padding(10.dp)
|
||||
.testTag("station_${station.id}"),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(sizeDp)
|
||||
.clip(RoundedCornerShape(14.dp))
|
||||
.background(stationTileColor(station))
|
||||
.border(0.8.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(14.dp))
|
||||
) {
|
||||
AsyncImage(
|
||||
model = station.iconResId,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize()
|
||||
)
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
if (isCurrent && isPlaying) {
|
||||
LiveOnAirDot()
|
||||
}
|
||||
Text(
|
||||
text = station.name,
|
||||
style = MaterialTheme.typography.titleSmall.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 15.sp,
|
||||
color = if (isCurrent) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurface
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stationDescription(station),
|
||||
style = MaterialTheme.typography.bodySmall.copy(
|
||||
fontSize = 12.sp,
|
||||
color = LocalGeoColors.current.onSurfaceVariant
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StationListRow(
|
||||
station: RadioStation,
|
||||
isCurrent: Boolean,
|
||||
isPlaying: Boolean,
|
||||
sizeDp: Dp,
|
||||
onClick: () -> Unit,
|
||||
interactionSource: MutableInteractionSource,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(14.dp))
|
||||
.background(if (isCurrent) LocalGeoColors.current.primaryContainer.copy(alpha = 0.6f) else Color.Transparent)
|
||||
.clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = LocalIndication.current,
|
||||
role = Role.Button,
|
||||
onClick = onClick
|
||||
)
|
||||
.padding(horizontal = 10.dp, vertical = 7.dp)
|
||||
.testTag("station_${station.id}"),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(sizeDp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(stationTileColor(station))
|
||||
.border(0.8.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(10.dp))
|
||||
) {
|
||||
AsyncImage(
|
||||
model = station.iconResId,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize()
|
||||
)
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
if (isCurrent && isPlaying) {
|
||||
LiveOnAirDot()
|
||||
}
|
||||
Text(
|
||||
text = station.name,
|
||||
style = MaterialTheme.typography.bodyMedium.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = if (isCurrent) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurface
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun StationDetailsRow(
|
||||
station: RadioStation,
|
||||
isCurrent: Boolean,
|
||||
isPlaying: Boolean,
|
||||
sizeDp: Dp,
|
||||
onClick: () -> Unit,
|
||||
interactionSource: MutableInteractionSource,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(14.dp))
|
||||
.background(if (isCurrent) LocalGeoColors.current.primaryContainer.copy(alpha = 0.6f) else Color.Transparent)
|
||||
.border(
|
||||
width = 0.8.dp,
|
||||
color = if (isCurrent) LocalGeoColors.current.primary else LocalGeoColors.current.outlineVariant.copy(alpha = 0.6f),
|
||||
shape = RoundedCornerShape(14.dp)
|
||||
)
|
||||
.clickable(
|
||||
interactionSource = interactionSource,
|
||||
indication = LocalIndication.current,
|
||||
role = Role.Button,
|
||||
onClick = onClick
|
||||
)
|
||||
.padding(horizontal = 10.dp, vertical = 8.dp)
|
||||
.testTag("station_${station.id}"),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(sizeDp)
|
||||
.clip(RoundedCornerShape(10.dp))
|
||||
.background(stationTileColor(station))
|
||||
.border(0.8.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(10.dp))
|
||||
) {
|
||||
AsyncImage(
|
||||
model = station.iconResId,
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize()
|
||||
)
|
||||
}
|
||||
|
||||
Column(modifier = Modifier.weight(1.3f)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(6.dp)
|
||||
) {
|
||||
if (isCurrent && isPlaying) {
|
||||
LiveOnAirDot()
|
||||
}
|
||||
Text(
|
||||
text = station.name,
|
||||
style = MaterialTheme.typography.bodyMedium.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = if (isCurrent) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurface
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stationDescription(station),
|
||||
style = MaterialTheme.typography.bodySmall.copy(
|
||||
fontSize = 11.5.sp,
|
||||
color = LocalGeoColors.current.onSurfaceVariant
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
|
||||
Text(
|
||||
text = stationGenres(station),
|
||||
style = MaterialTheme.typography.bodySmall.copy(
|
||||
fontSize = 11.5.sp,
|
||||
color = LocalGeoColors.current.primary
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(0.9f)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,226 @@
|
||||
package cc.skysparkle.fogwave.ui.components
|
||||
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.FastOutSlowInEasing
|
||||
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.Image
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import cc.skysparkle.fogwave.R
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
|
||||
@Composable
|
||||
fun LiveOnAirDot(modifier: Modifier = Modifier, size: Dp = 7.dp) {
|
||||
val infiniteTransition = rememberInfiniteTransition(label = "pulse")
|
||||
val scale by infiniteTransition.animateFloat(
|
||||
initialValue = 0.8f,
|
||||
targetValue = 1.25f,
|
||||
animationSpec = infiniteRepeatable(
|
||||
animation = tween(900, easing = FastOutSlowInEasing),
|
||||
repeatMode = RepeatMode.Reverse
|
||||
),
|
||||
label = "live_pulse"
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = modifier
|
||||
.size(size)
|
||||
.graphicsLayer {
|
||||
scaleX = scale
|
||||
scaleY = scale
|
||||
}
|
||||
.clip(CircleShape)
|
||||
.background(LocalGeoColors.current.liveRed)
|
||||
)
|
||||
}
|
||||
|
||||
/** Small red "● LIVE" label used above station names. */
|
||||
@Composable
|
||||
fun LiveLabel(active: Boolean, modifier: Modifier = Modifier) {
|
||||
Row(
|
||||
modifier = modifier,
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(5.dp)
|
||||
) {
|
||||
if (active) {
|
||||
LiveOnAirDot(size = 6.dp)
|
||||
} else {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(6.dp)
|
||||
.clip(CircleShape)
|
||||
.background(LocalGeoColors.current.outline)
|
||||
)
|
||||
}
|
||||
Text(
|
||||
text = stringResource(R.string.live_label),
|
||||
style = MaterialTheme.typography.labelSmall.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 10.sp,
|
||||
letterSpacing = 1.sp,
|
||||
color = if (active) LocalGeoColors.current.liveRed else LocalGeoColors.current.outline
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** Station logo on its tile color with rounded corners. */
|
||||
@Composable
|
||||
fun StationThumb(
|
||||
station: RadioStation,
|
||||
size: Dp,
|
||||
modifier: Modifier = Modifier,
|
||||
cornerRadius: Dp = 12.dp
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier
|
||||
.size(size)
|
||||
.clip(RoundedCornerShape(cornerRadius))
|
||||
.background(stationTileColor(station))
|
||||
) {
|
||||
Image(
|
||||
painter = painterResource(id = station.iconResId),
|
||||
contentDescription = null,
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.matchParentSize()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** A row of the station list: logo, name, description and a play / live indicator. */
|
||||
@Composable
|
||||
fun StationRow(
|
||||
station: RadioStation,
|
||||
isCurrent: Boolean,
|
||||
isPlaying: Boolean,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
subtitle: String? = null
|
||||
) {
|
||||
val colors = LocalGeoColors.current
|
||||
val bg by animateColorAsState(
|
||||
targetValue = if (isCurrent) colors.surfaceContainerHigh else Color.Transparent,
|
||||
label = "station_row_bg"
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(bg)
|
||||
.clickable(role = Role.Button, onClick = onClick)
|
||||
.padding(horizontal = 10.dp, vertical = 8.dp)
|
||||
.testTag("station_${station.id}"),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(14.dp)
|
||||
) {
|
||||
StationThumb(station = station, size = 48.dp)
|
||||
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Text(
|
||||
text = station.name,
|
||||
style = MaterialTheme.typography.bodyLarge.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 15.sp,
|
||||
letterSpacing = 0.sp,
|
||||
color = if (isCurrent) colors.deepPurple else colors.onSurface
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
Text(
|
||||
text = subtitle ?: stationDescription(station),
|
||||
style = MaterialTheme.typography.bodySmall.copy(
|
||||
fontSize = 12.sp,
|
||||
color = colors.onSurfaceVariant
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
|
||||
Box(
|
||||
modifier = Modifier.size(36.dp),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
if (isCurrent && isPlaying) {
|
||||
LiveBars(
|
||||
active = true,
|
||||
color = colors.primary,
|
||||
modifier = Modifier.size(width = 22.dp, height = 16.dp)
|
||||
)
|
||||
} else {
|
||||
AppIcon(
|
||||
resId = R.drawable.ic_play,
|
||||
contentDescription = stringResource(R.string.play_content_desc),
|
||||
tint = if (isCurrent) colors.primary else colors.onSurfaceVariant,
|
||||
size = 18.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Section title such as "Stations", with an optional trailing count. */
|
||||
@Composable
|
||||
fun SectionHeader(title: String, modifier: Modifier = Modifier, trailing: String? = null) {
|
||||
Row(
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleMedium.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 17.sp,
|
||||
letterSpacing = (-0.2).sp,
|
||||
color = LocalGeoColors.current.onSurface
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
if (trailing != null) {
|
||||
Text(
|
||||
text = trailing,
|
||||
style = MaterialTheme.typography.labelMedium.copy(
|
||||
fontWeight = FontWeight.Medium,
|
||||
color = LocalGeoColors.current.onSurfaceVariant
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,82 +1,173 @@
|
||||
package cc.skysparkle.fogwave.ui.components
|
||||
|
||||
import androidx.compose.animation.AnimatedContent
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.togetherWith
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.statusBarsPadding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.IconButton
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
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.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.heading
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import cc.skysparkle.fogwave.R
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
|
||||
/**
|
||||
* Header with the logo on the left, the app name centered and a search action on the right.
|
||||
* While searching, the title turns into a search field.
|
||||
*/
|
||||
@Composable
|
||||
fun TopBrandBar(modifier: Modifier = Modifier) {
|
||||
Box(
|
||||
fun TopBrandBar(
|
||||
modifier: Modifier = Modifier,
|
||||
showSearch: Boolean = false,
|
||||
isSearchOpen: Boolean = false,
|
||||
query: String = "",
|
||||
onQueryChange: (String) -> Unit = {},
|
||||
onOpenSearch: () -> Unit = {},
|
||||
onCloseSearch: () -> Unit = {}
|
||||
) {
|
||||
val colors = LocalGeoColors.current
|
||||
|
||||
Row(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.background(LocalGeoColors.current.surfaceContainer.copy(alpha = 0.92f))
|
||||
.statusBarsPadding()
|
||||
.padding(horizontal = 20.dp, vertical = 12.dp)
|
||||
.padding(start = 20.dp, end = 10.dp, top = 8.dp, bottom = 8.dp)
|
||||
.height(48.dp)
|
||||
.testTag("top_brand_bar"),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
||||
) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(14.dp),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.testTag("top_brand_bar")
|
||||
) {
|
||||
Box(
|
||||
AppIcon(
|
||||
resId = R.drawable.ic_fogwave_logo,
|
||||
contentDescription = stringResource(R.string.fogwave_logo_content_desc),
|
||||
size = 30.dp
|
||||
)
|
||||
|
||||
Box(modifier = Modifier.weight(1f), contentAlignment = Alignment.Center) {
|
||||
AnimatedContent(
|
||||
targetState = showSearch && isSearchOpen,
|
||||
transitionSpec = { fadeIn(tween(180)) togetherWith fadeOut(tween(120)) },
|
||||
label = "header_search"
|
||||
) { searching ->
|
||||
if (searching) {
|
||||
SearchField(query = query, onQueryChange = onQueryChange)
|
||||
} else {
|
||||
Text(
|
||||
text = stringResource(R.string.app_name),
|
||||
style = MaterialTheme.typography.titleMedium.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 17.sp,
|
||||
letterSpacing = 0.sp,
|
||||
color = colors.deepPurple
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.semantics { heading() },
|
||||
textAlign = TextAlign.Center
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (showSearch) {
|
||||
IconButton(
|
||||
onClick = if (isSearchOpen) onCloseSearch else onOpenSearch,
|
||||
modifier = Modifier
|
||||
.size(40.dp)
|
||||
.clip(RoundedCornerShape(12.dp)),
|
||||
contentAlignment = Alignment.Center
|
||||
.testTag("search_toggle")
|
||||
) {
|
||||
AppIcon(
|
||||
resId = R.drawable.ic_fogwave_logo,
|
||||
size = 34.dp
|
||||
)
|
||||
}
|
||||
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
Text(
|
||||
text = stringResource(R.string.app_name),
|
||||
style = MaterialTheme.typography.titleMedium.copy(
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontSize = 20.sp,
|
||||
letterSpacing = (-0.4).sp,
|
||||
color = LocalGeoColors.current.deepPurple
|
||||
resId = if (isSearchOpen) R.drawable.ic_close else R.drawable.ic_search,
|
||||
contentDescription = stringResource(
|
||||
if (isSearchOpen) R.string.close_content_desc else R.string.search_content_desc
|
||||
),
|
||||
modifier = Modifier.semantics { heading() }
|
||||
)
|
||||
Text(
|
||||
text = stringResource(R.string.app_subtitle),
|
||||
style = MaterialTheme.typography.labelSmall.copy(
|
||||
fontWeight = FontWeight.Medium,
|
||||
fontSize = 11.5.sp,
|
||||
color = LocalGeoColors.current.onSurfaceVariant,
|
||||
letterSpacing = 0.2.sp
|
||||
)
|
||||
tint = colors.onSurface,
|
||||
size = 22.dp
|
||||
)
|
||||
}
|
||||
} else {
|
||||
Box(modifier = Modifier.size(40.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun SearchField(query: String, onQueryChange: (String) -> Unit) {
|
||||
val colors = LocalGeoColors.current
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
val keyboard = LocalSoftwareKeyboardController.current
|
||||
|
||||
LaunchedEffect(Unit) { focusRequester.requestFocus() }
|
||||
|
||||
BasicTextField(
|
||||
value = query,
|
||||
onValueChange = onQueryChange,
|
||||
singleLine = true,
|
||||
textStyle = MaterialTheme.typography.bodyLarge.copy(color = colors.onSurface, fontSize = 15.sp),
|
||||
cursorBrush = SolidColor(colors.primary),
|
||||
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Search),
|
||||
keyboardActions = KeyboardActions(onSearch = { keyboard?.hide() }),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.focusRequester(focusRequester)
|
||||
.testTag("search_field"),
|
||||
decorationBox = { inner ->
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(CircleShape)
|
||||
.background(colors.surfaceContainerHigh)
|
||||
.padding(horizontal = 14.dp, vertical = 10.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
||||
) {
|
||||
AppIcon(resId = R.drawable.ic_search, tint = colors.onSurfaceVariant, size = 18.dp)
|
||||
Box(modifier = Modifier.weight(1f)) {
|
||||
if (query.isEmpty()) {
|
||||
Text(
|
||||
text = stringResource(R.string.search_hint),
|
||||
style = MaterialTheme.typography.bodyLarge.copy(
|
||||
color = colors.onSurfaceVariant,
|
||||
fontSize = 15.sp
|
||||
),
|
||||
maxLines = 1
|
||||
)
|
||||
}
|
||||
inner()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,292 +0,0 @@
|
||||
package cc.skysparkle.fogwave.ui.components
|
||||
|
||||
import androidx.compose.animation.AnimatedVisibility
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.FastOutLinearInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.expandVertically
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.scaleOut
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.heightIn
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.selection.selectable
|
||||
import androidx.compose.foundation.selection.selectableGroup
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Slider
|
||||
import androidx.compose.material3.SliderDefaults
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.draw.shadow
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.TransformOrigin
|
||||
import androidx.compose.ui.platform.testTag
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.Role
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import cc.skysparkle.fogwave.R
|
||||
import cc.skysparkle.fogwave.data.model.IconSizeStep
|
||||
import cc.skysparkle.fogwave.data.model.ViewMode
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Composable
|
||||
fun StationsToolbar(
|
||||
title: String,
|
||||
isOpen: Boolean,
|
||||
onToggleOpen: () -> Unit,
|
||||
viewMode: ViewMode,
|
||||
onSelectViewMode: (ViewMode) -> Unit,
|
||||
sizeStep: IconSizeStep,
|
||||
onSelectSizeStep: (IconSizeStep) -> Unit,
|
||||
modifier: Modifier = Modifier,
|
||||
showViewOptions: Boolean = true
|
||||
) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 20.dp, vertical = 6.dp)
|
||||
) {
|
||||
Row(
|
||||
// Same height with or without the view button, so the title does not jump between tabs.
|
||||
modifier = Modifier.fillMaxWidth().heightIn(min = 38.dp),
|
||||
horizontalArrangement = Arrangement.SpaceBetween,
|
||||
verticalAlignment = Alignment.CenterVertically
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.titleLarge.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 22.sp,
|
||||
letterSpacing = (-0.4).sp,
|
||||
color = LocalGeoColors.current.deepPurple
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.padding(end = 12.dp)
|
||||
)
|
||||
|
||||
if (showViewOptions) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(38.dp)
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(if (isOpen) LocalGeoColors.current.primaryContainer else LocalGeoColors.current.surfaceContainer)
|
||||
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(12.dp))
|
||||
.clickable(role = Role.Button) { onToggleOpen() }
|
||||
.testTag("view_options_trigger"),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
AppIcon(
|
||||
resId = R.drawable.ic_table,
|
||||
contentDescription = stringResource(R.string.view_mode_content_desc),
|
||||
tint = if (isOpen) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurfaceVariant,
|
||||
size = 19.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = isOpen && showViewOptions,
|
||||
enter = expandVertically(
|
||||
animationSpec = spring(dampingRatio = 0.85f, stiffness = Spring.StiffnessMediumLow),
|
||||
expandFrom = Alignment.Top
|
||||
) + fadeIn(tween(200)) + scaleIn(
|
||||
initialScale = 0.96f,
|
||||
transformOrigin = TransformOrigin(1f, 0f),
|
||||
animationSpec = spring(dampingRatio = 0.85f, stiffness = Spring.StiffnessMediumLow)
|
||||
),
|
||||
exit = shrinkVertically(
|
||||
animationSpec = tween(180, easing = FastOutLinearInEasing),
|
||||
shrinkTowards = Alignment.Top
|
||||
) + fadeOut(tween(140)) + scaleOut(
|
||||
targetScale = 0.96f,
|
||||
transformOrigin = TransformOrigin(1f, 0f),
|
||||
animationSpec = tween(180)
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.padding(top = 10.dp)
|
||||
.fillMaxWidth()
|
||||
.shadow(4.dp, RoundedCornerShape(24.dp))
|
||||
.clip(RoundedCornerShape(24.dp))
|
||||
.background(LocalGeoColors.current.surfaceContainer)
|
||||
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(24.dp))
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(14.dp)
|
||||
) {
|
||||
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
|
||||
Text(
|
||||
text = stringResource(R.string.display_mode_label),
|
||||
style = MaterialTheme.typography.labelSmall.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 10.5.sp,
|
||||
letterSpacing = 0.8.sp,
|
||||
color = LocalGeoColors.current.primary
|
||||
)
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.clip(RoundedCornerShape(12.dp))
|
||||
.background(LocalGeoColors.current.surface)
|
||||
.border(0.8.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(12.dp))
|
||||
.padding(3.dp)
|
||||
.selectableGroup(),
|
||||
horizontalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
ViewModeSegment(
|
||||
title = stringResource(R.string.view_mode_list),
|
||||
icon = R.drawable.ic_list,
|
||||
isSelected = viewMode == ViewMode.LIST,
|
||||
onClick = { onSelectViewMode(ViewMode.LIST) },
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
ViewModeSegment(
|
||||
title = stringResource(R.string.view_mode_table),
|
||||
icon = R.drawable.ic_layout_columns,
|
||||
isSelected = viewMode == ViewMode.DETAILS,
|
||||
onClick = { onSelectViewMode(ViewMode.DETAILS) },
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
ViewModeSegment(
|
||||
title = stringResource(R.string.view_mode_tiles),
|
||||
icon = R.drawable.ic_layout_rows,
|
||||
isSelected = viewMode == ViewMode.TILES,
|
||||
onClick = { onSelectViewMode(ViewMode.TILES) },
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
ViewModeSegment(
|
||||
title = stringResource(R.string.view_mode_icons),
|
||||
icon = R.drawable.ic_grid,
|
||||
isSelected = viewMode == ViewMode.ICONS,
|
||||
onClick = { onSelectViewMode(ViewMode.ICONS) },
|
||||
modifier = Modifier.weight(1f)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
|
||||
Text(
|
||||
text = stringResource(R.string.size_label),
|
||||
style = MaterialTheme.typography.labelSmall.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
fontSize = 10.5.sp,
|
||||
letterSpacing = 0.8.sp,
|
||||
color = LocalGeoColors.current.primary
|
||||
)
|
||||
)
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(10.dp)
|
||||
) {
|
||||
Text(
|
||||
text = "S",
|
||||
style = MaterialTheme.typography.labelMedium.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = LocalGeoColors.current.onSurfaceVariant
|
||||
)
|
||||
)
|
||||
|
||||
val steps = IconSizeStep.entries
|
||||
val currentIndex = steps.indexOf(sizeStep).toFloat()
|
||||
val sizeLabel = stringResource(R.string.size_label)
|
||||
|
||||
Slider(
|
||||
value = currentIndex,
|
||||
onValueChange = { indexFloat ->
|
||||
val step = steps[indexFloat.roundToInt().coerceIn(0, steps.size - 1)]
|
||||
// The slider reports every drag frame; only persist real changes.
|
||||
if (step != sizeStep) onSelectSizeStep(step)
|
||||
},
|
||||
valueRange = 0f..(steps.size - 1).toFloat(),
|
||||
steps = steps.size - 2,
|
||||
colors = SliderDefaults.colors(
|
||||
thumbColor = LocalGeoColors.current.primary,
|
||||
activeTrackColor = LocalGeoColors.current.primary,
|
||||
inactiveTrackColor = LocalGeoColors.current.outlineVariant
|
||||
),
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.semantics { contentDescription = sizeLabel }
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "XL",
|
||||
style = MaterialTheme.typography.labelMedium.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = LocalGeoColors.current.onSurfaceVariant
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ViewModeSegment(
|
||||
title: String,
|
||||
icon: Int,
|
||||
isSelected: Boolean,
|
||||
onClick: () -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
val bg by animateColorAsState(
|
||||
targetValue = if (isSelected) LocalGeoColors.current.primaryContainer else Color.Transparent,
|
||||
animationSpec = tween(220),
|
||||
label = "segment_bg"
|
||||
)
|
||||
val tint by animateColorAsState(
|
||||
targetValue = if (isSelected) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurfaceVariant,
|
||||
animationSpec = tween(220),
|
||||
label = "segment_tint"
|
||||
)
|
||||
Box(
|
||||
modifier = modifier
|
||||
.height(34.dp)
|
||||
.clip(RoundedCornerShape(9.dp))
|
||||
.background(bg)
|
||||
.selectable(selected = isSelected, role = Role.RadioButton, onClick = onClick),
|
||||
contentAlignment = Alignment.Center
|
||||
) {
|
||||
AppIcon(
|
||||
resId = icon,
|
||||
contentDescription = title,
|
||||
tint = tint,
|
||||
size = 18.dp
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -12,51 +12,62 @@ import androidx.compose.animation.core.spring
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
import androidx.compose.animation.fadeOut
|
||||
import androidx.compose.animation.scaleIn
|
||||
import androidx.compose.animation.slideInHorizontally
|
||||
import androidx.compose.animation.slideInVertically
|
||||
import androidx.compose.animation.slideOutHorizontally
|
||||
import androidx.compose.animation.slideOutVertically
|
||||
import androidx.compose.animation.togetherWith
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
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.items
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
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.Modifier
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import cc.skysparkle.fogwave.R
|
||||
import cc.skysparkle.fogwave.data.model.AppTab
|
||||
import cc.skysparkle.fogwave.data.model.Genre
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
import cc.skysparkle.fogwave.player.PlayerState
|
||||
import cc.skysparkle.fogwave.ui.components.AboutPanel
|
||||
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.MiniPlayer
|
||||
import cc.skysparkle.fogwave.ui.components.MistyMountainBackground
|
||||
import cc.skysparkle.fogwave.ui.components.NavigationTabs
|
||||
import cc.skysparkle.fogwave.ui.components.NowPlayingSheet
|
||||
import cc.skysparkle.fogwave.ui.components.StationCollection
|
||||
import cc.skysparkle.fogwave.ui.components.StationsToolbar
|
||||
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.stationDescription
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
import cc.skysparkle.fogwave.ui.viewmodel.RadioViewModel
|
||||
|
||||
@OptIn(ExperimentalAnimationApi::class)
|
||||
@@ -67,6 +78,10 @@ fun HomeScreen(
|
||||
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
|
||||
val isPlaying = uiState.playerState is PlayerState.Playing
|
||||
|
||||
var isSearchOpen by rememberSaveable { mutableStateOf(false) }
|
||||
var query by rememberSaveable { mutableStateOf("") }
|
||||
var selectedGenre by rememberSaveable { mutableStateOf<Genre?>(null) }
|
||||
|
||||
val favoriteStations = remember(uiState.stations, uiState.favorites) {
|
||||
uiState.stations.filter { it.id in uiState.favorites }
|
||||
}
|
||||
@@ -77,11 +92,16 @@ fun HomeScreen(
|
||||
uiState.recents.filter { it.id != uiState.currentStation?.id }
|
||||
}
|
||||
|
||||
val closeSearch = {
|
||||
isSearchOpen = false
|
||||
query = ""
|
||||
}
|
||||
|
||||
BackHandler(enabled = uiState.isEqualizerPopOpen) { viewModel.closeEqualizerPop() }
|
||||
BackHandler(enabled = uiState.isNowPlayingOpen && !uiState.isEqualizerPopOpen) { viewModel.closeNowPlaying() }
|
||||
BackHandler(enabled = uiState.isViewPopOpen && !uiState.isNowPlayingOpen) { viewModel.closeViewPop() }
|
||||
BackHandler(enabled = isSearchOpen && !uiState.isNowPlayingOpen) { closeSearch() }
|
||||
BackHandler(
|
||||
enabled = uiState.selectedTab != AppTab.RADIO && !uiState.isNowPlayingOpen && !uiState.isViewPopOpen
|
||||
enabled = uiState.selectedTab != AppTab.RADIO && !uiState.isNowPlayingOpen && !isSearchOpen
|
||||
) { viewModel.setSelectedTab(AppTab.RADIO) }
|
||||
val showBatteryOptimizationPrompt by viewModel.showBatteryOptimizationPrompt.collectAsStateWithLifecycle()
|
||||
|
||||
@@ -90,16 +110,23 @@ fun HomeScreen(
|
||||
}
|
||||
|
||||
val density = LocalDensity.current
|
||||
var dockHeight by remember { mutableStateOf(140.dp) }
|
||||
var dockHeight by remember { mutableStateOf(160.dp) }
|
||||
val scrollBottomPadding = dockHeight + 16.dp
|
||||
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
MistyMountainBackground()
|
||||
|
||||
Column(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
TopBrandBar()
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(LocalGeoColors.current.background)
|
||||
) {
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
TopBrandBar(
|
||||
showSearch = uiState.selectedTab == AppTab.RADIO,
|
||||
isSearchOpen = isSearchOpen,
|
||||
query = query,
|
||||
onQueryChange = { query = it },
|
||||
onOpenSearch = { isSearchOpen = true },
|
||||
onCloseSearch = closeSearch
|
||||
)
|
||||
|
||||
Box(modifier = Modifier.weight(1f)) {
|
||||
AnimatedContent(
|
||||
@@ -116,75 +143,34 @@ fun HomeScreen(
|
||||
label = "tabs"
|
||||
) { tab ->
|
||||
when (tab) {
|
||||
AppTab.RADIO, AppTab.FAVORITES -> {
|
||||
val isFavorites = tab == AppTab.FAVORITES
|
||||
Column(modifier = Modifier.fillMaxSize()) {
|
||||
StationsToolbar(
|
||||
title = stringResource(
|
||||
if (isFavorites) R.string.favorite_stations_title else R.string.stations_title
|
||||
),
|
||||
isOpen = uiState.isViewPopOpen,
|
||||
onToggleOpen = { viewModel.toggleViewPop() },
|
||||
viewMode = uiState.viewMode,
|
||||
onSelectViewMode = { viewModel.setViewMode(it) },
|
||||
sizeStep = uiState.sizeStep,
|
||||
onSelectSizeStep = { viewModel.setSizeStep(it) },
|
||||
// View options live on the Radio tab only; Favorites follows that choice.
|
||||
showViewOptions = !isFavorites
|
||||
)
|
||||
AppTab.RADIO -> RadioTab(
|
||||
stations = uiState.stations,
|
||||
currentStation = uiState.currentStation,
|
||||
isPlaying = isPlaying,
|
||||
query = query.trim(),
|
||||
selectedGenre = selectedGenre,
|
||||
onSelectGenre = { selectedGenre = it },
|
||||
onSelectStation = { viewModel.onStationClick(it) },
|
||||
bottomContentPadding = scrollBottomPadding
|
||||
)
|
||||
|
||||
Box(modifier = Modifier.weight(1f)) {
|
||||
AnimatedContent(
|
||||
targetState = uiState.viewMode,
|
||||
transitionSpec = {
|
||||
(fadeIn(tween(220, delayMillis = 60)) +
|
||||
scaleIn(initialScale = 0.985f, animationSpec = tween(260)))
|
||||
.togetherWith(fadeOut(tween(120)))
|
||||
},
|
||||
label = "view_mode"
|
||||
) { mode ->
|
||||
if (isFavorites) {
|
||||
FavoritesPanel(
|
||||
favorites = favoriteStations,
|
||||
currentStation = uiState.currentStation,
|
||||
isPlaying = isPlaying,
|
||||
viewMode = mode,
|
||||
sizeStep = uiState.sizeStep,
|
||||
onSelectStation = { viewModel.onStationClick(it) },
|
||||
onBrowseStations = { viewModel.setSelectedTab(AppTab.RADIO) },
|
||||
bottomContentPadding = scrollBottomPadding,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
} else {
|
||||
StationCollection(
|
||||
stations = uiState.stations,
|
||||
currentStation = uiState.currentStation,
|
||||
isPlaying = isPlaying,
|
||||
viewMode = mode,
|
||||
sizeStep = uiState.sizeStep,
|
||||
onSelectStation = { viewModel.onStationClick(it) },
|
||||
bottomContentPadding = scrollBottomPadding,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
}
|
||||
}
|
||||
PopoverScrim(
|
||||
visible = uiState.isViewPopOpen,
|
||||
onDismiss = { viewModel.closeViewPop() }
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
AppTab.FAVORITES -> FavoritesPanel(
|
||||
favorites = favoriteStations,
|
||||
currentStation = uiState.currentStation,
|
||||
isPlaying = isPlaying,
|
||||
onSelectStation = { viewModel.onStationClick(it) },
|
||||
onBrowseStations = { viewModel.setSelectedTab(AppTab.RADIO) },
|
||||
bottomContentPadding = scrollBottomPadding,
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
|
||||
AppTab.ABOUT -> {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(bottom = scrollBottomPadding)
|
||||
) {
|
||||
AboutPanel()
|
||||
}
|
||||
AppTab.ABOUT -> Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(bottom = scrollBottomPadding)
|
||||
) {
|
||||
AboutPanel()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -206,13 +192,6 @@ fun HomeScreen(
|
||||
// even when the mini player is swiped away.
|
||||
.navigationBarsPadding()
|
||||
) {
|
||||
NavigationTabs(
|
||||
selectedTab = uiState.selectedTab,
|
||||
favoritesCount = uiState.unseenFavoritesCount,
|
||||
onTabSelected = { viewModel.setSelectedTab(it) },
|
||||
modifier = Modifier.padding(horizontal = 20.dp, vertical = 6.dp)
|
||||
)
|
||||
|
||||
AnimatedVisibility(
|
||||
visible = !uiState.isMiniPlayerHidden,
|
||||
enter = fadeIn() + slideInVertically(initialOffsetY = { it }),
|
||||
@@ -221,13 +200,22 @@ fun HomeScreen(
|
||||
MiniPlayer(
|
||||
station = uiState.currentStation,
|
||||
playerState = uiState.playerState,
|
||||
trackTitle = uiState.nowPlayingTitle,
|
||||
onTogglePlay = { viewModel.togglePlay() },
|
||||
onPrevious = { viewModel.previousStation() },
|
||||
onNext = { viewModel.nextStation() },
|
||||
onOpenNowPlaying = { viewModel.openNowPlaying() },
|
||||
onHide = { viewModel.hideMiniPlayer() }
|
||||
)
|
||||
}
|
||||
|
||||
NavigationTabs(
|
||||
selectedTab = uiState.selectedTab,
|
||||
favoritesCount = uiState.unseenFavoritesCount,
|
||||
onTabSelected = {
|
||||
closeSearch()
|
||||
viewModel.setSelectedTab(it)
|
||||
},
|
||||
modifier = Modifier.padding(horizontal = 20.dp, vertical = 6.dp)
|
||||
)
|
||||
}
|
||||
|
||||
AnimatedVisibility(
|
||||
@@ -239,6 +227,8 @@ fun HomeScreen(
|
||||
NowPlayingSheet(
|
||||
station = uiState.currentStation,
|
||||
playerState = uiState.playerState,
|
||||
trackTitle = uiState.nowPlayingTitle,
|
||||
trackHistory = uiState.trackHistory,
|
||||
isFavorite = isCurFav,
|
||||
onToggleFavorite = { viewModel.toggleFavorite() },
|
||||
onTogglePlay = { viewModel.togglePlay() },
|
||||
@@ -286,22 +276,83 @@ fun HomeScreen(
|
||||
}
|
||||
}
|
||||
|
||||
/** Genre cards on top, then the (filtered) station list. */
|
||||
@Composable
|
||||
private fun PopoverScrim(visible: Boolean, onDismiss: () -> Unit) {
|
||||
AnimatedVisibility(
|
||||
visible = visible,
|
||||
enter = fadeIn(tween(200)),
|
||||
exit = fadeOut(tween(160))
|
||||
private fun RadioTab(
|
||||
stations: List<RadioStation>,
|
||||
currentStation: RadioStation?,
|
||||
isPlaying: Boolean,
|
||||
query: String,
|
||||
selectedGenre: Genre?,
|
||||
onSelectGenre: (Genre?) -> Unit,
|
||||
onSelectStation: (RadioStation) -> Unit,
|
||||
bottomContentPadding: Dp
|
||||
) {
|
||||
val descriptions = stations.associate { it.id to stationDescription(it) }
|
||||
val visible = remember(stations, query, selectedGenre, descriptions) {
|
||||
stations.filter { station ->
|
||||
(selectedGenre == null || selectedGenre in station.genres) &&
|
||||
(query.isEmpty() ||
|
||||
station.name.contains(query, ignoreCase = true) ||
|
||||
descriptions[station.id].orEmpty().contains(query, ignoreCase = true))
|
||||
}
|
||||
}
|
||||
|
||||
LazyColumn(
|
||||
contentPadding = PaddingValues(top = 4.dp, bottom = bottomContentPadding),
|
||||
modifier = Modifier.fillMaxSize()
|
||||
) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.Black.copy(alpha = 0.38f))
|
||||
.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = null,
|
||||
onClick = onDismiss
|
||||
if (query.isEmpty()) {
|
||||
item(key = "genres") {
|
||||
GenreCarousel(
|
||||
stations = stations,
|
||||
selectedGenre = selectedGenre,
|
||||
onSelectGenre = onSelectGenre,
|
||||
modifier = Modifier.padding(bottom = 22.dp)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
item(key = "header") {
|
||||
SectionHeader(
|
||||
title = when {
|
||||
query.isNotEmpty() -> stringResource(R.string.search_results_title)
|
||||
selectedGenre != null -> stringResource(selectedGenre.labelRes)
|
||||
else -> stringResource(R.string.stations_title)
|
||||
},
|
||||
trailing = pluralStringResource(R.plurals.station_count, visible.size, visible.size),
|
||||
modifier = Modifier.padding(start = 20.dp, end = 20.dp, bottom = 8.dp)
|
||||
)
|
||||
}
|
||||
|
||||
if (visible.isEmpty()) {
|
||||
item(key = "empty") {
|
||||
Text(
|
||||
text = stringResource(R.string.search_no_results, query),
|
||||
style = MaterialTheme.typography.bodyMedium.copy(
|
||||
color = LocalGeoColors.current.onSurfaceVariant,
|
||||
textAlign = TextAlign.Center
|
||||
),
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 32.dp, vertical = 32.dp)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
items(visible, key = { it.id }) { station ->
|
||||
val isCur = station.id == currentStation?.id
|
||||
StationRow(
|
||||
station = station,
|
||||
isCurrent = isCur,
|
||||
isPlaying = isCur && isPlaying,
|
||||
onClick = { onSelectStation(station) },
|
||||
modifier = Modifier
|
||||
.padding(horizontal = 10.dp, vertical = 1.dp)
|
||||
.animateItem()
|
||||
)
|
||||
}
|
||||
|
||||
item(key = "spacer") { Spacer(modifier = Modifier.height(8.dp)) }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,33 +26,34 @@ data class GeoColors(
|
||||
val accentLavender: Color,
|
||||
val onAccentLavender: Color,
|
||||
val deepPurple: Color,
|
||||
val liveGreen: Color,
|
||||
val liveRed: Color,
|
||||
val redFavorite: Color
|
||||
)
|
||||
|
||||
// Dark take on the "Rad.io" layout: deep navy surfaces with an electric-blue accent.
|
||||
val DarkGeoColors = GeoColors(
|
||||
background = Color(0xFF141218),
|
||||
onBackground = Color(0xFFE6E0E9),
|
||||
surface = Color(0xFF141218),
|
||||
onSurface = Color(0xFFE6E0E9),
|
||||
surfaceContainer = Color(0xFF211F26),
|
||||
surfaceContainerHigh = Color(0xFF2B2930),
|
||||
onSurfaceVariant = Color(0xFFCAC4D0),
|
||||
outline = Color(0xFF938F99),
|
||||
outlineVariant = Color(0xFF49454F),
|
||||
primary = Color(0xFFD0BCFF),
|
||||
onPrimary = Color(0xFF381E72),
|
||||
primaryContainer = Color(0xFF4F378B),
|
||||
onPrimaryContainer = Color(0xFFEADDFF),
|
||||
secondary = Color(0xFFCCC2DC),
|
||||
onSecondary = Color(0xFF332D41),
|
||||
secondaryContainer = Color(0xFF4A4458),
|
||||
onSecondaryContainer = Color(0xFFE8DEF8),
|
||||
accentLavender = Color(0xFF4F378B),
|
||||
onAccentLavender = Color(0xFFEADDFF),
|
||||
deepPurple = Color(0xFFD0BCFF),
|
||||
liveGreen = Color(0xFF81C995),
|
||||
redFavorite = Color(0xFFF2B8B5)
|
||||
background = Color(0xFF0D1016),
|
||||
onBackground = Color(0xFFEEF1F7),
|
||||
surface = Color(0xFF0D1016),
|
||||
onSurface = Color(0xFFEEF1F7),
|
||||
surfaceContainer = Color(0xFF161A23),
|
||||
surfaceContainerHigh = Color(0xFF1F2430),
|
||||
onSurfaceVariant = Color(0xFF98A1B3),
|
||||
outline = Color(0xFF5C6577),
|
||||
outlineVariant = Color(0xFF272D3A),
|
||||
primary = Color(0xFF7C9DFF),
|
||||
onPrimary = Color(0xFF0B1A47),
|
||||
primaryContainer = Color(0xFF1F2D5C),
|
||||
onPrimaryContainer = Color(0xFFDCE4FF),
|
||||
secondary = Color(0xFFB2C1E6),
|
||||
onSecondary = Color(0xFF18233F),
|
||||
secondaryContainer = Color(0xFF283350),
|
||||
onSecondaryContainer = Color(0xFFDCE4FF),
|
||||
accentLavender = Color(0xFF3466F6),
|
||||
onAccentLavender = Color(0xFFFFFFFF),
|
||||
deepPurple = Color(0xFFF3F6FF),
|
||||
liveRed = Color(0xFFFF4D5E),
|
||||
redFavorite = Color(0xFFFF6B81)
|
||||
)
|
||||
|
||||
val LocalGeoColors = staticCompositionLocalOf { DarkGeoColors }
|
||||
|
||||
@@ -8,9 +8,8 @@ import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import cc.skysparkle.fogwave.data.model.AppTab
|
||||
import cc.skysparkle.fogwave.data.model.ExtraPlayerTab
|
||||
import cc.skysparkle.fogwave.data.model.IconSizeStep
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
import cc.skysparkle.fogwave.data.model.ViewMode
|
||||
import cc.skysparkle.fogwave.data.model.TrackEntry
|
||||
import cc.skysparkle.fogwave.data.repository.RadioRepository
|
||||
import cc.skysparkle.fogwave.player.AudioEffectsController
|
||||
import cc.skysparkle.fogwave.player.AudioEffectsState
|
||||
@@ -32,15 +31,14 @@ data class RadioUiState(
|
||||
val favorites: Set<String> = emptySet(),
|
||||
val recents: List<RadioStation> = emptyList(),
|
||||
val selectedTab: AppTab = AppTab.RADIO,
|
||||
val viewMode: ViewMode = ViewMode.ICONS,
|
||||
val sizeStep: IconSizeStep = IconSizeStep.M,
|
||||
val isNowPlayingOpen: Boolean = false,
|
||||
val isEqualizerPopOpen: Boolean = false,
|
||||
val isViewPopOpen: Boolean = false,
|
||||
val activeExtraTab: ExtraPlayerTab = ExtraPlayerTab.RECENT,
|
||||
val activeExtraTab: ExtraPlayerTab = ExtraPlayerTab.HISTORY,
|
||||
val audioEffects: AudioEffectsState = AudioEffectsState(),
|
||||
val isMiniPlayerHidden: Boolean = false,
|
||||
val unseenFavoritesCount: Int = 0
|
||||
val unseenFavoritesCount: Int = 0,
|
||||
val nowPlayingTitle: String? = null,
|
||||
val trackHistory: List<TrackEntry> = emptyList()
|
||||
)
|
||||
|
||||
class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
@@ -60,10 +58,12 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private val _selectedTab = MutableStateFlow(AppTab.RADIO)
|
||||
private val _isNowPlayingOpen = MutableStateFlow(false)
|
||||
private val _isEqualizerPopOpen = MutableStateFlow(false)
|
||||
private val _isViewPopOpen = MutableStateFlow(false)
|
||||
private val _activeExtraTab = MutableStateFlow(ExtraPlayerTab.RECENT)
|
||||
private val _activeExtraTab = MutableStateFlow(ExtraPlayerTab.HISTORY)
|
||||
private val _isMiniPlayerHidden = MutableStateFlow(false)
|
||||
|
||||
// Newest first; kept for this session only.
|
||||
private val _trackHistory = MutableStateFlow<List<TrackEntry>>(emptyList())
|
||||
|
||||
private val _showBatteryOptimizationPrompt = MutableStateFlow(false)
|
||||
val showBatteryOptimizationPrompt: StateFlow<Boolean> = _showBatteryOptimizationPrompt.asStateFlow()
|
||||
|
||||
@@ -83,16 +83,15 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
repository.favoritesFlow,
|
||||
repository.recentsFlow,
|
||||
_selectedTab,
|
||||
repository.viewModeFlow,
|
||||
repository.sizeStepFlow,
|
||||
_isNowPlayingOpen,
|
||||
_isEqualizerPopOpen,
|
||||
_isViewPopOpen,
|
||||
_activeExtraTab,
|
||||
AudioEffectsController.state,
|
||||
_isMiniPlayerHidden,
|
||||
repository.seenFavoritesFlow,
|
||||
_stations
|
||||
_stations,
|
||||
playerManager.nowPlayingTitle,
|
||||
_trackHistory
|
||||
) { params ->
|
||||
val current = params[0] as? RadioStation
|
||||
val pState = params[1] as PlayerState
|
||||
@@ -101,18 +100,18 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val recentsIds = params[3] as List<String>
|
||||
val tab = params[4] as AppTab
|
||||
val mode = params[5] as ViewMode
|
||||
val size = params[6] as IconSizeStep
|
||||
val nowPlaying = params[7] as Boolean
|
||||
val eqPop = params[8] as Boolean
|
||||
val viewPop = params[9] as Boolean
|
||||
val extraTab = params[10] as ExtraPlayerTab
|
||||
val effects = params[11] as AudioEffectsState
|
||||
val miniHidden = params[12] as Boolean
|
||||
val nowPlaying = params[5] as Boolean
|
||||
val eqPop = params[6] as Boolean
|
||||
val extraTab = params[7] as ExtraPlayerTab
|
||||
val effects = params[8] as AudioEffectsState
|
||||
val miniHidden = params[9] as Boolean
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val seenFavs = params[13] as Set<String>
|
||||
val seenFavs = params[10] as Set<String>
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val orderedStations = params[14] as List<RadioStation>
|
||||
val orderedStations = params[11] as List<RadioStation>
|
||||
val songTitle = params[12] as String?
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val history = params[13] as List<TrackEntry>
|
||||
|
||||
val byId = orderedStations.associateBy { it.id }
|
||||
val recentsList = recentsIds.mapNotNull { byId[it] }
|
||||
@@ -124,15 +123,14 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
favorites = favs,
|
||||
recents = recentsList,
|
||||
selectedTab = tab,
|
||||
viewMode = mode,
|
||||
sizeStep = size,
|
||||
isNowPlayingOpen = nowPlaying,
|
||||
isEqualizerPopOpen = eqPop,
|
||||
isViewPopOpen = viewPop,
|
||||
activeExtraTab = extraTab,
|
||||
audioEffects = effects,
|
||||
isMiniPlayerHidden = miniHidden,
|
||||
unseenFavoritesCount = favs.count { it !in seenFavs }
|
||||
unseenFavoritesCount = favs.count { it !in seenFavs },
|
||||
nowPlayingTitle = songTitle,
|
||||
trackHistory = history
|
||||
)
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
@@ -141,8 +139,6 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
stations = stations,
|
||||
currentStation = initialStation,
|
||||
favorites = repository.favoritesFlow.value,
|
||||
viewMode = repository.viewModeFlow.value,
|
||||
sizeStep = repository.sizeStepFlow.value,
|
||||
audioEffects = AudioEffectsController.state.value,
|
||||
unseenFavoritesCount = repository.favoritesFlow.value.count { it !in repository.seenFavoritesFlow.value }
|
||||
)
|
||||
@@ -159,6 +155,20 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
}
|
||||
}
|
||||
}
|
||||
viewModelScope.launch {
|
||||
playerManager.nowPlayingTitle.collect { title ->
|
||||
val stationId = playerManager.currentMediaId.value ?: _currentStation.value?.id
|
||||
if (title != null && stationId != null) recordTrack(stationId, title)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun recordTrack(stationId: String, title: String) {
|
||||
val history = _trackHistory.value
|
||||
val last = history.firstOrNull { it.stationId == stationId }
|
||||
if (last?.title == title) return
|
||||
_trackHistory.value = (listOf(TrackEntry(stationId, title, System.currentTimeMillis())) + history)
|
||||
.take(MAX_TRACK_HISTORY)
|
||||
}
|
||||
|
||||
/** Tap on a station tile: open the player for the station already on air, otherwise tune in. */
|
||||
@@ -273,20 +283,11 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
|
||||
fun setSelectedTab(tab: AppTab) {
|
||||
_selectedTab.value = tab
|
||||
_isViewPopOpen.value = false
|
||||
if (tab == AppTab.FAVORITES) {
|
||||
repository.markFavoritesSeen(repository.favoritesFlow.value)
|
||||
}
|
||||
}
|
||||
|
||||
fun setViewMode(mode: ViewMode) {
|
||||
repository.setViewMode(mode)
|
||||
}
|
||||
|
||||
fun setSizeStep(step: IconSizeStep) {
|
||||
repository.setSizeStep(step)
|
||||
}
|
||||
|
||||
fun openNowPlaying() {
|
||||
_isNowPlayingOpen.value = true
|
||||
}
|
||||
@@ -304,14 +305,6 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
_isEqualizerPopOpen.value = false
|
||||
}
|
||||
|
||||
fun toggleViewPop() {
|
||||
_isViewPopOpen.value = !_isViewPopOpen.value
|
||||
}
|
||||
|
||||
fun closeViewPop() {
|
||||
_isViewPopOpen.value = false
|
||||
}
|
||||
|
||||
fun setActiveExtraTab(tab: ExtraPlayerTab) {
|
||||
_activeExtraTab.value = tab
|
||||
}
|
||||
@@ -320,4 +313,8 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
super.onCleared()
|
||||
playerManager.release()
|
||||
}
|
||||
|
||||
private companion object {
|
||||
const val MAX_TRACK_HISTORY = 60
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user