mirror of
https://github.com/kalarina-bit/Fogwave.git
synced 2026-11-22 08:06:09 +00:00
Remove track history tab; fix hard edge of home fog and rows showing under the dock
This commit is contained in:
@@ -36,20 +36,8 @@ 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 }
|
||||
}
|
||||
|
||||
@@ -10,10 +10,15 @@ import androidx.compose.foundation.Canvas
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clipToBounds
|
||||
import androidx.compose.ui.draw.drawWithContent
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.BlendMode
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.CompositingStrategy
|
||||
import androidx.compose.ui.graphics.drawscope.DrawScope
|
||||
import androidx.compose.ui.graphics.graphicsLayer
|
||||
import androidx.compose.ui.graphics.lerp
|
||||
import kotlin.math.PI
|
||||
import kotlin.math.cos
|
||||
@@ -63,7 +68,8 @@ fun FogLayer(
|
||||
label = "fog_breathe"
|
||||
)
|
||||
|
||||
Canvas(modifier = modifier) {
|
||||
// Wisps are larger than the layer; clipping keeps them from leaking past its edges.
|
||||
Canvas(modifier = modifier.clipToBounds()) {
|
||||
Wisps.forEach { wisp -> drawWisp(wisp, t, breathe * intensity, tint) }
|
||||
}
|
||||
}
|
||||
@@ -90,3 +96,15 @@ private fun DrawScope.drawWisp(wisp: Wisp, time: Float, intensity: Float, tint:
|
||||
center = center
|
||||
)
|
||||
}
|
||||
|
||||
/** Fades the content to transparent towards the bottom, starting at [from] of its height. */
|
||||
fun Modifier.fadeOutBottom(from: Float = 0.55f): Modifier = this
|
||||
.clipToBounds()
|
||||
.graphicsLayer { compositingStrategy = CompositingStrategy.Offscreen }
|
||||
.drawWithContent {
|
||||
drawContent()
|
||||
drawRect(
|
||||
brush = Brush.verticalGradient(from to Color.Black, 1f to Color.Transparent),
|
||||
blendMode = BlendMode.DstIn
|
||||
)
|
||||
}
|
||||
|
||||
@@ -52,6 +52,8 @@ fun HomeBackdrop(
|
||||
.fillMaxWidth()
|
||||
.height(420.dp)
|
||||
.graphicsLayer { alpha = visibility().coerceIn(0f, 1f) }
|
||||
// Everything (photo and fog) melts into the page instead of ending at a hard edge.
|
||||
.fadeOutBottom(from = 0.45f)
|
||||
) {
|
||||
AsyncImage(
|
||||
model = request,
|
||||
@@ -63,15 +65,14 @@ fun HomeBackdrop(
|
||||
modifier = Modifier.fillMaxSize()
|
||||
)
|
||||
FogLayer(tint = tint, intensity = 0.6f, modifier = Modifier.fillMaxSize())
|
||||
// Darker top keeps the header readable over the photo.
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(
|
||||
Brush.verticalGradient(
|
||||
0f to background.copy(alpha = 0.45f),
|
||||
0.35f to background.copy(alpha = 0.15f),
|
||||
0.7f to background.copy(alpha = 0.7f),
|
||||
1f to background
|
||||
0.35f to Color.Transparent
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -2,7 +2,6 @@ package cc.skysparkle.fogwave.ui.components
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.text.format.DateFormat
|
||||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.animation.core.FastOutLinearInEasing
|
||||
import androidx.compose.animation.core.Spring
|
||||
@@ -75,11 +74,9 @@ import androidx.compose.ui.unit.sp
|
||||
import cc.skysparkle.fogwave.R
|
||||
import cc.skysparkle.fogwave.data.model.ExtraPlayerTab
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
import cc.skysparkle.fogwave.data.model.TrackEntry
|
||||
import cc.skysparkle.fogwave.player.AudioEffectsState
|
||||
import cc.skysparkle.fogwave.player.PlayerState
|
||||
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
|
||||
import java.util.Date
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
@Composable
|
||||
@@ -87,7 +84,6 @@ fun NowPlayingSheet(
|
||||
station: RadioStation?,
|
||||
playerState: PlayerState,
|
||||
trackTitle: String?,
|
||||
trackHistory: List<TrackEntry>,
|
||||
isFavorite: Boolean,
|
||||
onToggleFavorite: () -> Unit,
|
||||
onTogglePlay: () -> Unit,
|
||||
@@ -163,6 +159,7 @@ fun NowPlayingSheet(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(620.dp)
|
||||
.fadeOutBottom(from = 0.5f)
|
||||
) {
|
||||
FogLayer(
|
||||
tint = accent,
|
||||
@@ -175,9 +172,7 @@ fun NowPlayingSheet(
|
||||
.background(
|
||||
Brush.verticalGradient(
|
||||
0f to colors.background.copy(alpha = 0.35f),
|
||||
0.3f to Color.Transparent,
|
||||
0.75f to colors.background.copy(alpha = 0.6f),
|
||||
1f to colors.background
|
||||
0.3f to Color.Transparent
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -407,8 +402,6 @@ fun NowPlayingSheet(
|
||||
ExtraPanel(
|
||||
station = station,
|
||||
playerState = playerState,
|
||||
trackTitle = trackTitle,
|
||||
trackHistory = trackHistory,
|
||||
activeExtraTab = activeExtraTab,
|
||||
onSelectExtraTab = onSelectExtraTab,
|
||||
recents = recents,
|
||||
@@ -421,13 +414,11 @@ fun NowPlayingSheet(
|
||||
}
|
||||
}
|
||||
|
||||
/** Lower card of the player: track history, recent and similar stations, station info. */
|
||||
/** Lower card of the player: recent and similar stations, station info. */
|
||||
@Composable
|
||||
private fun ExtraPanel(
|
||||
station: RadioStation,
|
||||
playerState: PlayerState,
|
||||
trackTitle: String?,
|
||||
trackHistory: List<TrackEntry>,
|
||||
activeExtraTab: ExtraPlayerTab,
|
||||
onSelectExtraTab: (ExtraPlayerTab) -> Unit,
|
||||
recents: List<RadioStation>,
|
||||
@@ -435,7 +426,6 @@ private fun ExtraPanel(
|
||||
onSelectStation: (RadioStation) -> Unit
|
||||
) {
|
||||
val colors = LocalGeoColors.current
|
||||
val isPlaying = playerState is PlayerState.Playing
|
||||
|
||||
Column(
|
||||
modifier = Modifier
|
||||
@@ -500,20 +490,6 @@ private fun ExtraPanel(
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp)
|
||||
) {
|
||||
when (activeExtraTab) {
|
||||
ExtraPlayerTab.HISTORY -> {
|
||||
val entries = trackHistory.filter { it.stationId == station.id }
|
||||
if (entries.isEmpty()) {
|
||||
EmptyHint(stringResource(R.string.history_empty))
|
||||
} else {
|
||||
entries.forEachIndexed { index, entry ->
|
||||
TrackRow(
|
||||
entry = entry,
|
||||
isNowPlaying = index == 0 && isPlaying && entry.title == trackTitle
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ExtraPlayerTab.RECENT -> {
|
||||
if (recents.isEmpty()) {
|
||||
EmptyHint(stringResource(R.string.recent_empty))
|
||||
@@ -572,77 +548,6 @@ private fun ExtraPanel(
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun TrackRow(entry: TrackEntry, isNowPlaying: Boolean) {
|
||||
val colors = LocalGeoColors.current
|
||||
val context = LocalContext.current
|
||||
val time = remember(entry.startedAtMillis) {
|
||||
DateFormat.getTimeFormat(context).format(Date(entry.startedAtMillis))
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(horizontal = 10.dp, vertical = 9.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(12.dp)
|
||||
) {
|
||||
Column(modifier = Modifier.weight(1f)) {
|
||||
Row(
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp)
|
||||
) {
|
||||
Text(
|
||||
text = entry.song,
|
||||
style = MaterialTheme.typography.bodyMedium.copy(
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = if (isNowPlaying) colors.deepPurple else colors.onSurface
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis,
|
||||
modifier = Modifier.weight(1f, fill = false)
|
||||
)
|
||||
if (isNowPlaying) {
|
||||
Text(
|
||||
text = stringResource(R.string.history_now_playing_tag),
|
||||
style = MaterialTheme.typography.labelSmall.copy(
|
||||
fontWeight = FontWeight.SemiBold,
|
||||
fontSize = 10.sp,
|
||||
color = colors.primary
|
||||
),
|
||||
maxLines = 1
|
||||
)
|
||||
}
|
||||
}
|
||||
entry.artist?.let { artist ->
|
||||
Text(
|
||||
text = artist,
|
||||
style = MaterialTheme.typography.bodySmall.copy(
|
||||
fontSize = 12.sp,
|
||||
color = colors.onSurfaceVariant
|
||||
),
|
||||
maxLines = 1,
|
||||
overflow = TextOverflow.Ellipsis
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Text(
|
||||
text = time,
|
||||
style = MaterialTheme.typography.labelMedium.copy(
|
||||
color = if (isNowPlaying) colors.primary else colors.onSurfaceVariant
|
||||
)
|
||||
)
|
||||
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.size(width = 3.dp, height = 28.dp)
|
||||
.clip(CircleShape)
|
||||
.background(if (isNowPlaying) colors.accentLavender else Color.Transparent)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun EmptyHint(text: String) {
|
||||
Text(
|
||||
|
||||
@@ -44,6 +44,8 @@ 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.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
import androidx.compose.ui.platform.LocalDensity
|
||||
import androidx.compose.ui.res.pluralStringResource
|
||||
@@ -215,6 +217,15 @@ fun HomeScreen(
|
||||
dockHeight = measured
|
||||
}
|
||||
}
|
||||
// Rows (and the current station's highlight) fade out under the dock
|
||||
// instead of peeking through the gaps around the mini player and tabs.
|
||||
.background(
|
||||
Brush.verticalGradient(
|
||||
0f to Color.Transparent,
|
||||
0.22f to LocalGeoColors.current.background.copy(alpha = 0.94f),
|
||||
1f to LocalGeoColors.current.background
|
||||
)
|
||||
)
|
||||
// Insets live on the dock itself so the tabs stay clear of the gesture bar
|
||||
// even when the mini player is swiped away.
|
||||
.navigationBarsPadding()
|
||||
@@ -256,7 +267,6 @@ fun HomeScreen(
|
||||
station = uiState.currentStation,
|
||||
playerState = uiState.playerState,
|
||||
trackTitle = uiState.nowPlayingTitle,
|
||||
trackHistory = uiState.trackHistory,
|
||||
isFavorite = isCurFav,
|
||||
onToggleFavorite = { viewModel.toggleFavorite() },
|
||||
onTogglePlay = { viewModel.togglePlay() },
|
||||
|
||||
@@ -9,7 +9,6 @@ import androidx.lifecycle.viewModelScope
|
||||
import cc.skysparkle.fogwave.data.model.AppTab
|
||||
import cc.skysparkle.fogwave.data.model.ExtraPlayerTab
|
||||
import cc.skysparkle.fogwave.data.model.RadioStation
|
||||
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
|
||||
@@ -33,12 +32,11 @@ data class RadioUiState(
|
||||
val selectedTab: AppTab = AppTab.RADIO,
|
||||
val isNowPlayingOpen: Boolean = false,
|
||||
val isEqualizerPopOpen: Boolean = false,
|
||||
val activeExtraTab: ExtraPlayerTab = ExtraPlayerTab.HISTORY,
|
||||
val activeExtraTab: ExtraPlayerTab = ExtraPlayerTab.RECENT,
|
||||
val audioEffects: AudioEffectsState = AudioEffectsState(),
|
||||
val isMiniPlayerHidden: Boolean = false,
|
||||
val unseenFavoritesCount: Int = 0,
|
||||
val nowPlayingTitle: String? = null,
|
||||
val trackHistory: List<TrackEntry> = emptyList()
|
||||
val nowPlayingTitle: String? = null
|
||||
)
|
||||
|
||||
class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
@@ -58,12 +56,9 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
private val _selectedTab = MutableStateFlow(AppTab.RADIO)
|
||||
private val _isNowPlayingOpen = MutableStateFlow(false)
|
||||
private val _isEqualizerPopOpen = MutableStateFlow(false)
|
||||
private val _activeExtraTab = MutableStateFlow(ExtraPlayerTab.HISTORY)
|
||||
private val _activeExtraTab = MutableStateFlow(ExtraPlayerTab.RECENT)
|
||||
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()
|
||||
|
||||
@@ -90,8 +85,7 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
_isMiniPlayerHidden,
|
||||
repository.seenFavoritesFlow,
|
||||
_stations,
|
||||
playerManager.nowPlayingTitle,
|
||||
_trackHistory
|
||||
playerManager.nowPlayingTitle
|
||||
) { params ->
|
||||
val current = params[0] as? RadioStation
|
||||
val pState = params[1] as PlayerState
|
||||
@@ -110,8 +104,6 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
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] }
|
||||
@@ -129,8 +121,7 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
|
||||
audioEffects = effects,
|
||||
isMiniPlayerHidden = miniHidden,
|
||||
unseenFavoritesCount = favs.count { it !in seenFavs },
|
||||
nowPlayingTitle = songTitle,
|
||||
trackHistory = history
|
||||
nowPlayingTitle = songTitle
|
||||
)
|
||||
}.stateIn(
|
||||
scope = viewModelScope,
|
||||
@@ -155,20 +146,6 @@ 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. */
|
||||
@@ -313,8 +290,4 @@ 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