Release 1.0.12 with only the WebP interface icons on top of 1.0.11

This commit is contained in:
2026-11-03 15:36:07 +02:00
parent 52af3a7f4c
commit 9efb12a25f
25 changed files with 518 additions and 611 deletions
@@ -1,22 +1,11 @@
package cc.skysparkle.fogwave
import android.app.Application
import android.content.Context
import cc.skysparkle.fogwave.data.repository.RadioRepository
import cc.skysparkle.fogwave.player.AudioEffectsEngine
import coil.ImageLoader
import coil.ImageLoaderFactory
import coil.memory.MemoryCache
class FogwaveApp : Application(), ImageLoaderFactory {
override fun onCreate() {
super.onCreate()
// Opening the preference files starts loading them on a background thread right away, so the
// first screen and the playback service usually find them loaded instead of waiting on the disk.
getSharedPreferences(RadioRepository.PREFS_NAME, Context.MODE_PRIVATE)
getSharedPreferences(AudioEffectsEngine.PREFS_NAME, Context.MODE_PRIVATE)
}
override fun newImageLoader(): ImageLoader {
return ImageLoader.Builder(this)
.memoryCache {
@@ -25,6 +14,7 @@ class FogwaveApp : Application(), ImageLoaderFactory {
.build()
}
.crossfade(true)
.respectCacheHeaders(false)
.build()
}
}
@@ -2,6 +2,8 @@ package cc.skysparkle.fogwave.data.repository
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
@@ -11,11 +13,107 @@ import kotlinx.coroutines.flow.asStateFlow
import org.json.JSONArray
class RadioRepository(context: Context) {
private val prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
private val prefs = context.getSharedPreferences("fogwave_prefs", Context.MODE_PRIVATE)
val stations: List<RadioStation> = RadioStations
val stations: List<RadioStation> = listOf(
RadioStation(
id = "zip",
name = "ZIP FM",
descriptionRes = R.string.station_desc_zip,
streamUrl = "https://stream4.radijas.lt/zipfm",
iconResId = R.drawable.ic_station_zipfm,
genres = listOf(Genre.HITS, Genre.POP, Genre.LITHUANIAN),
bitrate = "MP3"
),
RadioStation(
id = "powerhit",
name = "Power Hit Radio",
descriptionRes = R.string.station_desc_powerhit,
// Stable revma entry point: it redirects to a fresh node URL with a short-lived token.
streamUrl = "https://stream.rcs.revma.com/f31w7e0fveuvv",
iconResId = R.drawable.ic_station_powerhit,
genres = listOf(Genre.DANCE, Genre.POP, Genre.HITS),
bitrate = "AAC"
),
RadioStation(
id = "powerhitgold",
name = "Power Hit Radio Gold",
descriptionRes = R.string.station_desc_powerhitgold,
streamUrl = "https://stream.rcs.revma.com/asdpz3qfbhuvv",
iconResId = R.drawable.ic_station_powerhitgold,
genres = listOf(Genre.DANCE, Genre.OLDIES, Genre.HITS),
bitrate = "AAC"
),
RadioStation(
id = "rock",
name = "Rock FM",
descriptionRes = R.string.station_desc_rock,
streamUrl = "https://stream4.radijas.lt/rockfm",
iconResId = R.drawable.ic_station_rockfm,
genres = listOf(Genre.ROCK, Genre.LITHUANIAN),
bitrate = "MP3",
lightBackdrop = true
),
RadioStation(
id = "relax",
name = "Relax FM",
descriptionRes = R.string.station_desc_relax,
streamUrl = "https://stream4.radijas.lt/relaxfm",
iconResId = R.drawable.ic_station_relaxfm,
genres = listOf(Genre.EASY_LISTENING),
bitrate = "MP3"
),
RadioStation(
id = "lietus",
name = "Lietus",
descriptionRes = R.string.station_desc_lietus,
streamUrl = "https://stream.m-1.fm/lietus/aacp64",
iconResId = R.drawable.ic_station_lietus,
genres = listOf(Genre.LITHUANIAN, Genre.POP),
bitrate = "AAC 64 kbps",
lightBackdrop = true
),
RadioStation(
id = "m1",
name = "M-1",
descriptionRes = R.string.station_desc_m1,
streamUrl = "https://stream.m-1.fm/m1/aacp64",
iconResId = R.drawable.ic_station_m1,
genres = listOf(Genre.POP, Genre.HITS),
bitrate = "AAC 64 kbps"
),
RadioStation(
id = "plus",
name = "M-1 Plius",
descriptionRes = R.string.station_desc_plus,
streamUrl = "https://radio.m-1.fm/m1plius/aacp64",
iconResId = R.drawable.ic_station_m1plus,
genres = listOf(Genre.POP, Genre.OLDIES),
bitrate = "AAC 64 kbps",
lightBackdrop = true
),
RadioStation(
id = "goldfm",
name = "Gold FM",
descriptionRes = R.string.station_desc_goldfm,
streamUrl = "https://stream.goldfm.lt/goldfm.aac",
iconResId = R.drawable.ic_station_goldfm,
genres = listOf(Genre.OLDIES, Genre.HITS, Genre.LITHUANIAN),
bitrate = "AAC"
),
RadioStation(
id = "rc",
name = "RC",
descriptionRes = R.string.station_desc_rc,
streamUrl = "https://stream1.rc.lt/rc128.mp3",
iconResId = R.drawable.ic_station_rc,
genres = listOf(Genre.HITS, Genre.LITHUANIAN),
bitrate = "MP3 128 kbps",
lightBackdrop = true
)
)
private val stationIds: Set<String> = RadioStations.mapTo(HashSet()) { it.id }
private val stationIds: Set<String> = stations.mapTo(HashSet()) { it.id }
private val _favoritesFlow = MutableStateFlow<Set<String>>(loadFavorites())
val favoritesFlow: StateFlow<Set<String>> = _favoritesFlow.asStateFlow()
@@ -37,10 +135,10 @@ class RadioRepository(context: Context) {
return loadFavorites()
}
fun markFavoritesSeen() {
val copy = _favoritesFlow.value.toSet()
fun markFavoritesSeen(ids: Set<String>) {
val copy = ids.toSet()
_seenFavoritesFlow.value = copy
prefs.edit { putStringSet("seen_favorites", copy) }
prefs.edit { putStringSet("seen_favorites", copy); remove("last_seen_favorites_count") }
}
fun getLastStationId(): String? {
@@ -86,11 +184,18 @@ class RadioRepository(context: Context) {
return prefs.getStringSet("favorites", null)?.filterTo(HashSet()) { it in stationIds } ?: emptySet()
}
fun toggleFavorite(stationId: String) {
fun toggleFavorite(stationId: String): Boolean {
val current = _favoritesFlow.value.toMutableSet()
if (!current.remove(stationId)) current.add(stationId)
val isNowFav = if (current.contains(stationId)) {
current.remove(stationId)
false
} else {
current.add(stationId)
true
}
prefs.edit { putStringSet("favorites", current) }
_favoritesFlow.value = current
return isNowFav
}
private fun loadRecents(): List<String> {
@@ -155,8 +260,4 @@ class RadioRepository(context: Context) {
fun markBatteryOptimizationPromptSeen() {
prefs.edit { putBoolean("seen_battery_optimization_prompt", true) }
}
companion object {
const val PREFS_NAME = "fogwave_prefs"
}
}
@@ -1,104 +0,0 @@
package cc.skysparkle.fogwave.data.repository
import cc.skysparkle.fogwave.R
import cc.skysparkle.fogwave.data.model.Genre
import cc.skysparkle.fogwave.data.model.RadioStation
// Built once per process and shared by the UI and the playback service.
val RadioStations: List<RadioStation> = listOf(
RadioStation(
id = "zip",
name = "ZIP FM",
descriptionRes = R.string.station_desc_zip,
streamUrl = "https://stream4.radijas.lt/zipfm",
iconResId = R.drawable.ic_station_zipfm,
genres = listOf(Genre.HITS, Genre.POP, Genre.LITHUANIAN),
bitrate = "MP3"
),
RadioStation(
id = "powerhit",
name = "Power Hit Radio",
descriptionRes = R.string.station_desc_powerhit,
// Stable revma entry point: it redirects to a fresh node URL with a short-lived token.
streamUrl = "https://stream.rcs.revma.com/f31w7e0fveuvv",
iconResId = R.drawable.ic_station_powerhit,
genres = listOf(Genre.DANCE, Genre.POP, Genre.HITS),
bitrate = "AAC"
),
RadioStation(
id = "powerhitgold",
name = "Power Hit Radio Gold",
descriptionRes = R.string.station_desc_powerhitgold,
streamUrl = "https://stream.rcs.revma.com/asdpz3qfbhuvv",
iconResId = R.drawable.ic_station_powerhitgold,
genres = listOf(Genre.DANCE, Genre.OLDIES, Genre.HITS),
bitrate = "AAC"
),
RadioStation(
id = "rock",
name = "Rock FM",
descriptionRes = R.string.station_desc_rock,
streamUrl = "https://stream4.radijas.lt/rockfm",
iconResId = R.drawable.ic_station_rockfm,
genres = listOf(Genre.ROCK, Genre.LITHUANIAN),
bitrate = "MP3",
lightBackdrop = true
),
RadioStation(
id = "relax",
name = "Relax FM",
descriptionRes = R.string.station_desc_relax,
streamUrl = "https://stream4.radijas.lt/relaxfm",
iconResId = R.drawable.ic_station_relaxfm,
genres = listOf(Genre.EASY_LISTENING),
bitrate = "MP3"
),
RadioStation(
id = "lietus",
name = "Lietus",
descriptionRes = R.string.station_desc_lietus,
streamUrl = "https://stream.m-1.fm/lietus/aacp64",
iconResId = R.drawable.ic_station_lietus,
genres = listOf(Genre.LITHUANIAN, Genre.POP),
bitrate = "AAC 64 kbps",
lightBackdrop = true
),
RadioStation(
id = "m1",
name = "M-1",
descriptionRes = R.string.station_desc_m1,
streamUrl = "https://stream.m-1.fm/m1/aacp64",
iconResId = R.drawable.ic_station_m1,
genres = listOf(Genre.POP, Genre.HITS),
bitrate = "AAC 64 kbps"
),
RadioStation(
id = "plus",
name = "M-1 Plius",
descriptionRes = R.string.station_desc_plus,
streamUrl = "https://radio.m-1.fm/m1plius/aacp64",
iconResId = R.drawable.ic_station_m1plus,
genres = listOf(Genre.POP, Genre.OLDIES),
bitrate = "AAC 64 kbps",
lightBackdrop = true
),
RadioStation(
id = "goldfm",
name = "Gold FM",
descriptionRes = R.string.station_desc_goldfm,
streamUrl = "https://stream.goldfm.lt/goldfm.aac",
iconResId = R.drawable.ic_station_goldfm,
genres = listOf(Genre.OLDIES, Genre.HITS, Genre.LITHUANIAN),
bitrate = "AAC"
),
RadioStation(
id = "rc",
name = "RC",
descriptionRes = R.string.station_desc_rc,
streamUrl = "https://stream1.rc.lt/rc128.mp3",
iconResId = R.drawable.ic_station_rc,
genres = listOf(Genre.HITS, Genre.LITHUANIAN),
bitrate = "MP3 128 kbps",
lightBackdrop = true
)
)
@@ -42,6 +42,11 @@ object AudioEffectsController {
refresh()
}
fun setLoudnessGain(gainMillibel: Float) {
engine?.setLoudnessGain(gainMillibel)
refresh()
}
fun setDynamicsProcessingEnabled(enabled: Boolean) {
engine?.setDynamicsProcessingEnabled(enabled)
refresh()
@@ -18,19 +18,22 @@ data class EqualizerBand(
)
data class AudioEffectsState(
val equalizerAvailable: Boolean = false,
val equalizerEnabled: Boolean = false,
val bands: List<EqualizerBand> = emptyList(),
val presets: List<String> = emptyList(),
val currentPreset: Int = -1,
val loudnessAvailable: Boolean = false,
val loudnessEnabled: Boolean = false,
val loudnessGainMillibel: Float = 0f,
val loudnessMaxGainMillibel: Float = 2000f,
val dynamicsProcessingAvailable: Boolean = false,
val dynamicsProcessingEnabled: Boolean = false
)
class AudioEffectsEngine(context: Context, audioSessionId: Int) {
private val prefs: SharedPreferences =
context.applicationContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
context.applicationContext.getSharedPreferences("fogwave_audio_effects", Context.MODE_PRIVATE)
// Tracked manually: Equalizer.currentPreset is unreliable after bands are moved by hand.
private var currentPresetIndex: Int = prefs.getInt(KEY_PRESET, -1)
@@ -41,21 +44,12 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
private val presetNames = mutableListOf<String>()
// Fixed for the lifetime of the equalizer, so they are read once instead of on every refresh.
private var bandCenterFreqsHz = IntArray(0)
private var minBandLevel = 0
private var maxBandLevel = 0
init {
try {
equalizer = Equalizer(0, audioSessionId).apply {
for (p in 0 until numberOfPresets) {
presetNames.add(getPresetName(p.toShort()))
}
bandCenterFreqsHz = IntArray(numberOfBands.toInt()) { getCenterFreq(it.toShort()) / 1000 }
val range = bandLevelRange
minBandLevel = range[0].toInt()
maxBandLevel = range[1].toInt()
val preset = currentPresetIndex
if (preset in 0 until numberOfPresets) {
@@ -74,6 +68,7 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
try {
loudnessEnhancer = LoudnessEnhancer(audioSessionId).apply {
setTargetGain(prefs.getInt(KEY_LOUDNESS_GAIN, 0))
enabled = prefs.getBoolean(KEY_LOUDNESS_ENABLED, false)
}
} catch (e: Exception) {
@@ -146,24 +141,32 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
fun currentState(): AudioEffectsState {
val eq = equalizer
val bands = if (eq != null) {
bandCenterFreqsHz.indices.map { i ->
(0 until eq.numberOfBands).map { i ->
val idx = i.toShort()
val range = eq.bandLevelRange
EqualizerBand(
index = i,
centerFreqHz = bandCenterFreqsHz[i],
levelMillibel = eq.getBandLevel(i.toShort()).toInt(),
minLevelMillibel = minBandLevel,
maxLevelMillibel = maxBandLevel
centerFreqHz = eq.getCenterFreq(idx) / 1000,
levelMillibel = eq.getBandLevel(idx).toInt(),
minLevelMillibel = range[0].toInt(),
maxLevelMillibel = range[1].toInt()
)
}
} else emptyList()
return AudioEffectsState(
equalizerAvailable = eq != null,
equalizerEnabled = eq?.enabled ?: false,
bands = bands,
presets = presetNames,
currentPreset = if (eq != null) currentPresetIndex else -1,
loudnessAvailable = loudnessEnhancer != null,
loudnessEnabled = loudnessEnhancer?.enabled ?: false,
loudnessGainMillibel = try {
loudnessEnhancer?.targetGain ?: 0f
} catch (_: Exception) {
0f
},
dynamicsProcessingAvailable = dynamicsProcessing != null,
dynamicsProcessingEnabled = dynamicsProcessing?.enabled ?: false
)
@@ -208,6 +211,14 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
} catch (_: Exception) {}
}
fun setLoudnessGain(gainMillibel: Float) {
try {
val gain = gainMillibel.coerceIn(0f, 2000f).toInt()
loudnessEnhancer?.setTargetGain(gain)
prefs.edit { putInt(KEY_LOUDNESS_GAIN, gain) }
} catch (_: Exception) {}
}
fun setDynamicsProcessingEnabled(enabled: Boolean) {
try {
dynamicsProcessing?.enabled = enabled
@@ -224,13 +235,13 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
dynamicsProcessing = null
}
companion object {
const val PREFS_NAME = "fogwave_audio_effects"
private const val TAG = "AudioEffectsEngine"
private const val KEY_EQ_ENABLED = "eq_enabled"
private const val KEY_PRESET = "eq_preset"
private const val KEY_BAND_PREFIX = "eq_band_"
private const val KEY_LOUDNESS_ENABLED = "loudness_enabled"
private const val KEY_DYNAMICS_ENABLED = "dynamics_enabled"
private companion object {
const val TAG = "AudioEffectsEngine"
const val KEY_EQ_ENABLED = "eq_enabled"
const val KEY_PRESET = "eq_preset"
const val KEY_BAND_PREFIX = "eq_band_"
const val KEY_LOUDNESS_ENABLED = "loudness_enabled"
const val KEY_LOUDNESS_GAIN = "loudness_gain"
const val KEY_DYNAMICS_ENABLED = "dynamics_enabled"
}
}
@@ -6,7 +6,6 @@ import android.content.Intent
import android.media.AudioManager
import android.net.ConnectivityManager
import android.net.Network
import android.os.LocaleList
import android.os.SystemClock
import android.util.Log
import androidx.annotation.OptIn
@@ -20,13 +19,6 @@ import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.DefaultHttpDataSource
import androidx.media3.exoplayer.DefaultLoadControl
import androidx.media3.exoplayer.ExoPlayer
import androidx.media3.exoplayer.Renderer
import androidx.media3.exoplayer.RenderersFactory
import androidx.media3.exoplayer.audio.DefaultAudioSink
import androidx.media3.exoplayer.audio.MediaCodecAudioRenderer
import androidx.media3.exoplayer.mediacodec.DefaultMediaCodecAdapterFactory
import androidx.media3.exoplayer.mediacodec.MediaCodecSelector
import androidx.media3.exoplayer.metadata.MetadataRenderer
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory
import androidx.media3.session.LibraryResult
import androidx.media3.session.MediaLibraryService
@@ -36,7 +28,7 @@ import androidx.media3.session.MediaSession
import cc.skysparkle.fogwave.BuildConfig
import cc.skysparkle.fogwave.MainActivity
import cc.skysparkle.fogwave.R
import cc.skysparkle.fogwave.data.repository.RadioStations
import cc.skysparkle.fogwave.data.repository.RadioRepository
import com.google.common.collect.ImmutableList
import com.google.common.util.concurrent.Futures
import com.google.common.util.concurrent.ListenableFuture
@@ -51,6 +43,7 @@ import kotlinx.coroutines.launch
@OptIn(UnstableApi::class)
class FogwavePlaybackService : MediaLibraryService() {
private var mediaLibrarySession: MediaLibrarySession? = null
private lateinit var repository: RadioRepository
private lateinit var player: ExoPlayer
private var audioEffectsEngine: AudioEffectsEngine? = null
@@ -82,61 +75,23 @@ class FogwavePlaybackService : MediaLibraryService() {
.setPrioritizeTimeOverSizeThresholds(true)
.build()
// Radio streams carry only audio and ICY/ID3 metadata. Without the default factory R8 can drop
// the video, text and image renderers. The audio renderer is configured like the default one,
// and two metadata renderers keep ICY titles working next to an in-stream ID3 track.
private fun audioOnlyRenderersFactory() = RenderersFactory { handler, _, audioListener, _, metadataOutput ->
arrayOf<Renderer>(
MediaCodecAudioRenderer(
this@FogwavePlaybackService,
DefaultMediaCodecAdapterFactory(this@FogwavePlaybackService),
MediaCodecSelector.DEFAULT,
false,
handler,
audioListener,
DefaultAudioSink.Builder(this@FogwavePlaybackService).build()
),
MetadataRenderer(metadataOutput, handler.looper),
MetadataRenderer(metadataOutput, handler.looper)
)
}
// Browse tree for Android Auto: built once and served from memory, rebuilt only when the app
// language changes so station descriptions stay translated.
private var browseTreeLocales: LocaleList? = null
private lateinit var rootItem: MediaItem
private lateinit var stationItems: ImmutableList<MediaItem>
private fun ensureBrowseTree() {
val locales = resources.configuration.locales
if (locales == browseTreeLocales) return
rootItem = MediaItem.Builder()
.setMediaId(ROOT_ID)
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle(getString(R.string.app_name))
.setIsBrowsable(true)
.setIsPlayable(false)
.setMediaType(MediaMetadata.MEDIA_TYPE_FOLDER_MIXED)
.build()
)
.build()
stationItems = ImmutableList.copyOf(RadioStations.map { it.toMediaItem(this) })
browseTreeLocales = locales
}
private fun stationItem(mediaId: String): MediaItem? {
ensureBrowseTree()
return stationItems.find { it.mediaId == mediaId }
}
private val librarySessionCallback = object : MediaLibrarySession.Callback {
override fun onGetLibraryRoot(
session: MediaLibrarySession,
browser: MediaSession.ControllerInfo,
params: LibraryParams?
): ListenableFuture<LibraryResult<MediaItem>> {
ensureBrowseTree()
val rootItem = MediaItem.Builder()
.setMediaId(ROOT_ID)
.setMediaMetadata(
MediaMetadata.Builder()
.setTitle(getString(R.string.app_name))
.setIsBrowsable(true)
.setIsPlayable(false)
.setMediaType(MediaMetadata.MEDIA_TYPE_FOLDER_MIXED)
.build()
)
.build()
return Futures.immediateFuture(LibraryResult.ofItem(rootItem, params))
}
@@ -151,8 +106,8 @@ class FogwavePlaybackService : MediaLibraryService() {
if (parentId != ROOT_ID) {
return Futures.immediateFuture(LibraryResult.ofError(LibraryResult.RESULT_ERROR_BAD_VALUE))
}
ensureBrowseTree()
return Futures.immediateFuture(LibraryResult.ofItemList(stationItems, params))
val items = repository.stations.map { it.toMediaItem(this@FogwavePlaybackService) }
return Futures.immediateFuture(LibraryResult.ofItemList(ImmutableList.copyOf(items), params))
}
override fun onGetItem(
@@ -160,9 +115,9 @@ class FogwavePlaybackService : MediaLibraryService() {
browser: MediaSession.ControllerInfo,
mediaId: String
): ListenableFuture<LibraryResult<MediaItem>> {
val item = stationItem(mediaId)
val station = repository.stations.find { it.id == mediaId }
?: return Futures.immediateFuture(LibraryResult.ofError(LibraryResult.RESULT_ERROR_BAD_VALUE))
return Futures.immediateFuture(LibraryResult.ofItem(item, null))
return Futures.immediateFuture(LibraryResult.ofItem(station.toMediaItem(this@FogwavePlaybackService), null))
}
override fun onAddMediaItems(
@@ -171,7 +126,13 @@ class FogwavePlaybackService : MediaLibraryService() {
mediaItems: MutableList<MediaItem>
): ListenableFuture<MutableList<MediaItem>> {
val resolved = mediaItems.map { item ->
if (item.localConfiguration != null) item else stationItem(item.mediaId) ?: item
if (item.localConfiguration != null) {
item
} else {
repository.stations.find { it.id == item.mediaId }
?.toMediaItem(this@FogwavePlaybackService)
?: item
}
}.toMutableList()
resolved.firstOrNull()?.let { item ->
@@ -309,15 +270,14 @@ class FogwavePlaybackService : MediaLibraryService() {
override fun onCreate() {
super.onCreate()
repository = RadioRepository(applicationContext)
val audioManager = getSystemService(Context.AUDIO_SERVICE) as? AudioManager
val audioSessionId = audioManager?.generateAudioSessionId()?.takeIf { it != 0 }
?: C.AUDIO_SESSION_ID_UNSET
player = ExoPlayer.Builder(
this,
audioOnlyRenderersFactory(),
DefaultMediaSourceFactory(this).setDataSourceFactory(httpDataSourceFactory)
)
player = ExoPlayer.Builder(this)
.setMediaSourceFactory(DefaultMediaSourceFactory(this).setDataSourceFactory(httpDataSourceFactory))
.setLoadControl(loadControl)
.build()
.apply {
@@ -126,7 +126,7 @@ class RadioPlayerManager(private val context: Context) {
}
}
private fun play() {
fun play() {
val c = controller
when {
c == null || c.mediaItemCount == 0 -> currentStation?.let { playStation(it) }
@@ -140,7 +140,7 @@ class RadioPlayerManager(private val context: Context) {
}
}
private fun pause() {
fun pause() {
controller?.pause()
}
@@ -23,6 +23,7 @@ import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Slider
import androidx.compose.material3.SliderDefaults
@@ -31,7 +32,6 @@ import androidx.compose.material3.SwitchDefaults
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha
@@ -47,55 +47,10 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import cc.skysparkle.fogwave.R
import cc.skysparkle.fogwave.player.AudioEffectsState
import cc.skysparkle.fogwave.player.EqualizerBand
import cc.skysparkle.fogwave.ui.theme.DarkGeoColors
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
import cc.skysparkle.fogwave.ui.theme.Typography
import java.util.Locale
import kotlin.math.roundToInt
// Text styles are built once from the app's only palette, not copied on every slider move.
private val EqTitleStyle = Typography.titleLarge.copy(
fontWeight = FontWeight.Bold,
color = DarkGeoColors.deepPurple
)
private val EqStateStyle = Typography.labelMedium.copy(
fontWeight = FontWeight.Bold,
color = DarkGeoColors.onSurfaceVariant
)
private val EqStateOnStyle = EqStateStyle.copy(color = DarkGeoColors.liveGreen)
private val EqSectionStyle = Typography.labelMedium.copy(
color = DarkGeoColors.onSurfaceVariant,
fontWeight = FontWeight.Medium
)
private val EqUnavailableStyle = Typography.bodyMedium.copy(color = DarkGeoColors.onSurfaceVariant)
private val EqPresetNameStyle = Typography.titleMedium.copy(
fontWeight = FontWeight.SemiBold,
color = DarkGeoColors.onSurface
)
private val EqPresetChipStyle = Typography.labelLarge.copy(
fontWeight = FontWeight.Medium,
color = DarkGeoColors.onSurfaceVariant
)
private val EqPresetChipSelectedStyle = Typography.labelLarge.copy(
fontWeight = FontWeight.Bold,
color = DarkGeoColors.deepPurple
)
private val EqLevelStyle = Typography.labelSmall.copy(
fontSize = 11.sp,
fontWeight = FontWeight.SemiBold,
color = DarkGeoColors.primary
)
private val EqLevelZeroStyle = EqLevelStyle.copy(color = DarkGeoColors.onSurfaceVariant)
private val EqFrequencyStyle = Typography.labelSmall.copy(
fontSize = 11.sp,
color = DarkGeoColors.onSurfaceVariant
)
private val EqToggleLabelStyle = Typography.bodyMedium.copy(
fontWeight = FontWeight.Medium,
color = DarkGeoColors.onSurface
)
@Composable
fun EqualizerSheet(
audioEffects: AudioEffectsState,
@@ -136,12 +91,18 @@ fun EqualizerSheet(
}
Text(
text = stringResource(R.string.equalizer_title),
style = EqTitleStyle,
style = MaterialTheme.typography.titleLarge.copy(
fontWeight = FontWeight.Bold,
color = LocalGeoColors.current.deepPurple
),
modifier = Modifier.weight(1f)
)
Text(
text = if (audioEffects.equalizerEnabled) stringResource(R.string.equalizer_on) else stringResource(R.string.equalizer_off),
style = if (audioEffects.equalizerEnabled) EqStateOnStyle else EqStateStyle,
style = MaterialTheme.typography.labelMedium.copy(
fontWeight = FontWeight.Bold,
color = if (audioEffects.equalizerEnabled) LocalGeoColors.current.liveGreen else LocalGeoColors.current.onSurfaceVariant
),
modifier = Modifier.padding(end = 6.dp)
)
Switch(
@@ -175,7 +136,10 @@ fun EqualizerSheet(
)
Text(
text = stringResource(R.string.equalizer_sound_section),
style = EqSectionStyle
style = MaterialTheme.typography.labelMedium.copy(
color = LocalGeoColors.current.onSurfaceVariant,
fontWeight = FontWeight.Medium
)
)
Box(
modifier = Modifier
@@ -206,11 +170,54 @@ fun EqualizerSheet(
verticalAlignment = Alignment.CenterVertically
) {
audioEffects.bands.forEach { band ->
EqualizerBandColumn(
band = band,
enabled = audioEffects.equalizerEnabled,
onSetEqualizerBand = onSetEqualizerBand
)
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.fillMaxHeight()
) {
val db = (band.levelMillibel / 100f).roundToInt()
Text(
text = if (db > 0) "+$db dB" else "$db dB",
style = MaterialTheme.typography.labelSmall.copy(
fontSize = 11.sp,
fontWeight = FontWeight.SemiBold,
color = if (db == 0) LocalGeoColors.current.onSurfaceVariant
else LocalGeoColors.current.primary
)
)
Box(
modifier = Modifier
.weight(1f)
.width(40.dp),
contentAlignment = Alignment.Center
) {
Slider(
value = band.levelMillibel.toFloat(),
onValueChange = { onSetEqualizerBand(band.index, it.roundToInt()) },
valueRange = band.minLevelMillibel.toFloat()..band.maxLevelMillibel.toFloat(),
enabled = audioEffects.equalizerEnabled,
colors = SliderDefaults.colors(
thumbColor = LocalGeoColors.current.primary,
activeTrackColor = LocalGeoColors.current.primary,
inactiveTrackColor = LocalGeoColors.current.outlineVariant
),
modifier = Modifier
// requiredWidth (not width): the parent is narrower, and width() would be clamped before rotation.
.requiredWidth(160.dp)
.graphicsLayer {
rotationZ = 270f
transformOrigin = TransformOrigin(0.5f, 0.5f)
}
)
}
Text(
text = frequencyLabel(band.centerFreqHz),
style = MaterialTheme.typography.labelSmall.copy(
fontSize = 11.sp,
color = LocalGeoColors.current.onSurfaceVariant
)
)
}
}
}
}
@@ -227,7 +234,7 @@ fun EqualizerSheet(
)
Text(
text = stringResource(R.string.equalizer_unavailable),
style = EqUnavailableStyle
style = MaterialTheme.typography.bodyMedium.copy(color = LocalGeoColors.current.onSurfaceVariant)
)
}
}
@@ -249,22 +256,25 @@ fun EqualizerSheet(
)
Text(
text = currentPresetName,
style = EqPresetNameStyle
style = MaterialTheme.typography.titleMedium.copy(
fontWeight = FontWeight.SemiBold,
color = LocalGeoColors.current.onSurface
)
)
}
// Captured instead of audioEffects, so moving a band does not recompose the preset chips.
val presets = audioEffects.presets
val currentPreset = audioEffects.currentPreset
LazyRow(
modifier = Modifier.fillMaxWidth(),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
itemsIndexed(presets) { index, name ->
val selected = currentPreset == index
itemsIndexed(audioEffects.presets) { index, name ->
val selected = audioEffects.currentPreset == index
Text(
text = presetLabel(name),
style = if (selected) EqPresetChipSelectedStyle else EqPresetChipStyle,
style = MaterialTheme.typography.labelLarge.copy(
fontWeight = if (selected) FontWeight.Bold else FontWeight.Medium,
color = if (selected) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurfaceVariant
),
modifier = Modifier
.clip(RoundedCornerShape(20.dp))
.background(if (selected) LocalGeoColors.current.primaryContainer else LocalGeoColors.current.surfaceContainerHigh)
@@ -314,57 +324,6 @@ fun EqualizerSheet(
}
}
// Stable parameters: moving one slider recomposes only that band, not its neighbors.
@Composable
private fun EqualizerBandColumn(
band: EqualizerBand,
enabled: Boolean,
onSetEqualizerBand: (Int, Int) -> Unit
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(6.dp),
modifier = Modifier.fillMaxHeight()
) {
val db = (band.levelMillibel / 100f).roundToInt()
Text(
text = if (db > 0) "+$db dB" else "$db dB",
style = if (db == 0) EqLevelZeroStyle else EqLevelStyle
)
Box(
modifier = Modifier
.weight(1f)
.width(40.dp),
contentAlignment = Alignment.Center
) {
Slider(
value = band.levelMillibel.toFloat(),
onValueChange = { onSetEqualizerBand(band.index, it.roundToInt()) },
valueRange = band.minLevelMillibel.toFloat()..band.maxLevelMillibel.toFloat(),
enabled = enabled,
colors = SliderDefaults.colors(
thumbColor = LocalGeoColors.current.primary,
activeTrackColor = LocalGeoColors.current.primary,
inactiveTrackColor = LocalGeoColors.current.outlineVariant
),
modifier = Modifier
// requiredWidth (not width): the parent is narrower, and width() would be clamped before rotation.
.requiredWidth(160.dp)
.graphicsLayer {
rotationZ = 270f
transformOrigin = TransformOrigin(0.5f, 0.5f)
}
)
}
// The label never changes for a band, so it is formatted once, not on every slider move.
val frequency = remember(band.centerFreqHz) { frequencyLabel(band.centerFreqHz) }
Text(
text = frequency,
style = EqFrequencyStyle
)
}
}
@Composable
private fun ToggleRow(
label: String,
@@ -383,7 +342,10 @@ private fun ToggleRow(
) {
Text(
text = label,
style = EqToggleLabelStyle,
style = MaterialTheme.typography.bodyMedium.copy(
fontWeight = FontWeight.Medium,
color = LocalGeoColors.current.onSurface
),
modifier = Modifier.weight(1f)
)
Switch(
@@ -5,6 +5,7 @@ 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,6 +27,7 @@ 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
import androidx.compose.runtime.Composable
@@ -38,8 +40,10 @@ 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
@@ -49,27 +53,12 @@ import androidx.compose.ui.unit.sp
import cc.skysparkle.fogwave.R
import cc.skysparkle.fogwave.data.model.RadioStation
import cc.skysparkle.fogwave.player.PlayerState
import cc.skysparkle.fogwave.ui.theme.DarkGeoColors
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
import cc.skysparkle.fogwave.ui.theme.Typography
import kotlin.math.roundToInt
private val TABLET_BREAKPOINT_DP = 600.dp
private val TABLET_MINI_PLAYER_MAX_WIDTH_DP = 640.dp
// Text styles are built once from the app's only palette, not copied on every recomposition.
private val MiniNameStyle = Typography.bodyMedium.copy(
fontWeight = FontWeight.Bold,
fontSize = 14.5.sp,
color = DarkGeoColors.deepPurple
)
private val MiniStatusStyle = Typography.bodySmall.copy(
fontSize = 11.5.sp,
color = DarkGeoColors.onSurfaceVariant
)
private val MiniStatusLiveStyle = MiniStatusStyle.copy(color = DarkGeoColors.liveGreen)
private val MiniStatusErrorStyle = MiniStatusStyle.copy(color = DarkGeoColors.redFavorite)
@Composable
fun MiniPlayer(
station: RadioStation?,
@@ -173,7 +162,12 @@ fun MiniPlayer(
.background(stationTileColor(station))
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(14.dp))
) {
StationArtwork(station, Modifier.matchParentSize())
Image(
painter = painterResource(id = station.iconResId),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
)
}
Column(
@@ -182,14 +176,21 @@ fun MiniPlayer(
) {
Text(
text = station.name,
style = MiniNameStyle,
style = MaterialTheme.typography.bodyMedium.copy(
fontWeight = FontWeight.Bold,
fontSize = 14.5.sp,
color = LocalGeoColors.current.deepPurple
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = subText,
style = if (isError) MiniStatusErrorStyle else (if (isPlaying) MiniStatusLiveStyle else MiniStatusStyle),
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)
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -7,6 +7,7 @@ import androidx.compose.animation.core.animate
import androidx.compose.animation.core.animateFloatAsState
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
@@ -47,16 +48,18 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.scale
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
import androidx.compose.ui.input.nestedscroll.nestedScroll
import androidx.compose.ui.input.pointer.pointerInput
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.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
@@ -70,61 +73,11 @@ 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.player.AudioEffectsState
import cc.skysparkle.fogwave.player.PlayerState
import cc.skysparkle.fogwave.ui.theme.DarkGeoColors
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
import cc.skysparkle.fogwave.ui.theme.Typography
import kotlin.math.roundToInt
// Text styles are built once from the app's only palette, not copied on every recomposition.
private val SheetLabelStyle = Typography.labelSmall.copy(
fontWeight = FontWeight.Bold,
fontSize = 11.5.sp,
letterSpacing = 1.2.sp,
color = DarkGeoColors.primary
)
private val SheetTitleStyle = Typography.headlineMedium.copy(
fontWeight = FontWeight.ExtraBold,
fontSize = 25.sp,
letterSpacing = (-0.5).sp,
color = DarkGeoColors.deepPurple,
textAlign = TextAlign.Center
)
private val SheetDescriptionStyle = Typography.bodyMedium.copy(
fontSize = 14.sp,
color = DarkGeoColors.onSurfaceVariant,
textAlign = TextAlign.Center
)
private val SheetStatusStyle = Typography.labelSmall.copy(
fontWeight = FontWeight.SemiBold,
fontSize = 12.sp,
color = DarkGeoColors.onSurfaceVariant
)
private val SheetStatusLiveStyle = SheetStatusStyle.copy(color = DarkGeoColors.deepPurple)
private val SheetStatusErrorStyle = SheetStatusStyle.copy(color = DarkGeoColors.redFavorite)
private val SheetEmptyListStyle = Typography.bodySmall.copy(
color = DarkGeoColors.onSurfaceVariant,
textAlign = TextAlign.Center
)
private val SheetRowNameStyle = Typography.bodyMedium.copy(
fontWeight = FontWeight.Bold,
color = DarkGeoColors.onSurface
)
private val SheetRowNameAccentStyle = SheetRowNameStyle.copy(color = DarkGeoColors.deepPurple)
private val SheetRowDescriptionStyle = Typography.bodySmall.copy(
fontSize = 11.5.sp,
color = DarkGeoColors.onSurfaceVariant
)
private val InfoKeyStyle = Typography.bodySmall.copy(
fontWeight = FontWeight.SemiBold,
color = DarkGeoColors.onSurfaceVariant
)
private val InfoValueStyle = Typography.bodySmall.copy(
fontWeight = FontWeight.Bold,
color = DarkGeoColors.deepPurple,
textAlign = TextAlign.End
)
@Composable
fun NowPlayingSheet(
station: RadioStation?,
@@ -136,7 +89,7 @@ fun NowPlayingSheet(
onNext: () -> Unit,
onClose: () -> Unit,
onOpenEqualizer: () -> Unit,
equalizerEnabled: Boolean,
audioEffects: AudioEffectsState,
activeExtraTab: ExtraPlayerTab,
onSelectExtraTab: (ExtraPlayerTab) -> Unit,
recents: List<RadioStation>,
@@ -219,7 +172,12 @@ fun NowPlayingSheet(
// The sheet closes by swiping down, tapping outside it or pressing Back.
Text(
text = stringResource(R.string.now_playing_label),
style = SheetLabelStyle,
style = MaterialTheme.typography.labelSmall.copy(
fontWeight = FontWeight.Bold,
fontSize = 11.5.sp,
letterSpacing = 1.2.sp,
color = LocalGeoColors.current.primary
),
modifier = Modifier.padding(horizontal = 24.dp, vertical = 12.dp)
)
@@ -228,17 +186,18 @@ fun NowPlayingSheet(
.padding(horizontal = 44.dp, vertical = 10.dp)
.fillMaxWidth()
.aspectRatio(1f)
// Scaled in the layer, so the spring does not recompose the sheet every frame.
.graphicsLayer {
scaleX = artScale
scaleY = artScale
}
.scale(artScale)
.shadow(8.dp, RoundedCornerShape(32.dp))
.clip(RoundedCornerShape(32.dp))
.background(stationTileColor(station))
.border(1.5.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(32.dp))
) {
StationArtwork(station, Modifier.matchParentSize())
Image(
painter = painterResource(id = station.iconResId),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
)
}
Column(
@@ -249,7 +208,13 @@ fun NowPlayingSheet(
) {
Text(
text = station.name,
style = SheetTitleStyle,
style = MaterialTheme.typography.headlineMedium.copy(
fontWeight = FontWeight.ExtraBold,
fontSize = 25.sp,
letterSpacing = (-0.5).sp,
color = LocalGeoColors.current.deepPurple,
textAlign = TextAlign.Center
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -258,7 +223,11 @@ fun NowPlayingSheet(
Text(
text = stationDescription(station),
style = SheetDescriptionStyle,
style = MaterialTheme.typography.bodyMedium.copy(
fontSize = 14.sp,
color = LocalGeoColors.current.onSurfaceVariant,
textAlign = TextAlign.Center
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -304,7 +273,11 @@ fun NowPlayingSheet(
isPlaying -> stringResource(R.string.now_playing_live)
else -> stringResource(R.string.player_stopped)
},
style = if (isPlaying) SheetStatusLiveStyle else (if (isError) SheetStatusErrorStyle else SheetStatusStyle)
style = MaterialTheme.typography.labelSmall.copy(
fontWeight = FontWeight.SemiBold,
fontSize = 12.sp,
color = if (isPlaying) LocalGeoColors.current.deepPurple else (if (isError) LocalGeoColors.current.redFavorite else LocalGeoColors.current.onSurfaceVariant)
)
)
}
}
@@ -340,7 +313,7 @@ fun NowPlayingSheet(
AppIcon(
resId = R.drawable.ic_equalizer,
contentDescription = stringResource(R.string.equalizer_content_desc),
tint = if (equalizerEnabled) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurfaceVariant.copy(alpha = 0.5f),
tint = if (audioEffects.equalizerEnabled) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurfaceVariant.copy(alpha = 0.5f),
size = 20.dp
)
}
@@ -425,10 +398,7 @@ fun NowPlayingSheet(
color = if (isFavorite) LocalGeoColors.current.redFavorite else LocalGeoColors.current.outlineVariant,
shape = CircleShape
)
.graphicsLayer {
scaleX = favScale
scaleY = favScale
}
.scale(favScale)
.clickable { onToggleFavorite() }
.testTag("np_favorite_toggle"),
contentAlignment = Alignment.Center
@@ -461,12 +431,34 @@ fun NowPlayingSheet(
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
ExtraPlayerTab.entries.forEach { tab ->
ExtraTabChip(
title = stringResource(tab.titleRes),
isSelected = tab == activeExtraTab,
onClick = { onSelectExtraTab(tab) },
modifier = Modifier.weight(1f)
val isSelected = tab == activeExtraTab
val bg by animateColorAsState(
targetValue = if (isSelected) LocalGeoColors.current.primaryContainer else Color.Transparent,
label = "extra_tab_bg"
)
val textColor by animateColorAsState(
targetValue = if (isSelected) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurfaceVariant,
label = "extra_tab_text"
)
Box(
modifier = Modifier
.weight(1f)
.clip(RoundedCornerShape(10.dp))
.background(bg)
.clickable { onSelectExtraTab(tab) }
.padding(vertical = 8.dp),
contentAlignment = Alignment.Center
) {
Text(
text = stringResource(tab.titleRes),
style = MaterialTheme.typography.labelSmall.copy(
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium,
fontSize = 12.sp,
color = textColor
)
)
}
}
}
@@ -475,7 +467,10 @@ fun NowPlayingSheet(
if (recents.isEmpty()) {
Text(
text = stringResource(R.string.recent_empty),
style = SheetEmptyListStyle,
style = MaterialTheme.typography.bodySmall.copy(
color = LocalGeoColors.current.onSurfaceVariant,
textAlign = TextAlign.Center
),
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp)
@@ -501,7 +496,12 @@ fun NowPlayingSheet(
.clip(RoundedCornerShape(10.dp))
.background(stationTileColor(s))
) {
StationArtwork(s, Modifier.matchParentSize())
Image(
painter = painterResource(id = s.iconResId),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
)
}
Column(modifier = Modifier.weight(1f)) {
@@ -514,14 +514,20 @@ fun NowPlayingSheet(
}
Text(
text = s.name,
style = if (isCur) SheetRowNameAccentStyle else SheetRowNameStyle,
style = MaterialTheme.typography.bodyMedium.copy(
fontWeight = FontWeight.Bold,
color = if (isCur) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurface
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
Text(
text = stationDescription(s),
style = SheetRowDescriptionStyle,
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 11.5.sp,
color = LocalGeoColors.current.onSurfaceVariant
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -543,7 +549,10 @@ fun NowPlayingSheet(
if (similarStations.isEmpty()) {
Text(
text = stringResource(R.string.similar_empty),
style = SheetEmptyListStyle,
style = MaterialTheme.typography.bodySmall.copy(
color = LocalGeoColors.current.onSurfaceVariant,
textAlign = TextAlign.Center
),
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp)
@@ -568,19 +577,30 @@ fun NowPlayingSheet(
.clip(RoundedCornerShape(10.dp))
.background(stationTileColor(s))
) {
StationArtwork(s, Modifier.matchParentSize())
Image(
painter = painterResource(id = s.iconResId),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
)
}
Column(modifier = Modifier.weight(1f)) {
Text(
text = s.name,
style = SheetRowNameAccentStyle,
style = MaterialTheme.typography.bodyMedium.copy(
fontWeight = FontWeight.Bold,
color = LocalGeoColors.current.deepPurple
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = "${stationDescription(s)} • ${stationGenres(s)}",
style = SheetRowDescriptionStyle,
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 11.5.sp,
color = LocalGeoColors.current.onSurfaceVariant
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -630,42 +650,6 @@ fun NowPlayingSheet(
}
}
// A composable of its own, so the color animation recomposes only this chip, not the whole sheet.
@Composable
private fun ExtraTabChip(
title: String,
isSelected: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
val bg by animateColorAsState(
targetValue = if (isSelected) LocalGeoColors.current.primaryContainer else Color.Transparent,
label = "extra_tab_bg"
)
val textColor by animateColorAsState(
targetValue = if (isSelected) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurfaceVariant,
label = "extra_tab_text"
)
Box(
modifier = modifier
.clip(RoundedCornerShape(10.dp))
.background(bg)
.clickable(onClick = onClick)
.padding(vertical = 8.dp),
contentAlignment = Alignment.Center
) {
Text(
text = title,
style = MaterialTheme.typography.labelSmall.copy(
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium,
fontSize = 12.sp,
color = textColor
)
)
}
}
@Composable
private fun InfoRow(key: String, value: String) {
Row(
@@ -675,12 +659,19 @@ private fun InfoRow(key: String, value: String) {
) {
Text(
text = key,
style = InfoKeyStyle
style = MaterialTheme.typography.bodySmall.copy(
fontWeight = FontWeight.SemiBold,
color = LocalGeoColors.current.onSurfaceVariant
)
)
// Long values (descriptions, genre lists) wrap on the right instead of pushing the key out.
Text(
text = value,
style = InfoValueStyle,
style = MaterialTheme.typography.bodySmall.copy(
fontWeight = FontWeight.Bold,
color = LocalGeoColors.current.deepPurple,
textAlign = TextAlign.End
),
modifier = Modifier.weight(1f)
)
}
@@ -28,6 +28,7 @@ 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
@@ -39,6 +40,7 @@ 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
@@ -49,9 +51,8 @@ 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.DarkGeoColors
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
import cc.skysparkle.fogwave.ui.theme.Typography
import coil.compose.AsyncImage
@Composable
fun LiveOnAirDot(modifier: Modifier = Modifier) {
@@ -80,41 +81,6 @@ fun LiveOnAirDot(modifier: Modifier = Modifier) {
private val GridTextShadow = Shadow(color = Color.Black.copy(alpha = 0.55f), blurRadius = 8f)
// Text styles are built once from the app's only palette, not copied on every recomposition.
private val IconsNameStyle = Typography.titleSmall.copy(
fontWeight = FontWeight.Bold,
fontSize = 14.5.sp,
lineHeight = 17.sp,
color = DarkGeoColors.onSurface,
shadow = GridTextShadow
)
private val IconsNameCurrentStyle = IconsNameStyle.copy(color = DarkGeoColors.deepPurple)
private val IconsDescriptionStyle = Typography.bodySmall.copy(
fontSize = 11.5.sp,
color = DarkGeoColors.onSurface.copy(alpha = 0.82f),
shadow = GridTextShadow
)
private val TilesNameStyle = Typography.titleSmall.copy(
fontWeight = FontWeight.Bold,
fontSize = 15.sp,
color = DarkGeoColors.onSurface
)
private val TilesNameCurrentStyle = TilesNameStyle.copy(color = DarkGeoColors.deepPurple)
private val TilesDescriptionStyle = Typography.bodySmall.copy(
fontSize = 12.sp,
color = DarkGeoColors.onSurfaceVariant
)
private val RowNameStyle = Typography.bodyMedium.copy(
fontWeight = FontWeight.Bold,
color = DarkGeoColors.onSurface
)
private val RowNameCurrentStyle = RowNameStyle.copy(color = DarkGeoColors.deepPurple)
private val RowDescriptionStyle = Typography.bodySmall.copy(
fontSize = 11.5.sp,
color = DarkGeoColors.onSurfaceVariant
)
private val RowGenresStyle = RowDescriptionStyle.copy(color = DarkGeoColors.primary)
@Composable
fun StationItem(
station: RadioStation,
@@ -222,7 +188,12 @@ private fun StationIconsCard(
shape = RoundedCornerShape(22.dp)
)
) {
StationLogoImage(station, Modifier.matchParentSize())
AsyncImage(
model = station.iconResId,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
)
}
Spacer(modifier = Modifier.height(8.dp))
@@ -236,7 +207,13 @@ private fun StationIconsCard(
}
Text(
text = station.name,
style = if (isCurrent) IconsNameCurrentStyle else IconsNameStyle,
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
)
@@ -244,7 +221,11 @@ private fun StationIconsCard(
Text(
text = stationDescription(station),
style = IconsDescriptionStyle,
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 11.5.sp,
color = LocalGeoColors.current.onSurface.copy(alpha = 0.82f),
shadow = GridTextShadow
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -289,7 +270,12 @@ private fun StationTilesCard(
.background(stationTileColor(station))
.border(0.8.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(14.dp))
) {
StationLogoImage(station, Modifier.matchParentSize())
AsyncImage(
model = station.iconResId,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
)
}
Column(modifier = Modifier.weight(1f)) {
@@ -302,14 +288,21 @@ private fun StationTilesCard(
}
Text(
text = station.name,
style = if (isCurrent) TilesNameCurrentStyle else TilesNameStyle,
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 = TilesDescriptionStyle,
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 12.sp,
color = LocalGeoColors.current.onSurfaceVariant
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -350,7 +343,12 @@ private fun StationListRow(
.background(stationTileColor(station))
.border(0.8.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(10.dp))
) {
StationLogoImage(station, Modifier.matchParentSize())
AsyncImage(
model = station.iconResId,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
)
}
Column(modifier = Modifier.weight(1f)) {
@@ -363,7 +361,10 @@ private fun StationListRow(
}
Text(
text = station.name,
style = if (isCurrent) RowNameCurrentStyle else RowNameStyle,
style = MaterialTheme.typography.bodyMedium.copy(
fontWeight = FontWeight.Bold,
color = if (isCurrent) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurface
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -410,7 +411,12 @@ private fun StationDetailsRow(
.background(stationTileColor(station))
.border(0.8.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(10.dp))
) {
StationLogoImage(station, Modifier.matchParentSize())
AsyncImage(
model = station.iconResId,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
)
}
Column(modifier = Modifier.weight(1.3f)) {
@@ -423,14 +429,20 @@ private fun StationDetailsRow(
}
Text(
text = station.name,
style = if (isCurrent) RowNameCurrentStyle else RowNameStyle,
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 = RowDescriptionStyle,
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 11.5.sp,
color = LocalGeoColors.current.onSurfaceVariant
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
@@ -438,7 +450,10 @@ private fun StationDetailsRow(
Text(
text = stationGenres(station),
style = RowGenresStyle,
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 11.5.sp,
color = LocalGeoColors.current.primary
),
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(0.9f)
@@ -2,14 +2,9 @@ package cc.skysparkle.fogwave.ui.components
import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import cc.skysparkle.fogwave.data.model.RadioStation
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
import coil.compose.AsyncImage
private val LightLogoBackdrop = Color(0xFFECE8F1)
@@ -18,26 +13,3 @@ private val LightLogoBackdrop = Color(0xFFECE8F1)
@ReadOnlyComposable
fun stationTileColor(station: RadioStation): Color =
if (station.lightBackdrop) LightLogoBackdrop else LocalGeoColors.current.surfaceContainer
// Use the same explicit Android resource URI as the Media3 session metadata. This avoids
// relying on Coil's implicit Int model handling for drawable-nodpi assets, while still letting
// Coil decode at the actual target size (important for the mini player and full-size artwork).
@Composable
fun StationLogoImage(station: RadioStation, modifier: Modifier = Modifier) {
val context = LocalContext.current
val artworkUri = remember(context.packageName, station.iconResId) {
"android.resource://${context.packageName}/${station.iconResId}"
}
AsyncImage(
model = artworkUri,
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = modifier
)
}
@Composable
fun StationArtwork(station: RadioStation, modifier: Modifier = Modifier) {
StationLogoImage(station, modifier)
}
@@ -4,6 +4,7 @@ import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.core.FastOutLinearInEasing
import androidx.compose.animation.core.FastOutSlowInEasing
import androidx.compose.animation.core.Spring
@@ -29,7 +30,6 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.derivedStateOf
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@@ -37,7 +37,7 @@ 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.onSizeChanged
import androidx.compose.ui.layout.onGloballyPositioned
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
@@ -59,15 +59,13 @@ import cc.skysparkle.fogwave.ui.components.StationsToolbar
import cc.skysparkle.fogwave.ui.components.TopBrandBar
import cc.skysparkle.fogwave.ui.viewmodel.RadioViewModel
@OptIn(ExperimentalAnimationApi::class)
@Composable
fun HomeScreen(
viewModel: RadioViewModel = viewModel()
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()
val isPlaying = uiState.playerState is PlayerState.Playing
// Read only inside the sheets below, so moving an equalizer slider recomposes just those.
val audioEffects = viewModel.audioEffects.collectAsStateWithLifecycle()
val equalizerEnabled by remember { derivedStateOf { audioEffects.value.equalizerEnabled } }
val favoriteStations = remember(uiState.stations, uiState.favorites) {
uiState.stations.filter { it.id in uiState.favorites }
@@ -196,8 +194,8 @@ fun HomeScreen(
.align(Alignment.BottomCenter)
.fillMaxWidth()
// Measured before the inset padding so list content clears the system bar too.
.onSizeChanged { size ->
val measured = with(density) { size.height.toDp() }
.onGloballyPositioned { coordinates ->
val measured = with(density) { coordinates.size.height.toDp() }
if (measured > 0.dp && measured != dockHeight) {
dockHeight = measured
}
@@ -246,7 +244,7 @@ fun HomeScreen(
onNext = { viewModel.nextStation() },
onClose = { viewModel.closeNowPlaying() },
onOpenEqualizer = { viewModel.toggleEqualizerPop() },
equalizerEnabled = equalizerEnabled,
audioEffects = uiState.audioEffects,
activeExtraTab = uiState.activeExtraTab,
onSelectExtraTab = { viewModel.setActiveExtraTab(it) },
recents = recentStations,
@@ -273,7 +271,7 @@ fun HomeScreen(
) { it / 3 }
) {
EqualizerSheet(
audioEffects = audioEffects.value,
audioEffects = uiState.audioEffects,
onClose = { viewModel.closeEqualizerPop() },
onSetEqualizerEnabled = { viewModel.setEqualizerEnabled(it) },
onSetEqualizerBand = { band, level -> viewModel.setEqualizerBand(band, level) },
@@ -3,6 +3,7 @@ package cc.skysparkle.fogwave.ui.theme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
private val DarkColorScheme = with(DarkGeoColors) {
darkColorScheme(
@@ -24,8 +25,9 @@ private val DarkColorScheme = with(DarkGeoColors) {
)
}
// LocalGeoColors needs no provider: the dark palette is its default and the only one.
@Composable
fun FogwaveTheme(content: @Composable () -> Unit) {
MaterialTheme(colorScheme = DarkColorScheme, typography = Typography, content = content)
CompositionLocalProvider(LocalGeoColors provides DarkGeoColors) {
MaterialTheme(colorScheme = DarkColorScheme, typography = Typography, content = content)
}
}
@@ -38,6 +38,7 @@ data class RadioUiState(
val isEqualizerPopOpen: Boolean = false,
val isViewPopOpen: Boolean = false,
val activeExtraTab: ExtraPlayerTab = ExtraPlayerTab.RECENT,
val audioEffects: AudioEffectsState = AudioEffectsState(),
val isMiniPlayerHidden: Boolean = false,
val unseenFavoritesCount: Int = 0
)
@@ -76,9 +77,6 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
_showBatteryOptimizationPrompt.value = false
}
// Kept out of uiState: equalizer changes arrive on every slider move and only the sheets need them.
val audioEffects: StateFlow<AudioEffectsState> = AudioEffectsController.state
val uiState: StateFlow<RadioUiState> = combine(
_currentStation,
playerManager.playerState,
@@ -91,6 +89,7 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
_isEqualizerPopOpen,
_isViewPopOpen,
_activeExtraTab,
AudioEffectsController.state,
_isMiniPlayerHidden,
repository.seenFavoritesFlow,
_stations
@@ -108,11 +107,12 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
val eqPop = params[8] as Boolean
val viewPop = params[9] as Boolean
val extraTab = params[10] as ExtraPlayerTab
val miniHidden = params[11] as Boolean
val effects = params[11] as AudioEffectsState
val miniHidden = params[12] as Boolean
@Suppress("UNCHECKED_CAST")
val seenFavs = params[12] as Set<String>
val seenFavs = params[13] as Set<String>
@Suppress("UNCHECKED_CAST")
val orderedStations = params[13] as List<RadioStation>
val orderedStations = params[14] as List<RadioStation>
val byId = orderedStations.associateBy { it.id }
val recentsList = recentsIds.mapNotNull { byId[it] }
@@ -130,6 +130,7 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
isEqualizerPopOpen = eqPop,
isViewPopOpen = viewPop,
activeExtraTab = extraTab,
audioEffects = effects,
isMiniPlayerHidden = miniHidden,
unseenFavoritesCount = favs.count { it !in seenFavs }
)
@@ -142,6 +143,7 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
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 }
)
)
@@ -217,11 +219,12 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
selectStation(list[prevIndex])
}
fun toggleFavorite() {
val stationId = _currentStation.value?.id ?: return
repository.toggleFavorite(stationId)
if (_selectedTab.value == AppTab.FAVORITES) {
repository.markFavoritesSeen()
fun toggleFavorite(stationId: String? = _currentStation.value?.id) {
if (stationId != null) {
repository.toggleFavorite(stationId)
if (_selectedTab.value == AppTab.FAVORITES) {
repository.markFavoritesSeen(repository.favoritesFlow.value)
}
}
}
@@ -260,6 +263,10 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
AudioEffectsController.setLoudnessEnabled(enabled)
}
fun setLoudnessGain(gainMillibel: Float) {
AudioEffectsController.setLoudnessGain(gainMillibel)
}
fun setDynamicsProcessingEnabled(enabled: Boolean) {
AudioEffectsController.setDynamicsProcessingEnabled(enabled)
}
@@ -268,7 +275,7 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
_selectedTab.value = tab
_isViewPopOpen.value = false
if (tab == AppTab.FAVORITES) {
repository.markFavoritesSeen()
repository.markFavoritesSeen(repository.favoritesFlow.value)
}
}