49 Commits
Author SHA1 Message Date
kalarina f6793cf5c0 Release 1.0.18 2026-11-12 16:54:17 +02:00
kalarina 5fd7be69e1 Smaller fixes from the review
- Turn off cloud backup (allowBackup=false); Android 12+ still allows
  device-to-device transfer.
- Strip Log.d/Log.v from release builds.
- Drop Coil (and OkHttp/Okio with it): the backdrop is a local image.
- Pause the home fog while the player covers it and cache its gradients.
- List all 14 broadcasters under Licenses.
- Pin the Gradle 9.7.1 distribution checksum.
- Equalizer units come from string resources (Russian uses дБ/Гц/кГц).
- Play buttons are announced as buttons.
- Remove the unused ic_sleep image and a stale preference cleanup.
2026-11-12 16:43:34 +02:00
kalarina 847aa8daae Add unit tests for the reconnect policy, the player state and the repository 2026-11-12 16:43:34 +02:00
kalarina 8cd9133803 Harden the playback service and make next/previous work outside the app
- Resolve every item from a controller against the station list: an item
  without a URI (voice requests from Assistant or Android Auto) no longer
  crashes the player, and other apps can no longer start arbitrary streams.
- Offer next/previous to the notification, headset buttons and Android Auto
  through a ForwardingSimpleBasePlayer that switches the station; the player
  still holds only the station on air, so no other stream is prepared.
- Do not spend reconnect attempts while offline; reconnect when the network
  comes back instead of pausing for good after about four minutes.
- Swiping the app away during an error or a pending reconnect stops the
  service; a short rebuffer while playing does not.
- Loudness Enhancer applies a 6 dB boost by default; the old default of 0
  made the switch do nothing. The unused gain setter chain is removed.
- Count station switches made outside the app in recents and play counts.
2026-11-12 16:43:34 +02:00
kalarina ac19416c00 Add color styles and a station-colored fog option; compact About with MingCute icons
Styles match Matewave: Fogwave (default), Lavender, Peach, Mint, Sky and
Device (Material You, Android 12+). The fog and the disc ring follow the
style and no longer change with the station unless 'Fog in station color'
is switched on. About now has an Appearance section and grouped link rows.
2026-11-12 16:26:57 +02:00
kalarina 73dd720533 Remove song titles line from README 2026-11-11 10:57:42 +02:00
kalarina 4b2396d20a Update screenshots for the new design 2026-11-10 19:57:20 +02:00
kalarina 15b7c7effc Remove genre cards and the player's back arrow; fill the whole screen with the player on tablets 2026-11-10 19:33:58 +02:00
kalarina 23f577ee89 Release 1.0.17 2026-11-10 19:26:44 +02:00
kalarina f4a855e98e Remove track history tab; fix hard edge of home fog and rows showing under the dock 2026-11-10 17:31:22 +02:00
kalarina 27e11db27f Release 1.0.16 2026-11-10 16:31:26 +02:00
kalarina 5a4752d32d Release 1.0.14 2026-11-10 16:27:39 +02:00
kalarina 42e77433bf Add station-colored fog, misty home backdrop and logo fitting; bring back next in mini player 2026-11-10 16:18:25 +02:00
kalarina 33423fbbc0 Redesign UI: genre cards, search, station disc player and track history 2026-11-10 16:06:36 +02:00
kalarina 36c56ecf35 Expand call for volunteer designers 2026-11-10 15:33:19 +02:00
kalarina 511635a5c8 Add call for volunteer designers to README 2026-11-10 15:30:42 +02:00
kalarina fe77813e53 Move Google Play notice to the top of README 2026-11-08 17:26:04 +02:00
kalarina 13acbc6d6a Add Google Play closed testing notice to README 2026-11-08 17:23:00 +02:00
kalarina 46a3f94057 Escape ampersands in new station strings 2026-11-08 14:10:06 +02:00
kalarina cca6d5e19c Release 1.0.13
- Add LRT Radijas, Žinių radijas, Latvijas Radio 1 and Latvijas Radio 2
- Add HLS playback (media3-exoplayer-hls) for the Latvijas Radio streams
- Add "News & talk" and "Latvian music" genres
- Show the view options button on the Radio tab only; Favorites uses the same layout
- Update descriptions and changelogs

Inspired by https://github.com/JacobBico/fogwave-baltic
2026-11-08 13:50:10 +02:00
kalarina 5561754a71 Release 1.0.13 2026-11-07 16:29:40 +02:00
kalarina f84df8b21e Reconnect the media controller after it disconnects 2026-11-07 16:28:01 +02:00
kalarina 197ac2784c Make stream reconnects reliable and create audio effects off the main thread
- Hold a wake lock and Wi-Fi lock while a reconnect is pending so the backoff
  does not stall with the screen off
- Raise the rebuffer threshold to 2.5 s to stop play-stall stutter on weak networks
- Reconnect at once when the default network changes during a stall
- Give up quickly on errors that will not recover (4xx, unsupported format)
- Build audio effects on a background thread to keep startup smooth
2026-11-07 16:28:01 +02:00
kalarina 237be98cf0 Cache equalizer state instead of querying audioserver on every slider move 2026-11-07 16:28:01 +02:00
kalarina 91e5467d11 Add GitHub issue and pull request templates 2026-11-05 18:44:16 +02:00
kalarina d9b12c9899 Update store and README screenshots 2026-11-03 15:56:01 +02:00
kalarina 9efb12a25f Release 1.0.12 with only the WebP interface icons on top of 1.0.11 2026-11-03 15:36:07 +02:00
kalarina 52af3a7f4c Fix station artwork resource loading in player 2026-11-03 14:45:05 +02:00
kalarina ae47b574c1 Load player artwork the same way as the station list 2026-11-03 14:09:24 +02:00
kalarina 8e815865da Load station logos the way 1.0.11 did 2026-11-03 13:53:36 +02:00
kalarina 50ac9f9886 Decode station logos directly at full size 2026-11-03 13:47:51 +02:00
kalarina fa2fda44d1 Release 1.0.12
- Load preferences and all station logos off the main thread
- Keep equalizer updates and player animations from recomposing whole screens
- Build the Android Auto browse tree once and serve it from memory
- Create only the audio and metadata renderers, ship only the app's languages
- Store interface icons as lossless WebP, drop unused code and dependencies
2026-11-03 12:42:31 +02:00
kalarina 6a819880e2 Use GPL-3.0-only license wording 2026-10-21 14:50:40 +00:00
kalarina 5fe3a0af0b Make star request platform-neutral 2026-10-20 13:01:12 +00:00
kalarina ac64478773 Add star request to README 2026-10-20 12:59:10 +00:00
kalarina 62df72f9b8 Point Obtainium links to Gitea 2026-10-16 11:59:21 +00:00
kalarina 1eae2c8493 Redesign README: store badges, release badge, install options 2026-10-16 11:50:50 +00:00
kalarina 440fbec8e3 Upload files to "assets" 2026-10-16 11:42:48 +00:00
kalarina 61fa65b080 Upload files to "assets" 2026-10-16 11:40:58 +00:00
kalarina 5bd0d96a92 Update store descriptions in six languages 2026-10-13 14:54:45 +00:00
kalarina e4a36b6cfa Remove duplicate account note from CONTRIBUTING 2026-10-12 13:37:27 +00:00
kalarina 4454a422bb Update README 2026-10-12 13:34:09 +00:00
kalarina 2900470e90 Use Gitea as the only contribution channel 2026-10-11 14:10:44 +00:00
kalarina f86d8cc70d Add contributing guide and issue/PR templates 2026-10-11 14:01:06 +00:00
kalarina 6485a51249 Restructure README 2026-10-11 13:46:30 +00:00
kalarina 1b52c5dbab Add minimum Android version to README 2026-10-11 13:41:01 +00:00
kalarina 7482217528 Remove fdroid recipe, state GPL-3.0-only, format key fingerprint
The build recipe now lives in fdroiddata, so the outdated copy in
fdroid/ is removed. README states the license as GPL-3.0-only to
match the F-Droid metadata and shows the signing certificate
fingerprint in colon-separated form.
2026-10-10 15:28:54 +00:00
kalarina e3aa92d346 Remove CHANGELOG.md and verify downloads by signing key
CHANGELOG.md was out of date (stopped at v1.0.10 under the old
Fogwawe name), so it is removed. README now tells users to verify
the APK signing certificate instead of per-file checksums and fixes
the APK file name in the adb example.
2026-10-10 15:17:26 +00:00
kalarinaandClaude Opus 5.5 be11ae190d Store all text files with LF line endings
Adds a catch-all "* text=auto eol=lf" rule so a Windows clone keeps
LF in assets and resources and release APKs built on Windows match
F-Droid's Linux build. Existing rules for gradlew, batch files and
binaries are kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01K8GS1YNyjzkkhpGz368nGD
2026-10-10 14:04:07 +00:00
175 changed files with 3544 additions and 2272 deletions
+1
View File
@@ -1,3 +1,4 @@
* text=auto eol=lf
gradlew text eol=lf
*.bat text eol=crlf
*.jar binary
+27
View File
@@ -0,0 +1,27 @@
---
name: Bug report
about: Something doesn't work as expected
title: "[Bug] "
---
**What happened**
**Steps to reproduce**
1.
2.
3.
**What you expected**
**Environment**
- App version:
- Installed from: Gitea / F-Droid / Google Play
- Device and Android version:
- Station (if related):
**Screenshots or logs** (optional)
+18
View File
@@ -0,0 +1,18 @@
---
name: Feature request
about: Suggest an idea that fits the app
title: "[Feature] "
---
<!-- Please check the "Out of scope" list in CONTRIBUTING.md before opening this. -->
**What problem does this solve**
**Proposed solution**
**Alternatives you considered**
- [ ] I'd like to implement this myself
+15
View File
@@ -0,0 +1,15 @@
---
name: Station request
about: Suggest a Lithuanian radio station
title: "[Station] "
---
<!-- Only Lithuanian stations with an official public stream are accepted. -->
- Station name:
- Official website:
- Stream URL:
- Genre:
- [ ] The station is Lithuanian
- [ ] The stream is official and public
+12
View File
@@ -0,0 +1,12 @@
---
name: Translation fix
about: Report a wrong or awkward translation
title: "[Translation] "
---
<!-- Supported languages: English, Russian, German, Japanese, Lithuanian, Chinese. New languages are not accepted. -->
- Language:
- Screen or place in the app:
- Current text:
- Suggested text:
+16
View File
@@ -0,0 +1,16 @@
## What does this change
## Related issue
Closes #
## Checklist
- [ ] Discussed in an issue first (not needed for small fixes)
- [ ] `./gradlew assembleDebug` builds
- [ ] Tested on a device or emulator (Android version: )
- [ ] No ads, analytics, trackers or Google Play Services / Firebase dependencies
- [ ] New strings added to `values/strings.xml` (missing translations noted below)
- [ ] Screenshots added for UI changes
- [ ] I agree that my contribution is licensed under GPL-3.0-only
+27
View File
@@ -0,0 +1,27 @@
---
name: Bug report
about: Something doesn't work as expected
title: "[Bug] "
---
**What happened**
**Steps to reproduce**
1.
2.
3.
**What you expected**
**Environment**
- App version:
- Installed from: Gitea / GitHub / F-Droid / Google Play
- Device and Android version:
- Station (if related):
**Screenshots or logs** (optional)
+5
View File
@@ -0,0 +1,5 @@
blank_issues_enabled: true
contact_links:
- name: Main repository on git.skysparkle.cc
url: https://git.skysparkle.cc/kalarina/Fogwave
about: This GitHub repository is a mirror. Issues are welcome here and on Gitea.
+18
View File
@@ -0,0 +1,18 @@
---
name: Feature request
about: Suggest an idea that fits the app
title: "[Feature] "
---
<!-- Please check the "Out of scope" list in CONTRIBUTING.md before opening this. -->
**What problem does this solve**
**Proposed solution**
**Alternatives you considered**
- [ ] I'd like to implement this myself
+15
View File
@@ -0,0 +1,15 @@
---
name: Station request
about: Suggest a Lithuanian radio station
title: "[Station] "
---
<!-- Only Lithuanian stations with an official public stream are accepted. -->
- Station name:
- Official website:
- Stream URL:
- Genre:
- [ ] The station is Lithuanian
- [ ] The stream is official and public
+12
View File
@@ -0,0 +1,12 @@
---
name: Translation fix
about: Report a wrong or awkward translation
title: "[Translation] "
---
<!-- Supported languages: English, Russian, German, Japanese, Lithuanian, Chinese. New languages are not accepted. -->
- Language:
- Screen or place in the app:
- Current text:
- Suggested text:
+16
View File
@@ -0,0 +1,16 @@
## What does this change
## Related issue
Closes #
## Checklist
- [ ] Discussed in an issue first (not needed for small fixes)
- [ ] `./gradlew assembleDebug` builds
- [ ] Tested on a device or emulator (Android version: )
- [ ] No ads, analytics, trackers or Google Play Services / Firebase dependencies
- [ ] New strings added to `values/strings.xml` (missing translations noted below)
- [ ] Screenshots added for UI changes
- [ ] I agree that my contribution is licensed under GPL-3.0-only
-17
View File
@@ -1,17 +0,0 @@
# Changelog
All notable builds of Fogwave are tracked here. None of these builds have a recoverable build timestamp (reproducible Android builds normalize internal file dates), so versions are numbered in the order they were provided; `v1.0.10` is the current, official latest build.
| Version | APK | Size | SHA-256 |
|---|---|---|---|
| v1.0.10 | [`Fogwawe-v1.0.10.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.10/Fogwawe-v1.0.10.apk) | 2.90 MB | `0e5d8daa71b3b3224192e8d8fc9687bcf4d28c62269c698d0921a2c9a44ed89d` |
| v1.0.9 | [`Fogwawe-v1.0.9.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.9/Fogwawe-v1.0.9.apk) | 2.85 MB | `dc0e96e13a322b702d673e1c1a0a44c5db6fbb7ac49de69fe60a48d3005fad9b` |
| v1.0.8 | [`Fogwawe-v1.0.8.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.8/Fogwawe-v1.0.8.apk) | 2.85 MB | `1baca54152ae1fc46f6b6894f798f3eff3f122fdadb22b22a604c90ae457c840` |
| v1.0.7 | [`Fogwawe-v1.0.7.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.7/Fogwawe-v1.0.7.apk) | 4.09 MB | `8f6dea613968f3c11bc8ea345b2fc62c79d34fc14129bec2757a00065b17f545` |
| v1.0.6 | [`Fogwawe-v1.0.6.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.6/Fogwawe-v1.0.6.apk) | 17.62 MB | `f1fd8479d9996bace2ca91c134ce4a0b835ba76ce69fddad4a3a440a7c137812` |
| v1.0.5 | [`Fogwawe-v1.0.5.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.5/Fogwawe-v1.0.5.apk) | 2.60 MB | `b3a567c32f3090e7ab91990ef0adf77d5c478cd136814092c81ca93cb044e47c` |
| v1.0.4 | [`Fogwawe-v1.0.4.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.4/Fogwawe-v1.0.4.apk) | 2.58 MB | `267c6c86bfa2ec521ab9a926bd3dbf97e69c8591e6d0548e9d59c6278ab8c77d` |
| v1.0.3 | [`Fogwawe-v1.0.3.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.3/Fogwawe-v1.0.3.apk) | 2.60 MB | `a011d962890a25f173593d0920b02ffa8ead38853c7dc8102c7eb976f7248461` |
| v1.0.2 | [`Fogwawe-v1.0.2.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.2/Fogwawe-v1.0.2.apk) | 2.60 MB | `152b09794e235e81d3421a0f20437d01608c776b180442cdaf57cd958c60c0b3` |
| v1.0.1 | [`Fogwawe-v1.0.1.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.1/Fogwawe-v1.0.1.apk) | 2.85 MB | `964979e2f60f7f5369f57c5b5d636563f9be0bae0128bbe318a00eaac8ea13c7` |
| v1.0.0 | [`Fogwawe-v1.0.0.apk`](https://github.com/kalarina-bit/Fogwave/releases/download/v1.0.0/Fogwawe-v1.0.0.apk) | 2.83 MB | `9a3fc4a45326315303f636535d9e88790bf72d244a5ffc54648c1b8d1132616d` |
+65
View File
@@ -0,0 +1,65 @@
# Contributing to Fogwave
Thanks for wanting to help! This guide explains where to contribute, what fits the project and how to send changes.
## Where to contribute
Issues and pull requests go to the repository on [Gitea](https://git.skysparkle.cc/kalarina/Fogwave).
## Ways to help
- **Report a bug** — use the *Bug report* template.
- **Suggest a station** — use the *Station request* template.
- **Suggest a feature** — use the *Feature request* template; check [Out of scope](#out-of-scope) first.
- **Fix a translation** — use the *Translation fix* template or send a pull request.
- **Write code** — see [Pull requests](#pull-requests).
## Before you start
- **Small changes** (typos, obvious bugs, translation fixes): send a pull request directly.
- **Anything bigger** (new features, UI changes, new dependencies): open an issue first and wait for a go-ahead, so your work isn't wasted.
## Ground rules
- No ads, analytics, trackers, crash reporters or accounts.
- No Google Play Services, Firebase or other proprietary libraries — the app must stay buildable for F-Droid.
- New dependencies must be open source and justified in the pull request.
- Be respectful in issues and reviews.
## Out of scope
These will not be accepted:
- Stations from outside Lithuania.
- A light theme or automatic light/dark switching — Fogwave is dark only.
- New UI languages (see [Translations](#translations)).
## Stations
A new station must be Lithuanian, have an official public stream (HTTP or HTTPS) and allow playback in third-party players. Include the official website and stream URL in the request.
## Translations
Fogwave is available in exactly six languages: English, Russian, German, Japanese, Lithuanian and Chinese. Fixes to these are welcome; new languages are not accepted.
- App strings: `app/src/main/res/values-<lang>/strings.xml` (English is `values/`).
- Store listing: `fastlane/metadata/android/<locale>/`.
If your code adds new strings, add them to `values/strings.xml`. Translations for the other languages are welcome but not required — mention missing ones in the pull request.
## Pull requests
1. Fork the repository and create a branch from `main`.
2. Keep one topic per pull request.
3. Follow the existing Kotlin and Jetpack Compose style; keep comments short and in English; don't reformat unrelated code.
4. Make sure `./gradlew assembleDebug` builds, and test on a device or emulator.
5. Write short, plain commit messages in English (for example `Fix crash when stream URL is empty`).
6. Add screenshots for UI changes.
## Security
Please don't post details of security issues publicly. Open a short issue titled "Security contact" without any details, and the maintainer will reach out privately.
## License
By contributing, you agree that your contribution is licensed under the [GNU General Public License v3.0 only](LICENSE), the same as the rest of the project.
+1 -2
View File
@@ -636,8 +636,7 @@ the "copyright" line and a pointer to where the full notice is found.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
the Free Software Foundation, version 3 of the License.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
+54 -58
View File
@@ -1,99 +1,95 @@
<p align="center">
<img src="assets/icon-rounded.png" width="128" alt="Fogwave icon">
<img src="assets/icon-rounded.png" width="112" alt="Fogwave icon">
</p>
<h1 align="center">Fogwave</h1>
<p align="center">
<a href="https://git.skysparkle.cc/kalarina/Fogwave/releases"><img src="assets/get-it-on-gitea.png" height="60" alt="Get it on Gitea"></a>
<b>A calm, open-source internet radio app for Android.</b><br>
Listen to Lithuania's favorite stations in one tap.
</p>
> [!IMPORTANT]
> **Fogwave is coming to Google Play!** The app is now in closed testing there ahead of the public release. Ideas, wishes and suggestions for improvement are very welcome — send them wherever is easiest for you: an issue on [Gitea](https://git.skysparkle.cc/kalarina/Fogwave/issues) or [GitHub](https://github.com/kalarina-bit/Fogwave/issues), or an email to [cuken107@proton.me](mailto:cuken107@proton.me).
> [!NOTE]
> **Looking for designers!** Fogwave is looking for volunteer designers to help with icons, logos, animations, cover art (store graphics) and UI design. This is unpaid help for an open-source project. If you're interested, write to [cuken107@proton.me](mailto:cuken107@proton.me).
<p align="center">
<a href="https://github.com/kalarina-bit/Fogwave/releases/latest"><img src="https://img.shields.io/github/v/release/kalarina-bit/Fogwave?style=for-the-badge&label=release&labelColor=1b1b1b&color=2e7d32" alt="Latest release"></a>
</p>
<p align="center">
<img src="https://img.shields.io/github/downloads/kalarina-bit/Fogwave/latest/total?label=downloads&color=2e7d32&labelColor=1b1b1b" alt="downloads counter">
<a href="https://f-droid.org/packages/cc.skysparkle.fogwave/"><img src="assets/get-it-on%20(1).png" height="56" alt="Get it on F-Droid"></a>
<a href="https://apps.obtainium.imranr.dev/redirect?r=obtainium://add/https://git.skysparkle.cc/kalarina/Fogwave"><img src="assets/badge_obtainium.png" height="56" alt="Get it on Obtainium"></a>
<a href="https://github.com/kalarina-bit/Fogwave/releases/latest"><img src="assets/get-it-on-github.png" height="56" alt="Get it on GitHub"></a>
<a href="https://git.skysparkle.cc/kalarina/Fogwave/releases"><img src="assets/get-it-on-gitea.png" height="56" alt="Get it on Gitea"></a>
</p>
**A calm, open-source internet radio app for Android.**
<p align="center">
<img src="assets/screenshots/1-lithuanian-radio-left.png" width="160" alt="Lithuanian radio, live"><img src="assets/screenshots/2-lithuanian-radio-right.png" width="160" alt="Station list">
<img src="assets/screenshots/3-favorites.png" width="160" alt="Save your favorites">
<img src="assets/screenshots/4-listen-live.png" width="160" alt="Listen live">
</p>
Listen to Lithuania's favorite stations in one tap — with background playback, a built-in equalizer, and a clean, distraction-free design.
> [!TIP]
> If you find Fogwave useful, please consider giving it a ⭐ — it helps others discover the project.
## Features
## ✨ Features
- 📻 **10 Lithuanian stations** — ZIP FM, Power Hit Radio, Rock FM, Relax FM, M-1, Gold FM and more
- 📻 **14 stations from Lithuania and Latvia** — ZIP FM, Power Hit Radio, Rock FM, LRT Radijas, Žinių radijas, Latvijas Radio 1 & 2 and more
- 🎧 **Background playback** with lock-screen, notification, headphone and Bluetooth controls
- 🚗 **Android Auto** support
- 🔄 **Auto-reconnect** when the stream drops or the network comes back
- 🎚️ **Equalizer** with presets, loudness boost and dynamics processing — settings are saved
- 🎚️ **Equalizer** with presets, loudness boost and dynamics processing
- ❤️ **Favorites, recently played and similar stations** matched by genre
- 🗂️ **Four layouts** — list, table, tiles or icons, with adjustable size
- 🌙 **Clean, elegant UI** in a dark theme
- 🌍 Available in English, Russian, German, Japanese, Lithuanian, and Chinese
- 🔓 **100% open source** — no ads, no tracking, no accounts
- 🔍 **Search** to find a station in a tap
- 🌙 **Dark theme**
- 🌍 **Six languages** — English, Russian, German, Japanese, Lithuanian and Chinese
- 🔓 **No ads, no tracking, no accounts**
## Screenshots
## <img src="assets/icon-install.png" width="32" alt=""> Installation
<p align="center">
<img src="assets/screenshots/5-feel-closer.png" width="200" alt="Feel closer to Lithuania">
<img src="assets/screenshots/4-stations.png" width="200" alt="Browse all stations">
<img src="assets/screenshots/1-find-station.png" width="200" alt="Find a station, then settle in">
<img src="assets/screenshots/2-your-style.png" width="200" alt="Just your style">
<img src="assets/screenshots/3-soundtrack.png" width="200" alt="Your soundtrack">
</p>
- **[F-Droid](https://f-droid.org/packages/cc.skysparkle.fogwave/)** — install and update through the F-Droid client.
- **[Obtainium](https://apps.obtainium.imranr.dev/redirect?r=obtainium://add/https://git.skysparkle.cc/kalarina/Fogwave)** — installs the APK straight from Gitea releases and keeps it up to date.
- **Manually** — download the latest APK from [GitHub](https://github.com/kalarina-bit/Fogwave/releases/latest) or [Gitea](https://git.skysparkle.cc/kalarina/Fogwave/releases), allow installs from unknown sources for the app you open it with (Settings → Apps → Special access → Install unknown apps), then open the `.apk` and confirm.
## Installation
## <img src="assets/icon-verify.png" width="32" alt=""> Verifying a download
<img src="assets/icon-install.png" width="36" align="left">
1. Download the APK for the version you want from the [Releases page](https://github.com/kalarina-bit/Fogwave/releases).
2. On your Android device, allow installs from unknown sources for the app you use to open the file (Settings → Apps → Special access → Install unknown apps).
3. Open the downloaded `.apk` file and confirm the install.
Or via `adb` (after downloading):
Every official APK is signed with the same key. Check it before installing:
```sh
adb install Fogwawe-v1.0.10.apk
apksigner verify --print-certs Fogwave-v<version>.apk
```
## Verifying a download
The SHA-256 fingerprint of the signing certificate must be:
<img src="assets/icon-verify.png" width="36" align="left">
Compare the SHA-256 checksum against the value listed in [CHANGELOG.md](CHANGELOG.md):
```sh
sha256sum Fogwawe-v1.0.10.apk
```
1A:85:AF:5A:08:23:DE:D1:76:7C:07:55:41:FA:15:87:7F:6E:3B:99:9E:5E:52:CF:2B:C8:03:55:F6:63:12:7F
```
## Building from source
`apksigner` prints the same value in lowercase without colons. On Android you can check it with [AppVerifier](https://github.com/soupslurpr/AppVerifier) (app ID `cc.skysparkle.fogwave`).
Requires JDK 17+ and Android Studio with Android SDK 37.
## <img src="assets/icon-structure.png" width="32" alt=""> Building from source
Requires JDK 17+ and Android SDK 37.
```sh
./gradlew assembleDebug
```
Release builds are signed only when a keystore is supplied through the `KEYSTORE_PATH`, `STORE_PASSWORD`, `KEY_ALIAS` and `KEY_PASSWORD` environment variables. Without them the release build is unsigned, which is what F-Droid expects. Keystores are excluded by `.gitignore` — never commit them.
Release builds are signed only when a keystore is supplied through the `KEYSTORE_PATH`, `STORE_PASSWORD`, `KEY_ALIAS` and `KEY_PASSWORD` environment variables; otherwise the release build is unsigned, as F-Droid expects. Never commit keystores.
For every release: bump `versionCode` and `versionName` in `app/build.gradle.kts`, add `fastlane/metadata/android/<locale>/changelogs/<versionCode>.txt`, and tag the commit as `v<versionName>` (for example `v1.0.11`).
### Releasing
## Repository structure
1. Bump `versionCode` and `versionName` in `app/build.gradle.kts`.
2. Add `fastlane/metadata/android/<locale>/changelogs/<versionCode>.txt`.
3. Tag the commit as `v<versionName>` (for example `v1.0.11`).
<img src="assets/icon-structure.png" width="36" align="left">
## 🤝 Contributing
```
.
├── app/ # Android app source (Kotlin, Jetpack Compose)
├── assets/ # README images and logos
│ └── screenshots/ # App screenshots
├── fastlane/ # F-Droid store listing, screenshots and changelogs
├── fdroid/ # Build recipe for fdroiddata
├── gradle/ # Gradle wrapper and version catalog
├── CHANGELOG.md # Per-version sizes and checksums (links to GitHub Releases)
├── LICENSE # GNU GPLv3
└── README.md
```
Bug reports, station suggestions, translation fixes and pull requests are welcome in the [issue tracker](https://git.skysparkle.cc/kalarina/Fogwave/issues). Please read [CONTRIBUTING.md](CONTRIBUTING.md) first — it explains what fits the project and how to send changes. To open an issue or a pull request, [create an account](https://git.skysparkle.cc/user/sign_up) on this Gitea.
APK builds themselves are published as assets on the [Releases page](https://github.com/kalarina-bit/Fogwave/releases), not stored in this repository.
## 📄 License
## License
This project is licensed under the **GNU General Public License v3.0** — see the [LICENSE](LICENSE) file for details.
[GNU General Public License v3.0 only](LICENSE).
+3 -4
View File
@@ -13,8 +13,8 @@ android {
applicationId = "cc.skysparkle.fogwave"
minSdk = 24
targetSdk = 36
versionCode = 11
versionName = "1.0.11"
versionCode = 18
versionName = "1.0.18"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
@@ -27,7 +27,6 @@ android {
buildConfigField("String", "MEDIA3_VERSION", "\"${libs.versions.media3.get()}\"")
buildConfigField("String", "COROUTINES_VERSION", "\"${libs.versions.kotlinxCoroutinesAndroid.get()}\"")
buildConfigField("String", "KOTLIN_VERSION", "\"${libs.versions.kotlin.get()}\"")
buildConfigField("String", "COIL_VERSION", "\"${libs.versions.coilCompose.get()}\"")
}
// Release signing is applied only when a keystore is available, so anyone (including F-Droid,
@@ -83,8 +82,8 @@ dependencies {
implementation(libs.androidx.lifecycle.runtime.compose)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.coil.compose)
implementation(libs.androidx.media3.exoplayer)
implementation(libs.androidx.media3.exoplayer.hls)
implementation(libs.androidx.media3.common)
implementation(libs.androidx.media3.session)
implementation(libs.kotlinx.coroutines.android)
+6
View File
@@ -1,2 +1,8 @@
-keepattributes SourceFile,LineNumberTable
-renamesourcefileattribute SourceFile
# Debug and verbose logging is stripped from release builds.
-assumenosideeffects class android.util.Log {
public static int d(...);
public static int v(...);
}
+1 -4
View File
@@ -8,10 +8,7 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />
<application
android:name=".FogwaveApp"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:allowBackup="false"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:localeConfig="@xml/locales_config"
@@ -1,20 +0,0 @@
package cc.skysparkle.fogwave
import android.app.Application
import coil.ImageLoader
import coil.ImageLoaderFactory
import coil.memory.MemoryCache
class FogwaveApp : Application(), ImageLoaderFactory {
override fun newImageLoader(): ImageLoader {
return ImageLoader.Builder(this)
.memoryCache {
MemoryCache.Builder(this)
.maxSizePercent(0.20)
.build()
}
.crossfade(true)
.respectCacheHeaders(false)
.build()
}
}
@@ -11,11 +11,13 @@ import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import cc.skysparkle.fogwave.ui.screens.HomeScreen
import cc.skysparkle.fogwave.ui.theme.AppThemeState
import cc.skysparkle.fogwave.ui.theme.FogwaveTheme
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
AppThemeState.load(this)
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.dark(Color.TRANSPARENT),
navigationBarStyle = SystemBarStyle.dark(Color.TRANSPARENT)
@@ -24,21 +24,9 @@ enum class Genre(@param:StringRes val labelRes: Int) {
OLDIES(R.string.genre_oldies),
ROCK(R.string.genre_rock),
EASY_LISTENING(R.string.genre_easy_listening),
LITHUANIAN(R.string.genre_lithuanian)
}
enum class ViewMode {
ICONS,
TILES,
LIST,
DETAILS
}
enum class IconSizeStep(val sizeDp: Int) {
S(64),
M(96),
L(132),
XL(176)
LITHUANIAN(R.string.genre_lithuanian),
NEWS_TALK(R.string.genre_news_talk),
LATVIAN(R.string.genre_latvian)
}
enum class AppTab(@param:StringRes val titleRes: Int) {
@@ -52,3 +40,4 @@ enum class ExtraPlayerTab(@param:StringRes val titleRes: Int) {
SIMILAR(R.string.extra_tab_similar),
INFO(R.string.extra_tab_info)
}
@@ -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
@@ -110,6 +108,43 @@ class RadioRepository(context: Context) {
genres = listOf(Genre.HITS, Genre.LITHUANIAN),
bitrate = "MP3 128 kbps",
lightBackdrop = true
),
RadioStation(
id = "lrt",
name = "LRT Radijas",
descriptionRes = R.string.station_desc_lrt,
streamUrl = "https://lrt-cast.lrt.lt/lrt_radijas",
iconResId = R.drawable.ic_station_lrt,
genres = listOf(Genre.NEWS_TALK, Genre.LITHUANIAN),
bitrate = "MP3",
lightBackdrop = true
),
RadioStation(
id = "ziniu",
name = "Žinių radijas",
descriptionRes = R.string.station_desc_ziniu,
streamUrl = "https://netradio.ziniur.lt/ziniur.mp3?n=975355",
iconResId = R.drawable.ic_station_ziniu,
genres = listOf(Genre.NEWS_TALK),
bitrate = "MP3"
),
RadioStation(
id = "lr1",
name = "Latvijas Radio 1",
descriptionRes = R.string.station_desc_lr1,
streamUrl = "https://muste.latvijasradio.lv/shoutcast/mp4:lr1a.stream/playlist.m3u8",
iconResId = R.drawable.ic_station_lr1,
genres = listOf(Genre.NEWS_TALK),
bitrate = "HLS"
),
RadioStation(
id = "lr2",
name = "Latvijas Radio 2",
descriptionRes = R.string.station_desc_lr2,
streamUrl = "https://muste.latvijasradio.lv/shoutcast/mp4:lr2a.stream/playlist.m3u8",
iconResId = R.drawable.ic_station_lr2,
genres = listOf(Genre.LATVIAN, Genre.POP),
bitrate = "HLS"
)
)
@@ -121,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()
@@ -138,7 +167,7 @@ class RadioRepository(context: Context) {
fun markFavoritesSeen(ids: Set<String>) {
val copy = ids.toSet()
_seenFavoritesFlow.value = copy
prefs.edit { putStringSet("seen_favorites", copy); remove("last_seen_favorites_count") }
prefs.edit { putStringSet("seen_favorites", copy) }
}
fun getLastStationId(): String? {
@@ -225,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)
}
@@ -42,11 +42,6 @@ object AudioEffectsController {
refresh()
}
fun setLoudnessGain(gainMillibel: Float) {
engine?.setLoudnessGain(gainMillibel)
refresh()
}
fun setDynamicsProcessingEnabled(enabled: Boolean) {
engine?.setDynamicsProcessingEnabled(enabled)
refresh()
@@ -25,12 +25,12 @@ data class AudioEffectsState(
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
)
// Effect parameters are cached here: every getter on an AudioEffect is a call into audioserver,
// and the state is rebuilt on every frame while an equalizer slider is dragged.
class AudioEffectsEngine(context: Context, audioSessionId: Int) {
private val prefs: SharedPreferences =
context.applicationContext.getSharedPreferences("fogwave_audio_effects", Context.MODE_PRIVATE)
@@ -42,37 +42,56 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
private var loudnessEnhancer: LoudnessEnhancer? = null
private var dynamicsProcessing: DynamicsProcessing? = null
private val presetNames = mutableListOf<String>()
private var presetNames: List<String> = emptyList()
private var centerFreqsHz = IntArray(0)
private var bandLevels = IntArray(0)
private var minBandLevel = 0
private var maxBandLevel = 0
private var equalizerEnabled = prefs.getBoolean(KEY_EQ_ENABLED, false)
private var loudnessEnabled = prefs.getBoolean(KEY_LOUDNESS_ENABLED, false)
// There is no gain slider, so the switch applies a fixed, moderate boost. A gain of 0 (the old
// default) made the switch do nothing.
private val loudnessGain = prefs.getInt(KEY_LOUDNESS_GAIN, DEFAULT_LOUDNESS_GAIN)
.takeIf { it > 0 }?.coerceAtMost(MAX_LOUDNESS_GAIN) ?: DEFAULT_LOUDNESS_GAIN
private var dynamicsEnabled = prefs.getBoolean(KEY_DYNAMICS_ENABLED, false)
init {
try {
equalizer = Equalizer(0, audioSessionId).apply {
for (p in 0 until numberOfPresets) {
presetNames.add(getPresetName(p.toShort()))
}
presetNames = (0 until numberOfPresets).map { getPresetName(it.toShort()) }
val bandCount = numberOfBands.toInt()
centerFreqsHz = IntArray(bandCount) { getCenterFreq(it.toShort()) / 1000 }
val range = bandLevelRange
minBandLevel = range[0].toInt()
maxBandLevel = range[1].toInt()
val preset = currentPresetIndex
if (preset in 0 until numberOfPresets) {
usePreset(preset.toShort())
} else {
for (b in 0 until numberOfBands) {
for (b in 0 until bandCount) {
val saved = prefs.getInt(KEY_BAND_PREFIX + b, Int.MIN_VALUE)
if (saved != Int.MIN_VALUE) setBandLevel(b.toShort(), saved.toShort())
}
}
enabled = prefs.getBoolean(KEY_EQ_ENABLED, false)
bandLevels = IntArray(bandCount) { getBandLevel(it.toShort()).toInt() }
enabled = equalizerEnabled
}
} catch (e: Exception) {
Log.e(TAG, "Equalizer unavailable", e)
equalizer = null
}
try {
loudnessEnhancer = LoudnessEnhancer(audioSessionId).apply {
setTargetGain(prefs.getInt(KEY_LOUDNESS_GAIN, 0))
enabled = prefs.getBoolean(KEY_LOUDNESS_ENABLED, false)
setTargetGain(loudnessGain)
enabled = loudnessEnabled
}
} catch (e: Exception) {
Log.e(TAG, "LoudnessEnhancer unavailable", e)
loudnessEnhancer = null
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
@@ -134,94 +153,91 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
dp.setLimiterByChannelIndex(ch, limiter)
}
dp.enabled = prefs.getBoolean(KEY_DYNAMICS_ENABLED, false)
dp.enabled = dynamicsEnabled
return dp
}
fun currentState(): AudioEffectsState {
val eq = equalizer
val bands = if (eq != null) {
(0 until eq.numberOfBands).map { i ->
val idx = i.toShort()
val range = eq.bandLevelRange
val eqAvailable = equalizer != null
val bands = if (eqAvailable) {
bandLevels.indices.map { i ->
EqualizerBand(
index = i,
centerFreqHz = eq.getCenterFreq(idx) / 1000,
levelMillibel = eq.getBandLevel(idx).toInt(),
minLevelMillibel = range[0].toInt(),
maxLevelMillibel = range[1].toInt()
centerFreqHz = centerFreqsHz[i],
levelMillibel = bandLevels[i],
minLevelMillibel = minBandLevel,
maxLevelMillibel = maxBandLevel
)
}
} else emptyList()
return AudioEffectsState(
equalizerAvailable = eq != null,
equalizerEnabled = eq?.enabled ?: false,
equalizerAvailable = eqAvailable,
equalizerEnabled = eqAvailable && equalizerEnabled,
bands = bands,
presets = presetNames,
currentPreset = if (eq != null) currentPresetIndex else -1,
currentPreset = if (eqAvailable) currentPresetIndex else -1,
loudnessAvailable = loudnessEnhancer != null,
loudnessEnabled = loudnessEnhancer?.enabled ?: false,
loudnessGainMillibel = try {
loudnessEnhancer?.targetGain ?: 0f
} catch (_: Exception) {
0f
},
loudnessEnabled = loudnessEnhancer != null && loudnessEnabled,
dynamicsProcessingAvailable = dynamicsProcessing != null,
dynamicsProcessingEnabled = dynamicsProcessing?.enabled ?: false
dynamicsProcessingEnabled = dynamicsProcessing != null && dynamicsEnabled
)
}
fun setEqualizerEnabled(enabled: Boolean) {
val eq = equalizer ?: return
try {
equalizer?.enabled = enabled
eq.enabled = enabled
equalizerEnabled = enabled
prefs.edit { putBoolean(KEY_EQ_ENABLED, enabled) }
} catch (_: Exception) {}
}
fun setBandLevel(band: Int, levelMillibel: Int) {
val eq = equalizer ?: return
if (band !in bandLevels.indices) return
val level = levelMillibel.coerceIn(minBandLevel, maxBandLevel)
if (bandLevels[band] == level && currentPresetIndex == -1) return
try {
equalizer?.setBandLevel(band.toShort(), levelMillibel.toShort())
eq.setBandLevel(band.toShort(), level.toShort())
bandLevels[band] = level
currentPresetIndex = -1
prefs.edit {
putInt(KEY_BAND_PREFIX + band, levelMillibel)
putInt(KEY_BAND_PREFIX + band, level)
putInt(KEY_PRESET, -1)
}
} catch (_: Exception) {}
}
fun setPreset(preset: Int) {
try {
val eq = equalizer ?: return
try {
eq.usePreset(preset.toShort())
currentPresetIndex = preset
for (b in bandLevels.indices) {
bandLevels[b] = eq.getBandLevel(b.toShort()).toInt()
}
prefs.edit {
putInt(KEY_PRESET, preset)
for (b in 0 until eq.numberOfBands) {
putInt(KEY_BAND_PREFIX + b, eq.getBandLevel(b.toShort()).toInt())
}
for (b in bandLevels.indices) putInt(KEY_BAND_PREFIX + b, bandLevels[b])
}
} catch (_: Exception) {}
}
fun setLoudnessEnabled(enabled: Boolean) {
val le = loudnessEnhancer ?: return
try {
loudnessEnhancer?.enabled = enabled
le.enabled = enabled
loudnessEnabled = enabled
prefs.edit { putBoolean(KEY_LOUDNESS_ENABLED, enabled) }
} 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) {
val dp = dynamicsProcessing ?: return
try {
dynamicsProcessing?.enabled = enabled
dp.enabled = enabled
dynamicsEnabled = enabled
prefs.edit { putBoolean(KEY_DYNAMICS_ENABLED, enabled) }
} catch (_: Exception) {}
}
@@ -237,6 +253,8 @@ class AudioEffectsEngine(context: Context, audioSessionId: Int) {
private companion object {
const val TAG = "AudioEffectsEngine"
const val MAX_LOUDNESS_GAIN = 2000
const val DEFAULT_LOUDNESS_GAIN = 600
const val KEY_EQ_ENABLED = "eq_enabled"
const val KEY_PRESET = "eq_preset"
const val KEY_BAND_PREFIX = "eq_band_"
@@ -6,11 +6,16 @@ import android.content.Intent
import android.media.AudioManager
import android.net.ConnectivityManager
import android.net.Network
import android.net.wifi.WifiManager
import android.os.Handler
import android.os.Looper
import android.os.PowerManager
import android.os.SystemClock
import android.util.Log
import androidx.annotation.OptIn
import androidx.media3.common.AudioAttributes
import androidx.media3.common.C
import androidx.media3.common.ForwardingSimpleBasePlayer
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import androidx.media3.common.PlaybackException
@@ -28,6 +33,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.model.RadioStation
import cc.skysparkle.fogwave.data.repository.RadioRepository
import com.google.common.collect.ImmutableList
import com.google.common.util.concurrent.Futures
@@ -45,6 +51,10 @@ class FogwavePlaybackService : MediaLibraryService() {
private var mediaLibrarySession: MediaLibrarySession? = null
private lateinit var repository: RadioRepository
private lateinit var player: ExoPlayer
// Station order for next/previous from the notification, a headset or the car; sorted once,
// like the grid in the app.
private var stationOrder: List<RadioStation> = emptyList()
private var audioEffectsEngine: AudioEffectsEngine? = null
private val serviceScope = CoroutineScope(Dispatchers.Main.immediate + SupervisorJob())
@@ -60,6 +70,20 @@ class FogwavePlaybackService : MediaLibraryService() {
private var connectivityManager: ConnectivityManager? = null
private var networkCallback: ConnectivityManager.NetworkCallback? = null
private var defaultNetwork: Network? = null
private var hasNetwork = true
// Set when a reconnect is due but there is no network: no attempts are spent while offline,
// the stream is reopened from onAvailable instead.
private var waitingForNetwork = false
// ExoPlayer drops its own wake and Wi-Fi locks once the player is idle after an error, so the
// backoff delay would stall while the CPU sleeps. These are held only while a reconnect is pending.
private var reconnectWakeLock: PowerManager.WakeLock? = null
private var reconnectWifiLock: WifiManager.WifiLock? = null
private val mainHandler = Handler(Looper.getMainLooper())
private var destroyed = false
private val httpDataSourceFactory: DefaultHttpDataSource.Factory by lazy {
DefaultHttpDataSource.Factory()
@@ -71,7 +95,9 @@ class FogwavePlaybackService : MediaLibraryService() {
}
private val loadControl = DefaultLoadControl.Builder()
.setBufferDurationsMs(5_000, 15_000, 500, 1_000)
// Quick start (0.5 s), but after a stall wait for 2.5 s of audio so a weak network does not
// turn into a play-stall-play stutter.
.setBufferDurationsMs(15_000, 50_000, 500, 2_500)
.setPrioritizeTimeOverSizeThresholds(true)
.build()
@@ -120,30 +146,94 @@ class FogwavePlaybackService : MediaLibraryService() {
return Futures.immediateFuture(LibraryResult.ofItem(station.toMediaItem(this@FogwavePlaybackService), null))
}
// Items coming from a controller are never trusted: only the mediaId (or a voice search
// query) is read, and the stream URI always comes from our own station list. Without this
// an item without a URI (a voice request from Assistant or Android Auto) crashed the
// player, and any app on the device could make Fogwave play an arbitrary stream.
override fun onAddMediaItems(
mediaSession: MediaSession,
controller: MediaSession.ControllerInfo,
mediaItems: MutableList<MediaItem>
): ListenableFuture<MutableList<MediaItem>> {
val resolved = mediaItems.map { item ->
if (item.localConfiguration != null) {
item
} else {
repository.stations.find { it.id == item.mediaId }
?.toMediaItem(this@FogwavePlaybackService)
?: item
val resolved = mediaItems.map { resolveStation(it).toMediaItem(this@FogwavePlaybackService) }
.toMutableList()
resolved.firstOrNull()?.let { onNewRequest(it) }
return Futures.immediateFuture(resolved)
}
}
}.toMutableList()
resolved.firstOrNull()?.let { item ->
Log.d(TAG, "MediaItem resolved: mediaId=${item.mediaId} uri=${item.localConfiguration?.uri}")
private fun resolveStation(item: MediaItem): RadioStation {
val stations = repository.stations
val query = item.requestMetadata.searchQuery?.trim().orEmpty()
return stations.find { it.id == item.mediaId }
?: query.takeIf { it.isNotEmpty() }?.let { q ->
stations.find { it.name.contains(q, ignoreCase = true) }
?: stations.find { q.contains(it.name, ignoreCase = true) }
}
?: stations.find { it.id == repository.getLastStationId() }
?: stations.first()
}
private fun onNewRequest(item: MediaItem) {
Log.d(TAG, "MediaItem resolved: mediaId=${item.mediaId}")
lastRequestedItem = item
retryJob?.cancel()
retryAttempt = 0
waitingForNetwork = false
}
return Futures.immediateFuture(resolved)
private fun switchStation(step: Int) {
val order = stationOrder.ifEmpty { repository.stations }
val currentId = player.currentMediaItem?.mediaId ?: lastRequestedItem?.mediaId
val index = order.indexOfFirst { it.id == currentId }
val target = if (index < 0) order.first() else order[(index + step).mod(order.size)]
Log.d(TAG, "Switching station: ${target.id}")
val item = target.toMediaItem(this)
onNewRequest(item)
repository.setLastStationId(target.id)
// playWhenReady is kept: a paused player switches the station and stays paused.
player.setMediaItem(item)
player.prepare()
}
/**
* The player only ever holds the station that is on air: with the whole list in ExoPlayer every
* stream would be prepared at once, and the HLS ones would keep refreshing their playlists in
* the background. Instead next/previous are always offered to the session (notification,
* headset buttons, Android Auto) and switch the station here, wrapping around like the app.
*/
private inner class StationSwitchingPlayer(player: Player) : ForwardingSimpleBasePlayer(player) {
override fun getState(): State {
val state = super.getState()
if (state.timeline.isEmpty()) return state
val commands = state.availableCommands.buildUpon()
.addAll(
Player.COMMAND_SEEK_TO_NEXT,
Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM,
Player.COMMAND_SEEK_TO_PREVIOUS,
Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM
)
.remove(Player.COMMAND_SET_REPEAT_MODE)
.build()
// REPEAT_MODE_ALL makes next/previous resolve to the single item, which lands in
// handleSeek below with the original seek command.
return state.buildUpon()
.setAvailableCommands(commands)
.setRepeatMode(Player.REPEAT_MODE_ALL)
.build()
}
override fun handleSeek(mediaItemIndex: Int, positionMs: Long, seekCommand: Int): ListenableFuture<*> {
when (seekCommand) {
Player.COMMAND_SEEK_TO_NEXT, Player.COMMAND_SEEK_TO_NEXT_MEDIA_ITEM -> switchStation(+1)
Player.COMMAND_SEEK_TO_PREVIOUS, Player.COMMAND_SEEK_TO_PREVIOUS_MEDIA_ITEM -> switchStation(-1)
else -> return super.handleSeek(mediaItemIndex, positionMs, seekCommand)
}
return Futures.immediateVoidFuture()
}
// The stream's own repeat mode stays off; a dropped stream is handled by scheduleReconnect.
override fun handleSetRepeatMode(repeatMode: Int): ListenableFuture<*> = Futures.immediateVoidFuture()
}
private val resiliencePlayerListener = object : Player.Listener {
@@ -166,6 +256,7 @@ class FogwavePlaybackService : MediaLibraryService() {
if (retryAttempt != 0) Log.d(TAG, "Reconnect succeeded - resetting backoff")
retryAttempt = 0
retryJob?.cancel()
releaseReconnectLocks()
}
}
@@ -179,6 +270,8 @@ class FogwavePlaybackService : MediaLibraryService() {
Log.d(TAG, "Reconnect cancelled - playWhenReady=false (reason=$reason)")
}
retryJob?.cancel()
waitingForNetwork = false
releaseReconnectLocks()
pausedAtMs = SystemClock.elapsedRealtime()
return
}
@@ -203,20 +296,30 @@ class FogwavePlaybackService : MediaLibraryService() {
"mediaItem=${lastRequestedItem?.localConfiguration?.uri}",
error
)
scheduleReconnect()
scheduleReconnect(maxAttempts = maxRetryAttemptsFor(error))
}
}
private fun scheduleReconnect(immediate: Boolean = false) {
private fun scheduleReconnect(immediate: Boolean = false, maxAttempts: Int = MAX_RETRY_ATTEMPTS) {
retryJob?.cancel()
if (!immediate && retryAttempt >= MAX_RETRY_ATTEMPTS) {
if (!immediate && !hasNetwork) {
// Attempts would only fail and run out while offline; wait for onAvailable instead.
Log.d(TAG, "No network - waiting for it before reconnecting")
waitingForNetwork = true
releaseReconnectLocks()
return
}
waitingForNetwork = false
if (!immediate && retryAttempt >= maxAttempts) {
// Give up instead of keeping the device busy forever; the error stays visible and a tap
// on play starts over.
Log.w(TAG, "Reconnect abandoned after $retryAttempt attempts")
retryAttempt = 0
releaseReconnectLocks()
player.pause()
return
}
acquireReconnectLocks()
val delayMs = if (immediate) 0L else retryDelaysMs.getOrElse(retryAttempt) { retryDelaysMs.last() }
retryAttempt++
Log.d(TAG, "Reconnect scheduled in ${delayMs}ms (attempt=$retryAttempt)")
@@ -224,6 +327,7 @@ class FogwavePlaybackService : MediaLibraryService() {
delay(delayMs)
if (!player.playWhenReady) {
Log.d(TAG, "Reconnect skipped - no longer playWhenReady")
releaseReconnectLocks()
return@launch
}
restartStream()
@@ -247,19 +351,71 @@ class FogwavePlaybackService : MediaLibraryService() {
}
}
@Suppress("DEPRECATION") // WIFI_MODE_FULL_HIGH_PERF is what ExoPlayer itself uses for streaming.
private fun acquireReconnectLocks() {
try {
if (reconnectWakeLock == null) {
val pm = getSystemService(Context.POWER_SERVICE) as? PowerManager
reconnectWakeLock = pm?.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Fogwave:reconnect")
?.apply { setReferenceCounted(false) }
}
// The timeout is a safety net; the lock is released as soon as the stream is back.
reconnectWakeLock?.acquire(RECONNECT_LOCK_TIMEOUT_MS)
if (reconnectWifiLock == null) {
val wm = applicationContext.getSystemService(Context.WIFI_SERVICE) as? WifiManager
reconnectWifiLock = wm?.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "Fogwave:reconnect")
?.apply { setReferenceCounted(false) }
}
val wifiLock = reconnectWifiLock
if (wifiLock != null && !wifiLock.isHeld) wifiLock.acquire()
} catch (e: Exception) {
Log.w(TAG, "Could not acquire reconnect locks", e)
}
}
private fun releaseReconnectLocks() {
try { reconnectWakeLock?.takeIf { it.isHeld }?.release() } catch (_: Exception) {}
try { reconnectWifiLock?.takeIf { it.isHeld }?.release() } catch (_: Exception) {}
}
private fun registerNetworkCallback() {
val cm = getSystemService(Context.CONNECTIVITY_SERVICE) as? ConnectivityManager ?: return
connectivityManager = cm
hasNetwork = cm.activeNetwork != null
val callback = object : ConnectivityManager.NetworkCallback() {
// Called on a ConnectivityManager thread; ExoPlayer must only be accessed on the main thread.
override fun onAvailable(network: Network) {
serviceScope.launch {
if (retryJob?.isActive == true && player.playWhenReady && player.playbackState != Player.STATE_READY) {
Log.d(TAG, "Network available again - reconnecting immediately")
val previous = defaultNetwork
defaultNetwork = network
hasNetwork = true
val wasWaiting = waitingForNetwork
waitingForNetwork = false
if (!player.playWhenReady || player.playbackState == Player.STATE_READY) return@launch
if (wasWaiting) {
Log.d(TAG, "Network is back - reconnecting")
retryAttempt = 0
scheduleReconnect(immediate = true)
return@launch
}
// After a switch (e.g. Wi-Fi to mobile) a stalled load can sit on a dead socket until
// the read timeout, so reopen right away instead of waiting for the error.
val switchedWhileStalled = previous != null && previous != network &&
player.playbackState == Player.STATE_BUFFERING
if (retryJob?.isActive == true || switchedWhileStalled) {
Log.d(TAG, "Network available - reconnecting immediately")
scheduleReconnect(immediate = true)
}
}
}
override fun onLost(network: Network) {
serviceScope.launch {
// A switch reports the new network first; only the loss of the current one counts.
if (network == defaultNetwork) hasNetwork = false
}
}
}
networkCallback = callback
try {
@@ -271,6 +427,7 @@ class FogwavePlaybackService : MediaLibraryService() {
override fun onCreate() {
super.onCreate()
repository = RadioRepository(applicationContext)
stationOrder = repository.stationsSortedByPopularity()
val audioManager = getSystemService(Context.AUDIO_SERVICE) as? AudioManager
val audioSessionId = audioManager?.generateAudioSessionId()?.takeIf { it != 0 }
@@ -300,9 +457,7 @@ class FogwavePlaybackService : MediaLibraryService() {
}
Log.d(TAG, "Audio session id for effects: ${player.audioSessionId}")
audioEffectsEngine = AudioEffectsEngine(applicationContext, player.audioSessionId).also {
AudioEffectsController.attach(it)
}
createAudioEffectsAsync(player.audioSessionId)
registerNetworkCallback()
@@ -314,22 +469,47 @@ class FogwavePlaybackService : MediaLibraryService() {
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
)
mediaLibrarySession = MediaLibrarySession.Builder(this, player, librarySessionCallback)
mediaLibrarySession = MediaLibrarySession.Builder(this, StationSwitchingPlayer(player), librarySessionCallback)
.setSessionActivity(sessionActivity)
.build()
}
// Creating the effects means several calls into audioserver; done off the main thread so the
// service, which starts together with the UI, does not delay the first frames.
private fun createAudioEffectsAsync(audioSessionId: Int) {
Thread({
try {
val engine = AudioEffectsEngine(applicationContext, audioSessionId)
mainHandler.post {
if (destroyed) {
engine.release()
} else {
audioEffectsEngine = engine
AudioEffectsController.attach(engine)
}
}
} catch (e: Exception) {
Log.e(TAG, "Audio effects init failed", e)
}
}, "FogwaveEffectsInit").start()
}
override fun onGetSession(controllerInfo: MediaSession.ControllerInfo): MediaLibrarySession? = mediaLibrarySession
// Swiping the app away keeps only real playback alive (a short rebuffer counts): a failed
// stream, a pending reconnect or a pause stop the service. The Media3 default would also stop
// during a rebuffer, because isPlaying is false while buffering.
override fun onTaskRemoved(rootIntent: Intent?) {
if (!player.playWhenReady || player.mediaItemCount == 0) {
player.pause()
stopSelf()
val reconnecting = retryJob?.isActive == true || waitingForNetwork || player.playerError != null
if (!isPlaybackOngoing() || !player.playWhenReady || player.mediaItemCount == 0 || reconnecting) {
pauseAllPlayersAndStopSelf()
}
}
override fun onDestroy() {
destroyed = true
retryJob?.cancel()
releaseReconnectLocks()
serviceScope.cancel()
networkCallback?.let { cb ->
try { connectivityManager?.unregisterNetworkCallback(cb) } catch (_: Exception) {}
@@ -348,7 +528,7 @@ class FogwavePlaybackService : MediaLibraryService() {
companion object {
private const val ROOT_ID = "fogwave_root"
private const val TAG = "FogwavePlaybackService"
private const val MAX_RETRY_ATTEMPTS = 12
private const val RECONNECT_LOCK_TIMEOUT_MS = 2 * 60_000L
private const val LIVE_RESYNC_AFTER_MS = 30_000L
}
}
@@ -0,0 +1,45 @@
package cc.skysparkle.fogwave.player
import androidx.annotation.OptIn
import androidx.media3.common.PlaybackException
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import androidx.media3.datasource.HttpDataSource
// Kept apart from the service and the UI controller so the decisions can be unit tested.
internal const val MAX_RETRY_ATTEMPTS = 12
internal const val MAX_PERMANENT_ERROR_RETRY_ATTEMPTS = 2
// A missing stream or an unsupported format will not fix itself, so it gets only a couple of
// attempts (a stale token or a short server outage can still recover); network errors get the full backoff.
@OptIn(UnstableApi::class)
internal fun maxRetryAttemptsFor(error: PlaybackException): Int {
val httpCode = (error.cause as? HttpDataSource.InvalidResponseCodeException)?.responseCode
val permanent = when (error.errorCode) {
PlaybackException.ERROR_CODE_IO_BAD_HTTP_STATUS ->
httpCode != null && httpCode in 400..499 && httpCode != 408 && httpCode != 429
PlaybackException.ERROR_CODE_IO_FILE_NOT_FOUND,
PlaybackException.ERROR_CODE_IO_CLEARTEXT_NOT_PERMITTED,
PlaybackException.ERROR_CODE_PARSING_CONTAINER_UNSUPPORTED,
PlaybackException.ERROR_CODE_PARSING_MANIFEST_UNSUPPORTED,
PlaybackException.ERROR_CODE_DECODING_FORMAT_UNSUPPORTED -> true
else -> false
}
return if (permanent) MAX_PERMANENT_ERROR_RETRY_ATTEMPTS else MAX_RETRY_ATTEMPTS
}
/** What the UI shows for the session's player; [errorMessage] turns a playback error into text. */
internal fun deriveState(p: Player, errorMessage: (PlaybackException) -> String): PlayerState {
p.playerError?.let { return PlayerState.Error(errorMessage(it)) }
return when (p.playbackState) {
Player.STATE_READY -> if (p.playWhenReady) PlayerState.Playing else PlayerState.Paused
Player.STATE_BUFFERING, Player.STATE_ENDED ->
if (p.playWhenReady) PlayerState.Connecting else PlayerState.Paused
else -> when {
p.mediaItemCount == 0 -> PlayerState.Idle
p.playWhenReady -> PlayerState.Connecting
else -> PlayerState.Paused
}
}
}
@@ -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
@@ -39,8 +43,9 @@ class RadioPlayerManager(private val context: Context) {
private val playerListener = object : Player.Listener {
override fun onEvents(player: Player, events: Player.Events) {
_playerState.value = deriveState(player)
_playerState.value = deriveState(player, ::errorMessage)
_currentMediaId.value = player.currentMediaItem?.mediaId
_nowPlayingTitle.value = streamTitle(player)
}
override fun onPlayerError(error: PlaybackException) {
@@ -48,6 +53,17 @@ class RadioPlayerManager(private val context: Context) {
}
}
// Without this a controller whose session went away stays non-null and every command is
// silently dropped, leaving the UI stuck on "connecting".
private val controllerListener = object : MediaController.Listener {
override fun onDisconnected(controller: MediaController) {
if (released || controller !== this@RadioPlayerManager.controller) return
Log.w(TAG, "MediaController disconnected")
dropController()
_playerState.value = PlayerState.Idle
}
}
// Declared after every property it touches so that nothing is read before initialization.
init {
connectToPlaybackService()
@@ -56,7 +72,9 @@ class RadioPlayerManager(private val context: Context) {
private fun connectToPlaybackService() {
if (released || controllerFuture != null) return
val sessionToken = SessionToken(context, ComponentName(context, FogwavePlaybackService::class.java))
val future = MediaController.Builder(context, sessionToken).buildAsync()
val future = MediaController.Builder(context, sessionToken)
.setListener(controllerListener)
.buildAsync()
controllerFuture = future
future.addListener({
if (released) return@addListener
@@ -70,8 +88,9 @@ class RadioPlayerManager(private val context: Context) {
if (station != null) {
playStation(station)
} else {
_playerState.value = deriveState(c)
_playerState.value = deriveState(c, ::errorMessage)
_currentMediaId.value = c.currentMediaItem?.mediaId
_nowPlayingTitle.value = streamTitle(c)
}
} catch (e: Exception) {
Log.e(TAG, "Failed to connect to FogwavePlaybackService", e)
@@ -83,18 +102,27 @@ class RadioPlayerManager(private val context: Context) {
}, MoreExecutors.directExecutor())
}
private fun deriveState(p: Player): PlayerState {
p.playerError?.let { return PlayerState.Error(errorMessage(it)) }
return when (p.playbackState) {
Player.STATE_READY -> if (p.playWhenReady) PlayerState.Playing else PlayerState.Paused
Player.STATE_BUFFERING, Player.STATE_ENDED ->
if (p.playWhenReady) PlayerState.Connecting else PlayerState.Paused
else -> when {
p.mediaItemCount == 0 -> PlayerState.Idle
p.playWhenReady -> PlayerState.Connecting
else -> PlayerState.Paused
/** The controller if it is still connected; a stale one is dropped so the next call reconnects. */
private fun connectedController(): MediaController? {
val c = controller ?: return null
if (c.isConnected) return c
dropController()
return null
}
private fun dropController() {
controller?.removeListener(playerListener)
controller = null
controllerFuture?.let { MediaController.releaseFuture(it) }
controllerFuture = null
}
// 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(
@@ -108,7 +136,7 @@ class RadioPlayerManager(private val context: Context) {
fun playStation(station: RadioStation) {
Log.d(TAG, "Station requested: ${station.id}")
currentStation = station
val c = controller
val c = connectedController()
if (c == null) {
pendingStation = station
_playerState.value = PlayerState.Connecting
@@ -116,6 +144,7 @@ class RadioPlayerManager(private val context: Context) {
return
}
_playerState.value = PlayerState.Connecting
_nowPlayingTitle.value = null
try {
c.setMediaItem(station.toMediaItem(context))
c.prepare()
@@ -127,7 +156,7 @@ class RadioPlayerManager(private val context: Context) {
}
fun play() {
val c = controller
val c = connectedController()
when {
c == null || c.mediaItemCount == 0 -> currentStation?.let { playStation(it) }
// A failed, stopped or finished live stream has to be reopened rather than resumed.
@@ -5,12 +5,15 @@ import android.content.Context
import androidx.core.net.toUri
import androidx.media3.common.MediaItem
import androidx.media3.common.MediaMetadata
import androidx.media3.common.MimeTypes
import cc.skysparkle.fogwave.data.model.RadioStation
fun RadioStation.toMediaItem(context: Context): MediaItem {
val artworkUri = "${ContentResolver.SCHEME_ANDROID_RESOURCE}://${context.packageName}/$iconResId".toUri()
return MediaItem.Builder()
.setUri(streamUrl)
// HLS playlists are picked up by the HLS module; everything else stays a progressive stream.
.apply { if (streamUrl.substringBefore('?').endsWith(".m3u8")) setMimeType(MimeTypes.APPLICATION_M3U8) }
.setMediaId(id)
.setMediaMetadata(
MediaMetadata.Builder()
@@ -1,40 +1,52 @@
package cc.skysparkle.fogwave.ui.components
import androidx.annotation.DrawableRes
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateColorAsState
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.ColumnScope
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.selection.selectable
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Switch
import androidx.compose.material3.SwitchDefaults
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.draw.clip
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
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.TextAlign
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.BuildConfig
import cc.skysparkle.fogwave.R
import cc.skysparkle.fogwave.ui.theme.AppStyle
import cc.skysparkle.fogwave.ui.theme.AppThemeState
import cc.skysparkle.fogwave.ui.theme.GeoColors
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
private const val REPOSITORY_URL = "https://git.skysparkle.cc/kalarina/Fogwave"
@@ -48,179 +60,372 @@ fun AboutPanel(modifier: Modifier = Modifier) {
Column(
modifier = modifier
.fillMaxWidth()
.padding(horizontal = 20.dp, vertical = 12.dp),
verticalArrangement = Arrangement.spacedBy(16.dp)
) {
Column(
modifier = Modifier
.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(20.dp),
horizontalAlignment = Alignment.CenterHorizontally,
.padding(horizontal = 20.dp, vertical = 8.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
) {
Box(
modifier = Modifier
.size(64.dp)
.clip(RoundedCornerShape(20.dp)),
contentAlignment = Alignment.Center
) {
AppIcon(
resId = R.drawable.ic_fogwave_logo,
contentDescription = stringResource(R.string.fogwave_logo_content_desc),
size = 52.dp
)
AppHeader()
SectionLabel(stringResource(R.string.about_appearance))
GroupCard {
StylePicker()
CardDivider()
StationFogRow()
}
Text(
text = stringResource(R.string.app_name),
style = MaterialTheme.typography.titleLarge.copy(
fontWeight = FontWeight.ExtraBold,
fontSize = 22.sp,
letterSpacing = (-0.5).sp,
color = LocalGeoColors.current.deepPurple
)
)
// Comes straight from versionName in app/build.gradle.kts, so it can never drift.
Text(
text = stringResource(R.string.about_version, BuildConfig.VERSION_NAME),
style = MaterialTheme.typography.labelMedium.copy(
fontWeight = FontWeight.SemiBold,
color = LocalGeoColors.current.primary
),
modifier = Modifier.testTag("about_version")
)
Text(
text = stringResource(R.string.about_description),
style = MaterialTheme.typography.bodyMedium.copy(
fontSize = 13.5.sp,
lineHeight = 20.sp,
color = LocalGeoColors.current.onSurfaceVariant,
textAlign = TextAlign.Center
),
modifier = Modifier.padding(top = 4.dp)
)
}
AboutLinkCard(
iconRes = R.drawable.ic_repo,
iconTint = null,
SectionLabel(stringResource(R.string.about_more))
GroupCard {
LinkRow(
iconRes = R.drawable.ic_mc_code,
title = stringResource(R.string.about_my_repository),
subtitle = REPOSITORY_URL.removePrefix("https://git.skysparkle.cc/"),
trailingIconRes = R.drawable.ic_open_in_new,
subtitle = REPOSITORY_URL.removePrefix("https://"),
external = true,
onClick = { context.openUrl(REPOSITORY_URL) },
modifier = Modifier.testTag("github_repo_card")
)
AboutLinkCard(
iconRes = R.drawable.ic_privacy,
CardDivider()
LinkRow(
iconRes = R.drawable.ic_mc_shield,
title = stringResource(R.string.privacy_title),
subtitle = stringResource(R.string.privacy_subtitle),
trailingIconRes = R.drawable.ic_open_in_new,
external = true,
onClick = { context.openUrl(PRIVACY_POLICY_URL) },
modifier = Modifier.testTag("privacy_card")
)
AboutLinkCard(
iconRes = R.drawable.ic_copyright,
CardDivider()
LinkRow(
iconRes = R.drawable.ic_mc_copyright,
title = stringResource(R.string.licenses_title),
subtitle = stringResource(R.string.licenses_subtitle),
trailingIconRes = R.drawable.ic_chevron_right,
external = false,
onClick = { showLicenses = true },
modifier = Modifier.testTag("licenses_card")
)
}
}
if (showLicenses) {
LicensesDialog(onDismiss = { showLicenses = false })
}
}
/** Logo, name and version in one row, the description underneath. */
@Composable
private fun AboutLinkCard(
@DrawableRes iconRes: Int,
title: String,
subtitle: String,
@DrawableRes trailingIconRes: Int,
onClick: () -> Unit,
modifier: Modifier = Modifier,
iconTint: Color? = LocalGeoColors.current.deepPurple
) {
val opensBrowser = trailingIconRes == R.drawable.ic_open_in_new
private fun AppHeader() {
val colors = LocalGeoColors.current
GroupCard(contentPadding = 16.dp) {
Row(
modifier = modifier
.fillMaxWidth()
.shadow(4.dp, RoundedCornerShape(20.dp))
.clip(RoundedCornerShape(20.dp))
.background(LocalGeoColors.current.surfaceContainer)
.border(1.2.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(20.dp))
.clickable(
onClickLabel = if (opensBrowser) stringResource(R.string.about_open_in_browser) else null,
role = Role.Button,
onClick = onClick
)
.padding(16.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(14.dp)
) {
Box(
modifier = Modifier
.size(48.dp)
.clip(RoundedCornerShape(14.dp))
.background(LocalGeoColors.current.primaryContainer)
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(14.dp)),
.size(52.dp)
.clip(RoundedCornerShape(16.dp))
.background(colors.primaryContainer),
contentAlignment = Alignment.Center
) {
AppIcon(
resId = iconRes,
tint = iconTint ?: Color.Unspecified,
size = if (iconTint == null) 32.dp else 26.dp
resId = R.drawable.ic_fogwave_logo,
contentDescription = stringResource(R.string.fogwave_logo_content_desc),
size = 40.dp
)
}
Column(modifier = Modifier.weight(1f)) {
Column(verticalArrangement = Arrangement.spacedBy(4.dp)) {
Text(
text = title,
style = MaterialTheme.typography.titleSmall.copy(
text = stringResource(R.string.app_name),
style = MaterialTheme.typography.titleLarge.copy(
fontWeight = FontWeight.ExtraBold,
fontSize = 21.sp,
letterSpacing = (-0.4).sp,
color = colors.deepPurple
)
)
// Comes straight from versionName in app/build.gradle.kts, so it can never drift.
Text(
text = stringResource(R.string.about_version, BuildConfig.VERSION_NAME),
style = MaterialTheme.typography.labelSmall.copy(
fontWeight = FontWeight.Bold,
fontSize = 15.sp,
color = LocalGeoColors.current.deepPurple
)
fontSize = 11.sp,
color = colors.primary
),
modifier = Modifier
.clip(CircleShape)
.background(colors.primaryContainer)
.padding(horizontal = 9.dp, vertical = 3.dp)
.testTag("about_version")
)
}
}
Text(
text = subtitle,
text = stringResource(R.string.about_description),
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 13.sp,
lineHeight = 19.sp,
color = colors.onSurfaceVariant
),
modifier = Modifier.padding(top = 12.dp)
)
}
}
@Composable
private fun StylePicker() {
val context = LocalContext.current
val colors = LocalGeoColors.current
val selected = AppThemeState.style
val styles = remember { AppStyle.available }
Column(modifier = Modifier.padding(16.dp)) {
RowHeader(iconRes = R.drawable.ic_mc_palette, title = stringResource(R.string.app_style_title))
Row(
modifier = Modifier
.fillMaxWidth()
.padding(top = 14.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
styles.forEach { style ->
StyleSwatch(
style = style,
preview = remember(style) { AppThemeState.colorsFor(context, style) },
selected = style == selected,
onClick = { AppThemeState.select(context, style) },
modifier = Modifier.weight(1f)
)
}
}
AnimatedVisibility(visible = selected == AppStyle.DEVICE) {
Text(
text = stringResource(R.string.app_style_device_hint),
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 12.sp,
color = LocalGeoColors.current.primary
)
lineHeight = 17.sp,
color = colors.onSurfaceVariant
),
modifier = Modifier.padding(top = 12.dp)
)
}
}
}
if (opensBrowser) {
@Composable
private fun StyleSwatch(
style: AppStyle,
preview: GeoColors,
selected: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
val colors = LocalGeoColors.current
val ring by animateColorAsState(if (selected) colors.deepPurple else Color.Transparent, label = "swatch_ring")
Column(
modifier = modifier
.clip(RoundedCornerShape(14.dp))
.selectable(selected = selected, role = Role.RadioButton, onClick = onClick)
.padding(vertical = 6.dp)
.testTag("style_${style.name.lowercase()}"),
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(6.dp)
) {
// The outer ring shows the selection; inside, the style's accent over its background
Box(
modifier = Modifier
.size(36.dp)
.size(42.dp)
.border(2.dp, ring, CircleShape)
.padding(4.dp)
.clip(CircleShape)
.background(LocalGeoColors.current.primaryContainer),
.background(preview.surfaceContainerHigh),
contentAlignment = Alignment.Center
) {
AppIcon(
resId = trailingIconRes,
tint = LocalGeoColors.current.deepPurple,
size = 18.dp
Box(
modifier = Modifier
.size(24.dp)
.clip(CircleShape)
.background(preview.accentLavender),
contentAlignment = Alignment.Center
) {
if (selected) {
AppIcon(resId = R.drawable.ic_mc_check, tint = preview.onAccentLavender, size = 15.dp)
}
}
}
Text(
text = stringResource(style.titleRes),
style = MaterialTheme.typography.labelSmall.copy(
fontSize = 11.sp,
fontWeight = if (selected) FontWeight.Bold else FontWeight.Medium,
color = if (selected) colors.deepPurple else colors.onSurfaceVariant
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
} else {
}
@Composable
private fun StationFogRow() {
val context = LocalContext.current
val colors = LocalGeoColors.current
val checked = AppThemeState.stationFog
Row(
modifier = Modifier
.fillMaxWidth()
.toggleable(
value = checked,
role = Role.Switch,
onValueChange = { AppThemeState.setStationFog(context, it) }
)
.padding(16.dp)
.testTag("station_fog_toggle"),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
RowIcon(R.drawable.ic_mc_fog)
Column(modifier = Modifier.weight(1f)) {
RowTitle(stringResource(R.string.station_fog_title))
RowSubtitle(stringResource(R.string.station_fog_subtitle), maxLines = 3)
}
// The row handles the tap, so the switch itself only shows the state
Switch(
checked = checked,
onCheckedChange = null,
colors = SwitchDefaults.colors(
checkedThumbColor = colors.onAccentLavender,
checkedTrackColor = colors.accentLavender,
checkedBorderColor = colors.accentLavender,
uncheckedThumbColor = colors.onSurfaceVariant,
uncheckedTrackColor = colors.surfaceContainerHigh,
uncheckedBorderColor = colors.outline
)
)
}
}
@Composable
private fun LinkRow(
@DrawableRes iconRes: Int,
title: String,
subtitle: String,
external: Boolean,
onClick: () -> Unit,
modifier: Modifier = Modifier
) {
Row(
modifier = modifier
.fillMaxWidth()
.clickable(
onClickLabel = if (external) stringResource(R.string.about_open_in_browser) else null,
role = Role.Button,
onClick = onClick
)
.padding(horizontal = 16.dp, vertical = 13.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
RowIcon(iconRes)
Column(modifier = Modifier.weight(1f)) {
RowTitle(title)
RowSubtitle(subtitle)
}
AppIcon(
resId = trailingIconRes,
resId = if (external) R.drawable.ic_mc_external else R.drawable.ic_mc_right,
tint = LocalGeoColors.current.onSurfaceVariant,
size = 18.dp
)
}
}
@Composable
private fun RowHeader(@DrawableRes iconRes: Int, title: String) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
RowIcon(iconRes)
RowTitle(title)
}
}
@Composable
private fun RowIcon(@DrawableRes iconRes: Int) {
Box(
modifier = Modifier
.size(36.dp)
.clip(RoundedCornerShape(11.dp))
.background(LocalGeoColors.current.primaryContainer),
contentAlignment = Alignment.Center
) {
AppIcon(resId = iconRes, tint = LocalGeoColors.current.primary, size = 20.dp)
}
}
@Composable
private fun RowTitle(text: String) {
Text(
text = text,
style = MaterialTheme.typography.titleSmall.copy(
fontWeight = FontWeight.Bold,
fontSize = 14.5.sp,
color = LocalGeoColors.current.deepPurple
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
@Composable
private fun RowSubtitle(text: String, maxLines: Int = 1) {
Text(
text = text,
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 12.sp,
lineHeight = 16.sp,
color = LocalGeoColors.current.onSurfaceVariant
),
maxLines = maxLines,
overflow = TextOverflow.Ellipsis
)
}
@Composable
private fun SectionLabel(text: String) {
Text(
text = text.uppercase(),
style = MaterialTheme.typography.labelSmall.copy(
fontWeight = FontWeight.Bold,
fontSize = 11.sp,
letterSpacing = 1.2.sp,
color = LocalGeoColors.current.onSurfaceVariant
),
modifier = Modifier.padding(start = 6.dp, top = 8.dp)
)
}
/** Rows grouped on one rounded card, like a settings list. */
@Composable
private fun GroupCard(
contentPadding: Dp = 0.dp,
content: @Composable ColumnScope.() -> Unit
) {
Column(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(22.dp))
.background(LocalGeoColors.current.surfaceContainer)
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(22.dp))
.padding(contentPadding),
content = content
)
}
@Composable
private fun CardDivider() {
Box(
modifier = Modifier
.fillMaxWidth()
.padding(start = 64.dp)
.height(1.dp)
.background(LocalGeoColors.current.outlineVariant)
)
}
@@ -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)
)
@@ -177,7 +177,7 @@ fun EqualizerSheet(
) {
val db = (band.levelMillibel / 100f).roundToInt()
Text(
text = if (db > 0) "+$db dB" else "$db dB",
text = stringResource(R.string.eq_gain_db, if (db > 0) "+$db" else "$db"),
style = MaterialTheme.typography.labelSmall.copy(
fontSize = 11.sp,
fontWeight = FontWeight.SemiBold,
@@ -356,10 +356,11 @@ private fun ToggleRow(
}
}
@Composable
private fun frequencyLabel(hz: Int): String = when {
hz < 1000 -> "$hz Hz"
hz % 1000 == 0 -> "${hz / 1000} kHz"
else -> String.format(Locale.getDefault(), "%.1f kHz", hz / 1000f)
hz < 1000 -> stringResource(R.string.eq_freq_hz, hz.toString())
hz % 1000 == 0 -> stringResource(R.string.eq_freq_khz, (hz / 1000).toString())
else -> stringResource(R.string.eq_freq_khz, String.format(Locale.getDefault(), "%.1f", hz / 1000f))
}
// Preset names come from the device's audio framework in English; translate the standard ones.
@@ -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,70 +60,29 @@ 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
) {
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)
)
}
/** 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 ->
items(favorites, key = { it.id }) { station ->
val isCur = station.id == currentStation?.id
StationItem(
StationRow(
station = station,
isCurrent = isCur,
isPlaying = isCur && isPlaying,
viewMode = viewMode,
sizeStep = sizeStep,
onClick = { onSelectStation(station) }
onClick = { onSelectStation(station) },
modifier = Modifier.animateItem()
)
}
}
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) }
)
}
}
}
}
@Composable
@@ -0,0 +1,147 @@
package cc.skysparkle.fogwave.ui.components
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.RepeatMode
import androidx.compose.animation.core.animateFloat
import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.rememberInfiniteTransition
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Spacer
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.draw.drawWithCache
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.drawscope.translate
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.graphics.lerp
import kotlin.math.PI
import kotlin.math.cos
import kotlin.math.max
import kotlin.math.sin
/** One drifting patch of mist: where it rests, how far and how it wanders, and how big it is. */
private class Wisp(
val x: Float,
val y: Float,
val dx: Float,
val dy: Float,
val phase: Float,
val radius: Float,
val alpha: Float,
val mix: Float
)
private val Wisps = listOf(
Wisp(x = 0.18f, y = 0.30f, dx = 0.10f, dy = 0.05f, phase = 0.0f, radius = 0.62f, alpha = 0.55f, mix = 0.0f),
Wisp(x = 0.82f, y = 0.42f, dx = 0.08f, dy = 0.07f, phase = 1.9f, radius = 0.55f, alpha = 0.45f, mix = 0.35f),
Wisp(x = 0.50f, y = 0.70f, dx = 0.14f, dy = 0.04f, phase = 3.7f, radius = 0.70f, alpha = 0.35f, mix = 0.15f),
Wisp(x = 0.35f, y = 0.55f, dx = 0.06f, dy = 0.08f, phase = 5.1f, radius = 0.38f, alpha = 0.22f, mix = 0.8f)
)
/**
* Slowly drifting colored fog — Fogwave's signature backdrop. [tint] is usually the playing
* station's color. Only the draw phase reads the animation, so the fog never recomposes anything.
* With [animate] off (the layer is covered, e.g. by the open player) the fog holds still and the
* animation stops; it resumes from the same spot.
*/
@Composable
fun FogLayer(
tint: Color,
modifier: Modifier = Modifier,
intensity: Float = 1f,
animate: Boolean = true
) {
// Last drawn time and breathing, so a paused fog stays put and resumes without a jump.
val last = remember { floatArrayOf(0f, 1f) }
if (animate) {
val transition = rememberInfiniteTransition(label = "fog")
val t = transition.animateFloat(
initialValue = 0f,
targetValue = TWO_PI,
animationSpec = infiniteRepeatable(tween(28_000, easing = LinearEasing), RepeatMode.Restart),
label = "fog_t"
)
val breathe = transition.animateFloat(
initialValue = 0.85f,
targetValue = 1f,
animationSpec = infiniteRepeatable(tween(6_000), RepeatMode.Reverse),
label = "fog_breathe"
)
// The transition restarts from 0 each time; continue from where the fog was paused.
val start = remember { last[0] }
FogCanvas(tint, intensity, last, modifier) {
last[0] = (start + t.value) % TWO_PI
last[1] = breathe.value
}
} else {
FogCanvas(tint, intensity, last, modifier) {}
}
}
@Composable
private fun FogCanvas(
tint: Color,
intensity: Float,
last: FloatArray,
modifier: Modifier,
advance: () -> Unit
) {
// Wisps are larger than the layer; clipping keeps them from leaking past its edges.
Spacer(
modifier = modifier.clipToBounds().drawWithCache {
// The gradients only depend on the size, tint and intensity; a frame just moves them.
val unit = max(size.width, size.height)
val brushes = Wisps.map { wisp -> wispBrush(wisp, unit, tint, intensity) }
onDrawBehind {
// Reads the animation here, in the draw phase, so only drawing repeats per frame.
advance()
Wisps.forEachIndexed { i, wisp -> drawWisp(wisp, brushes[i], unit, last[0], last[1]) }
}
}
)
}
private const val TWO_PI = (2 * PI).toFloat()
private fun wispBrush(wisp: Wisp, unit: Float, tint: Color, intensity: Float): Brush {
// Part of the mist is paler, so the fog is not a flat single-color glow.
val color = lerp(tint, Color(0xFFDDE6FF), wisp.mix)
val a = (wisp.alpha * intensity).coerceIn(0f, 1f)
// Centered at the origin; drawWisp moves it into place.
return Brush.radialGradient(
0f to color.copy(alpha = a),
0.45f to color.copy(alpha = a * 0.35f),
1f to Color.Transparent,
center = Offset.Zero,
radius = unit * wisp.radius
)
}
private fun DrawScope.drawWisp(wisp: Wisp, brush: Brush, unit: Float, time: Float, breathe: Float) {
val cx = size.width * (wisp.x + wisp.dx * sin(time + wisp.phase))
val cy = size.height * (wisp.y + wisp.dy * cos(time * 2f + wisp.phase))
translate(cx, cy) {
drawCircle(brush = brush, radius = unit * wisp.radius, center = Offset.Zero, alpha = breathe)
}
}
/** 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
)
}
@@ -0,0 +1,72 @@
package cc.skysparkle.fogwave.ui.components
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.ColorMatrix
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import cc.skysparkle.fogwave.R
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
/**
* Misty peak at the top of the home screen with drifting fog in the playing station's color.
* [animate] is turned off while the home screen is covered, so the hidden fog does not keep drawing.
* [visibility] is read in the draw phase (0 = gone, 1 = fully shown) so scrolling never recomposes it.
*/
@Composable
fun HomeBackdrop(
tint: Color,
modifier: Modifier = Modifier,
animate: Boolean = true,
visibility: () -> Float = { 1f }
) {
val background = LocalGeoColors.current.background
// Cool, slightly desaturated photo so the colored fog and the UI stay in front.
val muted = remember {
ColorFilter.colorMatrix(ColorMatrix().apply { setToSaturation(0.35f) })
}
Box(
modifier = modifier
.fillMaxWidth()
.height(420.dp)
.graphicsLayer { alpha = visibility().coerceIn(0f, 1f) }
// Everything (photo and fog) melts into the page instead of ending at a hard edge.
.fadeOutBottom(from = 0.45f)
) {
Image(
painter = painterResource(R.drawable.bg_misty_mountain),
contentDescription = null,
contentScale = ContentScale.Crop,
alignment = Alignment.TopCenter,
colorFilter = muted,
alpha = 0.5f,
modifier = Modifier.fillMaxSize()
)
FogLayer(tint = tint, intensity = 0.6f, animate = animate, 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 Color.Transparent
)
)
)
}
}
@@ -46,13 +46,11 @@ private val LIBRARIES = listOf(
LicenseRow("AndroidX Activity Compose", AOSP, APACHE, "https://developer.android.com/jetpack/androidx/releases/activity", BuildConfig.ACTIVITY_VERSION),
LicenseRow("AndroidX Core KTX", AOSP, APACHE, "https://developer.android.com/jetpack/androidx/releases/core", BuildConfig.CORE_KTX_VERSION),
LicenseRow("AndroidX Lifecycle (ViewModel + Runtime Compose)", AOSP, APACHE, "https://developer.android.com/jetpack/androidx/releases/lifecycle", BuildConfig.LIFECYCLE_VERSION),
LicenseRow("AndroidX Media3 (ExoPlayer, MediaSession)", AOSP, APACHE, "https://developer.android.com/jetpack/androidx/releases/media3", BuildConfig.MEDIA3_VERSION),
LicenseRow("AndroidX Media3 (ExoPlayer, HLS, MediaSession)", AOSP, APACHE, "https://developer.android.com/jetpack/androidx/releases/media3", BuildConfig.MEDIA3_VERSION),
LicenseRow("AndroidX \u2014 other libraries pulled in by the ones above", AOSP, APACHE, "https://developer.android.com/jetpack/androidx"),
LicenseRow("Guava (used by Media3)", "Google", APACHE, "https://github.com/google/guava"),
LicenseRow("kotlinx.coroutines", "JetBrains", APACHE, "https://github.com/Kotlin/kotlinx.coroutines", BuildConfig.COROUTINES_VERSION),
LicenseRow("Kotlin Standard Library", "JetBrains", APACHE, "https://github.com/JetBrains/kotlin", BuildConfig.KOTLIN_VERSION),
LicenseRow("Coil", "Coil Contributors", APACHE, "https://github.com/coil-kt/coil", BuildConfig.COIL_VERSION),
LicenseRow("OkHttp & Okio (used by Coil)", "Square, Inc.", APACHE, "https://square.github.io/okhttp/")
LicenseRow("Kotlin Standard Library", "JetBrains", APACHE, "https://github.com/JetBrains/kotlin", BuildConfig.KOTLIN_VERSION)
)
private val ASSETS = listOf(
@@ -69,7 +67,11 @@ private val STATIONS = listOf(
LicenseRow("M-1", "M-1 group", BROADCASTER, "https://www.m-1.fm/"),
LicenseRow("M-1 Plius", "M-1 group", BROADCASTER, "https://www.m-1.fm/"),
LicenseRow("Gold FM", "Gold FM", BROADCASTER, "https://www.goldfm.lt/"),
LicenseRow("RC", "Radiocentras group", BROADCASTER, "https://www.rc.lt/")
LicenseRow("RC", "Radiocentras group", BROADCASTER, "https://www.rc.lt/"),
LicenseRow("LRT Radijas", "Lietuvos nacionalinis radijas ir televizija (LRT)", BROADCASTER, "https://www.lrt.lt/"),
LicenseRow("\u017Dini\u0173 radijas", "\u017Dini\u0173 radijas, UAB", BROADCASTER, "https://www.ziniuradijas.lt/"),
LicenseRow("Latvijas Radio 1", "Latvijas Sabiedriskais medijs (LSM)", BROADCASTER, "https://latvijasradio.lsm.lv/"),
LicenseRow("Latvijas Radio 2", "Latvijas Sabiedriskais medijs (LSM)", BROADCASTER, "https://latvijasradio.lsm.lv/")
)
@Composable
@@ -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
@@ -40,11 +39,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.semantics.Role
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.IntOffset
@@ -63,8 +61,8 @@ 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,
@@ -72,6 +70,7 @@ fun MiniPlayer(
) {
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 +78,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 +106,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,91 +149,67 @@ fun MiniPlayer(
}
}
)
.padding(start = 10.dp, end = 12.dp, top = 8.dp, bottom = 8.dp)
.padding(start = 8.dp, end = 4.dp, top = 8.dp, bottom = 8.dp)
.testTag("mini_player"),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(12.dp)
) {
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)
) {
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
)
}
Box(
modifier = Modifier
.size(42.dp)
.shadow(2.dp, CircleShape)
.size(48.dp)
.shadow(6.dp, CircleShape)
.clip(CircleShape)
.background(LocalGeoColors.current.accentLavender)
.clickable { onTogglePlay() }
.background(colors.accentLavender)
.clickable(role = Role.Button) { onTogglePlay() }
.testTag("mini_play_btn"),
contentAlignment = Alignment.Center
) {
if (isConnecting) {
CircularProgressIndicator(
modifier = Modifier.size(20.dp),
color = LocalGeoColors.current.onAccentLavender,
modifier = Modifier.size(22.dp),
color = colors.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,
tint = colors.onAccentLavender,
size = 22.dp
)
}
@@ -243,18 +218,17 @@ fun MiniPlayer(
IconButton(
onClick = onNext,
modifier = Modifier
.size(36.dp)
.size(40.dp)
.testTag("mini_next_btn")
) {
AppIcon(
resId = R.drawable.ic_chevron_right,
resId = R.drawable.ic_skip_next,
contentDescription = stringResource(R.string.next_station_content_desc),
tint = LocalGeoColors.current.onSurfaceVariant,
size = 24.dp
tint = colors.onSurfaceVariant,
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)
)
)
)
)
}
}
@@ -1,5 +1,7 @@
package cc.skysparkle.fogwave.ui.components
import android.content.Context
import android.content.Intent
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.FastOutLinearInEasing
import androidx.compose.animation.core.Spring
@@ -7,34 +9,34 @@ 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
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
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.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.foundation.layout.widthIn
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.CircularProgressIndicator
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@@ -51,16 +53,17 @@ import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.scale
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.nestedscroll.NestedScrollConnection
import androidx.compose.ui.input.nestedscroll.NestedScrollSource
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.LocalContext
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.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.text.font.FontWeight
@@ -75,6 +78,7 @@ 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.AppThemeState
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
import kotlin.math.roundToInt
@@ -82,6 +86,7 @@ import kotlin.math.roundToInt
fun NowPlayingSheet(
station: RadioStation?,
playerState: PlayerState,
trackTitle: String?,
isFavorite: Boolean,
onToggleFavorite: () -> Unit,
onTogglePlay: () -> Unit,
@@ -100,6 +105,8 @@ fun NowPlayingSheet(
) {
if (station == null) return
val colors = LocalGeoColors.current
val context = LocalContext.current
val isPlaying = playerState is PlayerState.Playing
val isConnecting = playerState is PlayerState.Connecting
val isError = playerState is PlayerState.Error
@@ -110,239 +117,244 @@ fun NowPlayingSheet(
SheetDragState(
dismissThresholdPx = with(density) { 110.dp.toPx() },
flingThresholdPx = with(density) { 1400.dp.toPx() },
offscreenPx = with(density) { 900.dp.toPx() },
offscreenPx = with(density) { 1200.dp.toPx() },
onDismiss = { currentOnClose() }
)
}
val artScale by animateFloatAsState(
targetValue = if (isPlaying) 1.02f else 0.98f,
val accent by animateColorAsState(
targetValue = rememberStationArt(station).takeIf { AppThemeState.stationFog }.accentOr(colors.accentLavender),
animationSpec = tween(700),
label = "page_accent"
)
val discScale by animateFloatAsState(
targetValue = if (isPlaying) 1f else 0.94f,
animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy),
label = "art_scale"
label = "disc_scale"
)
Box(
modifier = modifier
.fillMaxSize()
// Read in the draw phase so pulling the sheet does not recompose the whole player.
// Read in the draw phase so pulling the page does not recompose the whole player.
.drawBehind {
val progress = (drag.offsetPx / drag.dismissThresholdPx).coerceIn(0f, 1f)
drawRect(Color.Black.copy(alpha = 0.55f * (1f - progress)))
}
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null
) {
onClose()
}
) {
BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
val isTablet = maxWidth > 600.dp
val sheetWidthModifier = if (isTablet) Modifier.widthIn(max = 560.dp) else Modifier.fillMaxWidth()
val pageWidth = if (isTablet) Modifier.widthIn(max = 560.dp) else Modifier.fillMaxWidth()
Column(
Box(
modifier = Modifier
.align(Alignment.BottomCenter)
.align(Alignment.TopCenter)
.then(sheetModifier)
.offset { IntOffset(0, drag.offsetPx.roundToInt()) }
.then(sheetWidthModifier)
.fillMaxHeight(0.94f)
.shadow(16.dp, RoundedCornerShape(topStart = 36.dp, topEnd = 36.dp))
.clip(RoundedCornerShape(topStart = 36.dp, topEnd = 36.dp))
.background(LocalGeoColors.current.background)
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(topStart = 36.dp, topEnd = 36.dp))
// Swallow taps so they do not fall through to the scrim (which closes the sheet),
// without exposing the sheet itself as a button to accessibility services.
.fillMaxSize()
.background(colors.background)
// Swallow taps so nothing underneath reacts to them.
.pointerInput(Unit) { detectTapGestures { } }
// The whole sheet scrolls; drags that the content cannot use pull the sheet down.
.nestedScroll(drag.nestedScrollConnection)
.navigationBarsPadding()
.verticalScroll(rememberScrollState())
.padding(bottom = 28.dp)
.testTag("now_playing_sheet"),
horizontalAlignment = Alignment.CenterHorizontally
.testTag("now_playing_sheet")
) {
// Fog in the station's color drifts behind the disc and fades into the page.
Box(
modifier = Modifier
.padding(top = 12.dp, bottom = 4.dp)
.size(width = 48.dp, height = 5.dp)
.clip(CircleShape)
.background(LocalGeoColors.current.outlineVariant)
)
// The sheet closes by swiping down, tapping outside it or pressing Back.
Text(
text = stringResource(R.string.now_playing_label),
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)
)
Box(
modifier = Modifier
.padding(horizontal = 44.dp, vertical = 10.dp)
.fillMaxWidth()
.aspectRatio(1f)
.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))
.height(620.dp)
.fadeOutBottom(from = 0.5f)
) {
Image(
painter = painterResource(id = station.iconResId),
contentDescription = null,
contentScale = ContentScale.Crop,
FogLayer(
tint = accent,
intensity = if (isPlaying) 0.9f else 0.45f,
modifier = Modifier.matchParentSize()
)
Box(
modifier = Modifier
.matchParentSize()
.background(
Brush.verticalGradient(
0f to colors.background.copy(alpha = 0.35f),
0.3f to Color.Transparent
)
)
)
}
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 24.dp, vertical = 6.dp),
.align(Alignment.TopCenter)
.then(pageWidth)
.fillMaxHeight()
// The page scrolls; drags the content cannot use pull it down to close.
.nestedScroll(drag.nestedScrollConnection)
.verticalScroll(rememberScrollState())
.statusBarsPadding()
.navigationBarsPadding()
.padding(bottom = 24.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = station.name,
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
Row(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp, vertical = 4.dp),
verticalAlignment = Alignment.CenterVertically
) {
// Closed by swiping down or the system Back gesture.
Spacer(modifier = Modifier.weight(1f))
IconButton(onClick = onOpenEqualizer, modifier = Modifier.testTag("np_equalizer_toggle")) {
AppIcon(
resId = R.drawable.ic_equalizer,
contentDescription = stringResource(R.string.equalizer_content_desc),
tint = if (audioEffects.equalizerEnabled) colors.primary else colors.onSurface,
size = 22.dp
)
}
}
Spacer(modifier = Modifier.height(4.dp))
Text(
text = stationDescription(station),
style = MaterialTheme.typography.bodyMedium.copy(
fontSize = 14.sp,
color = LocalGeoColors.current.onSurfaceVariant,
textAlign = TextAlign.Center
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
StationDisc(
station = station,
isPlaying = isPlaying,
glow = false,
modifier = Modifier
.padding(top = 12.dp, bottom = 20.dp)
.fillMaxWidth(if (isTablet) 0.6f else 0.74f)
.scale(discScale)
)
Spacer(modifier = Modifier.height(10.dp))
Row(
modifier = Modifier
.clip(CircleShape)
.background(if (isPlaying) LocalGeoColors.current.primaryContainer else LocalGeoColors.current.surfaceContainer)
.border(
width = 1.dp,
color = if (isPlaying) LocalGeoColors.current.primary.copy(alpha = 0.4f) else LocalGeoColors.current.outlineVariant,
shape = CircleShape
.fillMaxWidth()
.padding(horizontal = 24.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(4.dp)
) {
Column(modifier = Modifier.weight(1f), verticalArrangement = Arrangement.spacedBy(2.dp)) {
LiveLabel(active = isPlaying)
Text(
text = station.name,
style = MaterialTheme.typography.headlineSmall.copy(
fontWeight = FontWeight.ExtraBold,
fontSize = 22.sp,
letterSpacing = (-0.4).sp,
color = colors.deepPurple
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
.padding(horizontal = 14.dp, vertical = 6.dp),
Text(
text = "${station.bitrate} • ${stationGenres(station)}",
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 12.sp,
color = colors.onSurfaceVariant
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
IconButton(
onClick = { context.shareStation(station, trackTitle) },
modifier = Modifier.testTag("np_share_btn")
) {
AppIcon(
resId = R.drawable.ic_share,
contentDescription = stringResource(R.string.share_content_desc),
tint = colors.onSurface,
size = 21.dp
)
}
val favScale by animateFloatAsState(
targetValue = if (isFavorite) 1.15f else 1f,
animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy),
label = "fav_scale"
)
IconButton(
onClick = onToggleFavorite,
modifier = Modifier
.scale(favScale)
.testTag("np_favorite_toggle")
) {
AppIcon(
resId = if (isFavorite) R.drawable.ic_heart_fill else R.drawable.ic_heart_outline,
contentDescription = stringResource(
if (isFavorite) R.string.remove_from_favorites else R.string.add_to_favorites
),
tint = if (isFavorite) colors.redFavorite else colors.onSurface,
size = 22.dp
)
}
}
Spacer(modifier = Modifier.height(22.dp))
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp)
) {
when {
isPlaying -> LiveOnAirDot()
isError -> AppIcon(
resId = R.drawable.ic_alert,
tint = LocalGeoColors.current.redFavorite,
size = 12.dp
AppIcon(resId = R.drawable.ic_music_note, tint = colors.onSurfaceVariant, size = 13.dp)
Text(
text = stringResource(R.string.now_playing_label),
style = MaterialTheme.typography.labelSmall.copy(
fontWeight = FontWeight.SemiBold,
fontSize = 10.5.sp,
letterSpacing = 1.2.sp,
color = colors.onSurfaceVariant
)
!isConnecting -> AppIcon(
resId = R.drawable.ic_sleep,
tint = LocalGeoColors.current.onSurfaceVariant,
size = 12.dp
)
else -> Box(
modifier = Modifier
.size(6.dp)
.clip(CircleShape)
.background(LocalGeoColors.current.onSurfaceVariant)
)
}
Spacer(modifier = Modifier.height(6.dp))
Text(
text = when {
isError -> playerState.message
isConnecting -> stringResource(R.string.player_connecting)
isPlaying -> stringResource(R.string.now_playing_live)
else -> stringResource(R.string.player_stopped)
!isPlaying -> stringResource(R.string.player_stopped)
else -> trackTitle ?: stationDescription(station)
},
style = MaterialTheme.typography.labelSmall.copy(
style = MaterialTheme.typography.titleMedium.copy(
fontWeight = FontWeight.SemiBold,
fontSize = 12.sp,
color = if (isPlaying) LocalGeoColors.current.deepPurple else (if (isError) LocalGeoColors.current.redFavorite else LocalGeoColors.current.onSurfaceVariant)
)
)
}
}
LiveBars(
active = isPlaying,
color = LocalGeoColors.current.primary,
fontSize = 16.sp,
lineHeight = 21.sp,
textAlign = TextAlign.Center,
color = if (isError) colors.redFavorite else colors.onSurface
),
maxLines = 2,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.align(Alignment.CenterHorizontally)
.padding(vertical = 10.dp)
.padding(horizontal = 32.dp)
.heightIn(min = 42.dp)
.testTag("np_track_title")
)
Box(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 18.dp, vertical = 8.dp),
contentAlignment = Alignment.Center
) {
Spacer(modifier = Modifier.height(18.dp))
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(14.dp)
horizontalArrangement = Arrangement.spacedBy(28.dp)
) {
Box(
IconButton(
onClick = onPrevious,
modifier = Modifier
.size(50.dp)
.clip(CircleShape)
.background(LocalGeoColors.current.surfaceContainer)
.border(1.dp, LocalGeoColors.current.outlineVariant, CircleShape)
.clickable { onOpenEqualizer() }
.testTag("np_equalizer_toggle"),
contentAlignment = Alignment.Center
) {
AppIcon(
resId = R.drawable.ic_equalizer,
contentDescription = stringResource(R.string.equalizer_content_desc),
tint = if (audioEffects.equalizerEnabled) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurfaceVariant.copy(alpha = 0.5f),
size = 20.dp
)
}
Box(
modifier = Modifier
.size(50.dp)
.clip(CircleShape)
.background(LocalGeoColors.current.surfaceContainer)
.border(1.dp, LocalGeoColors.current.outlineVariant, CircleShape)
.clickable { onPrevious() }
.testTag("np_prev_btn"),
contentAlignment = Alignment.Center
.size(52.dp)
.testTag("np_prev_btn")
) {
AppIcon(
resId = R.drawable.ic_skip_previous,
contentDescription = stringResource(R.string.previous_station_content_desc),
tint = LocalGeoColors.current.deepPurple,
size = 24.dp
tint = colors.onSurface,
size = 28.dp
)
}
Box(
modifier = Modifier
.size(72.dp)
.shadow(4.dp, RoundedCornerShape(26.dp))
.clip(RoundedCornerShape(26.dp))
.background(LocalGeoColors.current.accentLavender)
.clickable { onTogglePlay() }
.size(76.dp)
.shadow(14.dp, CircleShape, ambientColor = colors.accentLavender, spotColor = colors.accentLavender)
.clip(CircleShape)
.background(colors.accentLavender)
.clickable(role = Role.Button) { onTogglePlay() }
.testTag("np_play_btn"),
contentAlignment = Alignment.Center
) {
@@ -352,269 +364,157 @@ fun NowPlayingSheet(
modifier = Modifier
.size(32.dp)
.semantics { contentDescription = connecting },
color = LocalGeoColors.current.onAccentLavender,
color = colors.onAccentLavender,
strokeWidth = 3.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 = 34.dp
contentDescription = stringResource(
if (isPlaying) R.string.pause_content_desc else R.string.play_content_desc
),
tint = colors.onAccentLavender,
size = 32.dp
)
}
}
Box(
IconButton(
onClick = onNext,
modifier = Modifier
.size(50.dp)
.clip(CircleShape)
.background(LocalGeoColors.current.surfaceContainer)
.border(1.dp, LocalGeoColors.current.outlineVariant, CircleShape)
.clickable { onNext() }
.testTag("np_next_btn"),
contentAlignment = Alignment.Center
.size(52.dp)
.testTag("np_next_btn")
) {
AppIcon(
resId = R.drawable.ic_skip_next,
contentDescription = stringResource(R.string.next_station_content_desc),
tint = LocalGeoColors.current.deepPurple,
size = 24.dp
tint = colors.onSurface,
size = 28.dp
)
}
}
val favScale by animateFloatAsState(
targetValue = if (isFavorite) 1.12f else 1.0f,
animationSpec = spring(dampingRatio = Spring.DampingRatioMediumBouncy),
label = "fav_scale"
Spacer(modifier = Modifier.height(28.dp))
ExtraPanel(
station = station,
playerState = playerState,
activeExtraTab = activeExtraTab,
onSelectExtraTab = onSelectExtraTab,
recents = recents,
similarStations = similarStations,
onSelectStation = onSelectStation
)
Box(
modifier = Modifier
.size(50.dp)
.clip(CircleShape)
.background(if (isFavorite) LocalGeoColors.current.redFavorite.copy(alpha = 0.15f) else LocalGeoColors.current.surfaceContainer)
.border(
width = 1.2.dp,
color = if (isFavorite) LocalGeoColors.current.redFavorite else LocalGeoColors.current.outlineVariant,
shape = CircleShape
)
.scale(favScale)
.clickable { onToggleFavorite() }
.testTag("np_favorite_toggle"),
contentAlignment = Alignment.Center
}
}
}
}
}
/** Lower card of the player: recent and similar stations, station info. */
@Composable
private fun ExtraPanel(
station: RadioStation,
playerState: PlayerState,
activeExtraTab: ExtraPlayerTab,
onSelectExtraTab: (ExtraPlayerTab) -> Unit,
recents: List<RadioStation>,
similarStations: List<RadioStation>,
onSelectStation: (RadioStation) -> Unit
) {
AppIcon(
resId = if (isFavorite) R.drawable.ic_heart_fill else R.drawable.ic_heart_outline,
contentDescription = if (isFavorite) stringResource(R.string.remove_from_favorites) else stringResource(R.string.add_to_favorites),
tint = if (isFavorite) LocalGeoColors.current.redFavorite else LocalGeoColors.current.deepPurple,
size = 22.dp
)
}
}
}
Spacer(modifier = Modifier.height(16.dp))
val colors = LocalGeoColors.current
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 20.dp),
verticalArrangement = Arrangement.spacedBy(12.dp)
.padding(horizontal = 12.dp)
.clip(RoundedCornerShape(28.dp))
.background(colors.surfaceContainer)
.border(1.dp, colors.outlineVariant, RoundedCornerShape(28.dp))
.padding(vertical = 10.dp),
horizontalAlignment = Alignment.CenterHorizontally
) {
Box(
modifier = Modifier
.size(width = 40.dp, height = 4.dp)
.clip(CircleShape)
.background(colors.outlineVariant)
)
Row(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(14.dp))
.background(LocalGeoColors.current.surfaceContainer)
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(14.dp))
.padding(4.dp),
horizontalArrangement = Arrangement.spacedBy(4.dp)
.horizontalScroll(rememberScrollState())
.padding(horizontal = 12.dp, vertical = 12.dp),
horizontalArrangement = Arrangement.spacedBy(8.dp)
) {
ExtraPlayerTab.entries.forEach { tab ->
val isSelected = tab == activeExtraTab
val bg by animateColorAsState(
targetValue = if (isSelected) LocalGeoColors.current.primaryContainer else Color.Transparent,
targetValue = if (isSelected) colors.accentLavender else colors.surfaceContainerHigh,
label = "extra_tab_bg"
)
val textColor by animateColorAsState(
targetValue = if (isSelected) LocalGeoColors.current.deepPurple else LocalGeoColors.current.onSurfaceVariant,
label = "extra_tab_text"
val fg by animateColorAsState(
targetValue = if (isSelected) colors.onAccentLavender else colors.onSurfaceVariant,
label = "extra_tab_fg"
)
Box(
modifier = Modifier
.weight(1f)
.clip(RoundedCornerShape(10.dp))
.clip(CircleShape)
.background(bg)
.clickable { onSelectExtraTab(tab) }
.padding(vertical = 8.dp),
.padding(horizontal = 14.dp, vertical = 8.dp)
.testTag("extra_tab_${tab.name.lowercase()}"),
contentAlignment = Alignment.Center
) {
Text(
text = stringResource(tab.titleRes),
style = MaterialTheme.typography.labelSmall.copy(
style = MaterialTheme.typography.labelMedium.copy(
fontWeight = if (isSelected) FontWeight.Bold else FontWeight.Medium,
fontSize = 12.sp,
color = textColor
)
fontSize = 12.5.sp,
color = fg
),
maxLines = 1
)
}
}
}
Column(
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 8.dp),
verticalArrangement = Arrangement.spacedBy(2.dp)
) {
when (activeExtraTab) {
ExtraPlayerTab.RECENT -> {
if (recents.isEmpty()) {
Text(
text = stringResource(R.string.recent_empty),
style = MaterialTheme.typography.bodySmall.copy(
color = LocalGeoColors.current.onSurfaceVariant,
textAlign = TextAlign.Center
),
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp)
)
EmptyHint(stringResource(R.string.recent_empty))
} else {
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
recents.forEach { s ->
val isCur = s.id == station.id
Row(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(14.dp))
.background(if (isCur) LocalGeoColors.current.primaryContainer.copy(alpha = 0.6f) else LocalGeoColors.current.surfaceContainer)
.border(0.8.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(14.dp))
.clickable { onSelectStation(s) }
.padding(8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
Box(
modifier = Modifier
.size(40.dp)
.clip(RoundedCornerShape(10.dp))
.background(stationTileColor(s))
) {
Image(
painter = painterResource(id = s.iconResId),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
StationRow(
station = s,
isCurrent = false,
isPlaying = false,
onClick = { onSelectStation(s) }
)
}
Column(modifier = Modifier.weight(1f)) {
Row(
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(6.dp)
) {
if (isCur && isPlaying) {
LiveOnAirDot()
}
Text(
text = s.name,
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 = MaterialTheme.typography.bodySmall.copy(
fontSize = 11.5.sp,
color = LocalGeoColors.current.onSurfaceVariant
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
AppIcon(
resId = R.drawable.ic_play,
contentDescription = stringResource(R.string.play_content_desc),
tint = LocalGeoColors.current.deepPurple,
size = 18.dp
)
}
}
}
}
}
ExtraPlayerTab.SIMILAR -> {
if (similarStations.isEmpty()) {
Text(
text = stringResource(R.string.similar_empty),
style = MaterialTheme.typography.bodySmall.copy(
color = LocalGeoColors.current.onSurfaceVariant,
textAlign = TextAlign.Center
),
modifier = Modifier
.fillMaxWidth()
.padding(vertical = 16.dp)
)
EmptyHint(stringResource(R.string.similar_empty))
} else {
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
similarStations.forEach { s ->
Row(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(14.dp))
.background(LocalGeoColors.current.surfaceContainer)
.border(0.8.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(14.dp))
.clickable { onSelectStation(s) }
.padding(8.dp),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
Box(
modifier = Modifier
.size(40.dp)
.clip(RoundedCornerShape(10.dp))
.background(stationTileColor(s))
) {
Image(
painter = painterResource(id = s.iconResId),
contentDescription = null,
contentScale = ContentScale.Crop,
modifier = Modifier.matchParentSize()
StationRow(
station = s,
isCurrent = false,
isPlaying = false,
onClick = { onSelectStation(s) },
subtitle = "${stationDescription(s)} • ${stationGenres(s)}"
)
}
Column(modifier = Modifier.weight(1f)) {
Text(
text = s.name,
style = MaterialTheme.typography.bodyMedium.copy(
fontWeight = FontWeight.Bold,
color = LocalGeoColors.current.deepPurple
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Text(
text = "${stationDescription(s)} • ${stationGenres(s)}",
style = MaterialTheme.typography.bodySmall.copy(
fontSize = 11.5.sp,
color = LocalGeoColors.current.onSurfaceVariant
),
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
}
AppIcon(
resId = R.drawable.ic_play,
contentDescription = stringResource(R.string.play_content_desc),
tint = LocalGeoColors.current.deepPurple,
size = 18.dp
)
}
}
}
}
}
@@ -622,11 +522,8 @@ fun NowPlayingSheet(
Column(
modifier = Modifier
.fillMaxWidth()
.clip(RoundedCornerShape(16.dp))
.background(LocalGeoColors.current.surfaceContainer)
.border(1.dp, LocalGeoColors.current.outlineVariant, RoundedCornerShape(16.dp))
.padding(14.dp),
verticalArrangement = Arrangement.spacedBy(10.dp)
.padding(horizontal = 10.dp, vertical = 4.dp),
verticalArrangement = Arrangement.spacedBy(12.dp)
) {
InfoRow(key = stringResource(R.string.info_station), value = station.name)
InfoRow(key = stringResource(R.string.info_description), value = stationDescription(station))
@@ -647,7 +544,19 @@ fun NowPlayingSheet(
}
}
}
}
@Composable
private fun EmptyHint(text: String) {
Text(
text = text,
style = MaterialTheme.typography.bodySmall.copy(
color = LocalGeoColors.current.onSurfaceVariant,
textAlign = TextAlign.Center
),
modifier = Modifier
.fillMaxWidth()
.padding(horizontal = 16.dp, vertical = 20.dp)
)
}
@Composable
@@ -677,6 +586,22 @@ private fun InfoRow(key: String, value: String) {
}
}
private fun Context.shareStation(station: RadioStation, trackTitle: String?) {
val text = if (trackTitle != null) {
getString(R.string.share_text_track, trackTitle, station.name)
} else {
getString(R.string.share_text, station.name)
}
val send = Intent(Intent.ACTION_SEND).apply {
type = "text/plain"
putExtra(Intent.EXTRA_TEXT, text)
}
try {
startActivity(Intent.createChooser(send, null).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
} catch (_: android.content.ActivityNotFoundException) {
}
}
/**
* Offset of the now-playing sheet while it is being pulled down. Driven through nested scroll so
* the gesture works anywhere on the (scrollable) sheet once its content is scrolled to the top.
@@ -0,0 +1,132 @@
package cc.skysparkle.fogwave.ui.components
import android.content.res.Resources
import android.graphics.BitmapFactory
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.produceState
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.core.graphics.ColorUtils
import cc.skysparkle.fogwave.data.model.RadioStation
import java.util.concurrent.ConcurrentHashMap
import kotlin.math.abs
import kotlin.math.atan2
import kotlin.math.cos
import kotlin.math.sin
import kotlin.math.sqrt
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
/**
* What the UI needs to know about a station logo: its brand color (for the fog and the ring)
* and where the visible part of the logo sits, so wide wordmarks can be enlarged inside a circle.
*/
@Immutable
data class StationArt(
val accent: Color?,
val left: Float = 0f,
val top: Float = 0f,
val right: Float = 1f,
val bottom: Float = 1f
) {
/** Logos with their own square background are shown edge to edge instead of being shrunk. */
val isFullBleed: Boolean get() = right - left > 0.97f && bottom - top > 0.97f
/** Scale that fits the visible part of the logo into a circle of [fill] of its diameter. */
fun circleScale(fill: Float = 0.86f): Float {
if (isFullBleed) return 1f
val w = right - left
val h = bottom - top
return (fill / sqrt(w * w + h * h)).coerceIn(0.5f, 1.7f)
}
/** Scale that fits the visible part of the logo into [fill] of a square tile. */
fun squareScale(fill: Float = 0.84f): Float {
if (isFullBleed) return 1f
return minOf(fill / (right - left), fill / (bottom - top)).coerceIn(1f, 1.5f)
}
val centerX: Float get() = (left + right) / 2f
val centerY: Float get() = (top + bottom) / 2f
}
private val cache = ConcurrentHashMap<Int, StationArt>()
@Composable
fun rememberStationArt(station: RadioStation): StationArt? {
val resources = LocalContext.current.resources
val art by produceState(initialValue = cache[station.iconResId], station.iconResId) {
value = cache[station.iconResId] ?: withContext(Dispatchers.Default) {
analyzeLogo(resources, station.iconResId).also { cache[station.iconResId] = it }
}
}
return art
}
private fun analyzeLogo(resources: Resources, resId: Int): StationArt {
val options = BitmapFactory.Options().apply { inSampleSize = 4 }
val bitmap = BitmapFactory.decodeResource(resources, resId, options) ?: return StationArt(accent = null)
val w = bitmap.width
val h = bitmap.height
val pixels = IntArray(w * h)
bitmap.getPixels(pixels, 0, w, 0, 0, w, h)
bitmap.recycle()
var minX = w
var minY = h
var maxX = -1
var maxY = -1
// Hue is averaged on the circle, weighted by how vivid each pixel is.
var hueX = 0.0
var hueY = 0.0
var weight = 0.0
var opaque = 0
val hsl = FloatArray(3)
for (y in 0 until h) {
for (x in 0 until w) {
val c = pixels[y * w + x]
val alpha = c ushr 24
if (alpha <= 24) continue
if (x < minX) minX = x
if (x > maxX) maxX = x
if (y < minY) minY = y
if (y > maxY) maxY = y
opaque++
ColorUtils.colorToHSL(c, hsl)
val vivid = hsl[1] * (1f - abs(hsl[2] - 0.5f) * 2f)
if (vivid < 0.25f) continue
val wgt = vivid.toDouble() * (alpha / 255.0)
val rad = Math.toRadians(hsl[0].toDouble())
hueX += cos(rad) * wgt
hueY += sin(rad) * wgt
weight += wgt
}
}
if (maxX < 0) return StationArt(accent = null)
// Mostly black, white or grey logos keep the app's own blue.
val accent = if (opaque > 0 && weight / opaque > 0.08) {
var hue = Math.toDegrees(atan2(hueY, hueX)).toFloat()
if (hue < 0f) hue += 360f
// Same saturation and lightness for every station, so only the hue changes.
Color(ColorUtils.HSLToColor(floatArrayOf(hue, 0.78f, 0.6f)))
} else {
null
}
return StationArt(
accent = accent,
left = minX / w.toFloat(),
top = minY / h.toFloat(),
right = (maxX + 1) / w.toFloat(),
bottom = (maxY + 1) / h.toFloat()
)
}
/** Station color, or the app accent when the logo has none. */
fun StationArt?.accentOr(fallback: Color): Color = this?.accent ?: fallback
@@ -0,0 +1,151 @@
package cc.skysparkle.fogwave.ui.components
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.core.Animatable
import androidx.compose.animation.core.LinearEasing
import androidx.compose.animation.core.tween
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.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.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.graphics.graphicsLayer
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.AppThemeState
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 in the station's own color. Live radio has no track
* progress, so the arc slowly circles while the station plays and rests where it was when it stops.
*/
@Composable
fun StationDisc(
station: RadioStation,
isPlaying: Boolean,
modifier: Modifier = Modifier,
ringWidth: Dp = 4.dp,
ringGap: Dp = 10.dp,
glow: Boolean = true
) {
val colors = LocalGeoColors.current
val art = rememberStationArt(station)
val accent by animateColorAsState(
targetValue = art.takeIf { AppThemeState.stationFog }.accentOr(colors.primary),
animationSpec = tween(600),
label = "disc_accent"
)
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(accent.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 = accent,
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 = accent, 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
) {
// Wide wordmarks are enlarged and centered so they span the circle instead of
// floating small in the middle; square logos fill it edge to edge.
Image(
painter = painterResource(id = station.iconResId),
contentDescription = null,
contentScale = ContentScale.Fit,
modifier = Modifier
.fillMaxSize()
.graphicsLayer {
val scale = art?.circleScale() ?: 0.78f
scaleX = scale
scaleY = scale
if (art != null) {
translationX = (0.5f - art.centerX) * size.width * scale
translationY = (0.5f - art.centerY) * size.height * scale
}
}
)
}
}
}
@@ -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,237 @@
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
) {
val art = rememberStationArt(station)
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()
.graphicsLayer {
if (art != null) {
val scale = art.squareScale()
scaleX = scale
scaleY = scale
translationX = (0.5f - art.centerX) * this.size.width * scale
translationY = (0.5f - art.centerY) * this.size.height * scale
}
}
)
}
}
/** 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)
) {
Row(
.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(14.dp),
modifier = Modifier
.fillMaxWidth()
.testTag("top_brand_bar")
) {
Box(
modifier = Modifier
.size(40.dp)
.clip(RoundedCornerShape(12.dp)),
contentAlignment = Alignment.Center
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
AppIcon(
resId = R.drawable.ic_fogwave_logo,
size = 34.dp
contentDescription = stringResource(R.string.fogwave_logo_content_desc),
size = 30.dp
)
}
Column(
verticalArrangement = Arrangement.Center
) {
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.SemiBold,
fontSize = 20.sp,
letterSpacing = (-0.4).sp,
color = LocalGeoColors.current.deepPurple
fontWeight = FontWeight.Bold,
fontSize = 17.sp,
letterSpacing = 0.sp,
color = colors.deepPurple
),
modifier = Modifier.semantics { heading() }
modifier = Modifier
.fillMaxWidth()
.semantics { heading() },
textAlign = TextAlign.Center
)
}
}
}
if (showSearch) {
IconButton(
onClick = if (isSearchOpen) onCloseSearch else onOpenSearch,
modifier = Modifier
.size(40.dp)
.testTag("search_toggle")
) {
AppIcon(
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
),
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.app_subtitle),
style = MaterialTheme.typography.labelSmall.copy(
fontWeight = FontWeight.Medium,
fontSize = 11.5.sp,
color = LocalGeoColors.current.onSurfaceVariant,
letterSpacing = 0.2.sp
)
text = stringResource(R.string.search_hint),
style = MaterialTheme.typography.bodyLarge.copy(
color = colors.onSurfaceVariant,
fontSize = 15.sp
),
maxLines = 1
)
}
inner()
}
}
}
)
}
@@ -1,287 +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.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
) {
Column(
modifier = modifier
.fillMaxWidth()
.padding(horizontal = 20.dp, vertical = 6.dp)
) {
Row(
modifier = Modifier.fillMaxWidth(),
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)
)
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,
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
)
}
}
@@ -2,6 +2,7 @@ package cc.skysparkle.fogwave.ui.screens
import androidx.activity.compose.BackHandler
import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.animateColorAsState
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExitTransition
import androidx.compose.animation.ExperimentalAnimationApi
@@ -12,51 +13,68 @@ 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.LazyListState
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.MaterialTheme
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.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
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.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.HomeBackdrop
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.accentOr
import cc.skysparkle.fogwave.ui.components.rememberStationArt
import cc.skysparkle.fogwave.ui.components.stationDescription
import cc.skysparkle.fogwave.ui.theme.AppThemeState
import cc.skysparkle.fogwave.ui.theme.LocalGeoColors
import cc.skysparkle.fogwave.ui.viewmodel.RadioViewModel
@OptIn(ExperimentalAnimationApi::class)
@@ -67,6 +85,9 @@ 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("") }
val favoriteStations = remember(uiState.stations, uiState.favorites) {
uiState.stations.filter { it.id in uiState.favorites }
}
@@ -77,11 +98,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()
@@ -89,17 +115,49 @@ fun HomeScreen(
BatteryOptimizationDialog(onDismiss = { viewModel.dismissBatteryOptimizationPrompt() })
}
val radioListState = rememberLazyListState()
val accent by animateColorAsState(
// The style's colour unless the user asked for each station's own
targetValue = uiState.currentStation?.let { rememberStationArt(it) }
.takeIf { AppThemeState.stationFog }
.accentOr(LocalGeoColors.current.accentLavender),
animationSpec = tween(700),
label = "home_accent"
)
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()
Box(
modifier = Modifier
.fillMaxSize()
.background(LocalGeoColors.current.background)
) {
TopBrandBar()
HomeBackdrop(
tint = accent,
// Covered by the open player; no need to keep animating fog nobody sees.
animate = !uiState.isNowPlayingOpen,
visibility = {
if (uiState.selectedTab != AppTab.RADIO) {
0.55f
} else if (radioListState.firstVisibleItemIndex > 0) {
0.3f
} else {
1f - radioListState.firstVisibleItemScrollOffset / with(density) { 420.dp.toPx() } * 0.7f
}
}
)
Column(modifier = Modifier.fillMaxSize()) {
TopBrandBar(
showSearch = uiState.selectedTab == AppTab.RADIO,
isSearchOpen = isSearchOpen,
query = query,
onQueryChange = { query = it },
onOpenSearch = { isSearchOpen = true },
onCloseSearch = closeSearch
)
Box(modifier = Modifier.weight(1f)) {
AnimatedContent(
@@ -116,66 +174,27 @@ 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) }
AppTab.RADIO -> RadioTab(
listState = radioListState,
stations = uiState.stations,
currentStation = uiState.currentStation,
isPlaying = isPlaying,
query = query.trim(),
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(
AppTab.FAVORITES -> 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.ABOUT -> {
Column(
AppTab.ABOUT -> Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
@@ -187,7 +206,6 @@ fun HomeScreen(
}
}
}
}
Column(
modifier = Modifier
@@ -200,17 +218,19 @@ 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()
) {
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 }),
@@ -219,13 +239,23 @@ 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(
@@ -237,6 +267,7 @@ fun HomeScreen(
NowPlayingSheet(
station = uiState.currentStation,
playerState = uiState.playerState,
trackTitle = uiState.nowPlayingTitle,
isFavorite = isCurFav,
onToggleFavorite = { viewModel.toggleFavorite() },
onTogglePlay = { viewModel.togglePlay() },
@@ -284,22 +315,69 @@ fun HomeScreen(
}
}
/** Station list, filtered by the search query. */
@Composable
private fun PopoverScrim(visible: Boolean, onDismiss: () -> Unit) {
AnimatedVisibility(
visible = visible,
enter = fadeIn(tween(200)),
exit = fadeOut(tween(160))
private fun RadioTab(
listState: LazyListState,
stations: List<RadioStation>,
currentStation: RadioStation?,
isPlaying: Boolean,
query: String,
onSelectStation: (RadioStation) -> Unit,
bottomContentPadding: Dp
) {
Box(
val descriptions = stations.associate { it.id to stationDescription(it) }
val visible = remember(stations, query, descriptions) {
stations.filter { station ->
query.isEmpty() ||
station.name.contains(query, ignoreCase = true) ||
descriptions[station.id].orEmpty().contains(query, ignoreCase = true)
}
}
LazyColumn(
state = listState,
contentPadding = PaddingValues(top = 12.dp, bottom = bottomContentPadding),
modifier = Modifier.fillMaxSize()
) {
item(key = "header") {
SectionHeader(
title = stringResource(
if (query.isNotEmpty()) R.string.search_results_title else 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
.fillMaxSize()
.background(Color.Black.copy(alpha = 0.38f))
.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = onDismiss
)
.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)) }
}
}
@@ -0,0 +1,126 @@
package cc.skysparkle.fogwave.ui.theme
import android.content.Context
import android.os.Build
import androidx.annotation.StringRes
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.lerp
import cc.skysparkle.fogwave.R
/** Colour styles, the same set as in Matewave. Every style is dark. */
enum class AppStyle(@param:StringRes val titleRes: Int) {
FOGWAVE(R.string.app_style_fogwave),
LAVENDER(R.string.app_style_lavender),
PEACH(R.string.app_style_peach),
MINT(R.string.app_style_mint),
SKY(R.string.app_style_sky),
DEVICE(R.string.app_style_device);
companion object {
/** Wallpaper colours exist from Android 12. */
val deviceSupported: Boolean get() = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
val available: List<AppStyle> get() = entries.filter { it != DEVICE || deviceSupported }
}
}
/** The selected style, kept in compose state so every screen recolours at once. */
object AppThemeState {
private const val PREFS = "app_theme"
private const val KEY_STYLE = "style"
private const val KEY_STATION_FOG = "station_fog"
var style by mutableStateOf(AppStyle.FOGWAVE)
private set
var colors by mutableStateOf(DarkGeoColors)
private set
/** Fog and the disc ring take the playing station's colour instead of the style's. */
var stationFog by mutableStateOf(false)
private set
/** Reads the saved settings; call before the first frame. */
fun load(context: Context) {
val prefs = prefs(context)
val saved = prefs.getString(KEY_STYLE, null)
stationFog = prefs.getBoolean(KEY_STATION_FOG, false)
apply(context, AppStyle.entries.firstOrNull { it.name == saved } ?: AppStyle.FOGWAVE)
}
fun select(context: Context, style: AppStyle) {
prefs(context).edit().putString(KEY_STYLE, style.name).apply()
apply(context, style)
}
fun setStationFog(context: Context, enabled: Boolean) {
prefs(context).edit().putBoolean(KEY_STATION_FOG, enabled).apply()
stationFog = enabled
}
/** Colours of a style, also used for the previews in the picker. */
fun colorsFor(context: Context, style: AppStyle): GeoColors = when (style) {
AppStyle.FOGWAVE -> DarkGeoColors
AppStyle.LAVENDER -> styleColors(Color(0xFFC8B6FF), Color(0xFF1E1630), Color(0xFF0F0E14), Color(0xFF1A1822), Color(0xFF25222F))
AppStyle.PEACH -> styleColors(Color(0xFFFFB59E), Color(0xFF2A1710), Color(0xFF12100E), Color(0xFF1D1A17), Color(0xFF28231F))
AppStyle.MINT -> styleColors(Color(0xFF9EE7C8), Color(0xFF0F231B), Color(0xFF0D110F), Color(0xFF171C1A), Color(0xFF202724))
AppStyle.SKY -> styleColors(Color(0xFFA5CBFF), Color(0xFF0F1A2A), Color(0xFF0D1014), Color(0xFF171B21), Color(0xFF20252D))
AppStyle.DEVICE -> deviceColors(context)
}
private fun apply(context: Context, requested: AppStyle) {
val style = if (requested == AppStyle.DEVICE && !AppStyle.deviceSupported) AppStyle.FOGWAVE else requested
this.style = style
colors = colorsFor(context, style)
}
private fun deviceColors(context: Context): GeoColors {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S) return DarkGeoColors
val scheme = dynamicDarkColorScheme(context)
return styleColors(
accent = scheme.primary,
onAccent = scheme.onPrimary,
background = scheme.background,
surface1 = scheme.surfaceContainer,
surface2 = scheme.surfaceContainerHigh
)
}
private fun prefs(context: Context) =
context.applicationContext.getSharedPreferences(PREFS, Context.MODE_PRIVATE)
}
/**
* Builds the full set from a style's few colours. Pastel styles use their accent for buttons too,
* with dark text on top, like in Matewave. The live dot and the favourite heart keep their own red.
*/
private fun styleColors(
accent: Color,
onAccent: Color,
background: Color,
surface1: Color,
surface2: Color
): GeoColors = DarkGeoColors.copy(
background = background,
surface = background,
surfaceContainer = surface1,
surfaceContainerHigh = surface2,
onSurfaceVariant = lerp(Color(0xFF9AA0AA), accent, 0.12f),
outline = lerp(surface2, Color.White, 0.3f),
outlineVariant = lerp(surface2, Color.White, 0.06f),
primary = accent,
onPrimary = onAccent,
primaryContainer = lerp(background, accent, 0.22f),
onPrimaryContainer = lerp(accent, Color.White, 0.75f),
secondary = lerp(accent, Color.White, 0.4f),
onSecondary = onAccent,
secondaryContainer = lerp(surface2, accent, 0.18f),
onSecondaryContainer = lerp(accent, Color.White, 0.75f),
accentLavender = accent,
onAccentLavender = onAccent,
deepPurple = lerp(Color.White, accent, 0.06f)
)
@@ -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 }
@@ -1,12 +1,13 @@
package cc.skysparkle.fogwave.ui.theme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.remember
private val DarkColorScheme = with(DarkGeoColors) {
darkColorScheme(
private fun GeoColors.toColorScheme(): ColorScheme = darkColorScheme(
primary = primary,
onPrimary = onPrimary,
primaryContainer = primaryContainer,
@@ -23,11 +24,13 @@ private val DarkColorScheme = with(DarkGeoColors) {
onSurfaceVariant = onSurfaceVariant,
outline = outline
)
}
/** Always dark; the colours follow the style picked in About (see [AppThemeState]). */
@Composable
fun FogwaveTheme(content: @Composable () -> Unit) {
CompositionLocalProvider(LocalGeoColors provides DarkGeoColors) {
MaterialTheme(colorScheme = DarkColorScheme, typography = Typography, content = content)
val colors = AppThemeState.colors
val scheme = remember(colors) { colors.toColorScheme() }
CompositionLocalProvider(LocalGeoColors provides colors) {
MaterialTheme(colorScheme = scheme, typography = Typography, content = content)
}
}
@@ -8,9 +8,7 @@ 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.repository.RadioRepository
import cc.skysparkle.fogwave.player.AudioEffectsController
import cc.skysparkle.fogwave.player.AudioEffectsState
@@ -32,15 +30,13 @@ 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 audioEffects: AudioEffectsState = AudioEffectsState(),
val isMiniPlayerHidden: Boolean = false,
val unseenFavoritesCount: Int = 0
val unseenFavoritesCount: Int = 0,
val nowPlayingTitle: String? = null
)
class RadioViewModel(application: Application) : AndroidViewModel(application) {
@@ -60,7 +56,6 @@ 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 _isMiniPlayerHidden = MutableStateFlow(false)
@@ -83,16 +78,14 @@ 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
) { params ->
val current = params[0] as? RadioStation
val pState = params[1] as PlayerState
@@ -101,18 +94,16 @@ 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?
val byId = orderedStations.associateBy { it.id }
val recentsList = recentsIds.mapNotNull { byId[it] }
@@ -124,15 +115,13 @@ 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
)
}.stateIn(
scope = viewModelScope,
@@ -141,8 +130,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 }
)
@@ -152,9 +139,12 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
viewModelScope.launch {
playerManager.currentMediaId.collect { id ->
if (id != null && id != _currentStation.value?.id) {
// Switched outside the app (notification, headset, Android Auto): count it like a tap.
stations.find { it.id == id }?.let { onAir ->
_currentStation.value = onAir
repository.setLastStationId(onAir.id)
repository.pushRecent(onAir.id)
repository.recordStationPlayed(onAir.id)
}
}
}
@@ -263,30 +253,17 @@ class RadioViewModel(application: Application) : AndroidViewModel(application) {
AudioEffectsController.setLoudnessEnabled(enabled)
}
fun setLoudnessGain(gainMillibel: Float) {
AudioEffectsController.setLoudnessGain(gainMillibel)
}
fun setDynamicsProcessingEnabled(enabled: Boolean) {
AudioEffectsController.setDynamicsProcessingEnabled(enabled)
}
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 +281,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
}
Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 270 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 890 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 918 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 430 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 756 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 884 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 930 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 868 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

+12
View File
@@ -0,0 +1,12 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#00000000"
android:strokeColor="#FFFFFFFF"
android:strokeWidth="2"
android:strokeLineCap="round"
android:pathData="M6,6L18,18 M18,6L6,18" />
</vector>
+12
View File
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- MingCute icon "check_line" (Apache License 2.0) -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:fillType="evenOdd"
android:pathData="M21.192 5.465a1 1 0 0 1 0 1.414L9.95 18.122a1.1 1.1 0 0 1-1.556 0l-5.586-5.586a1 1 0 1 1 1.415-1.415l4.95 4.95L19.777 5.465a1 1 0 0 1 1.414 0Z" />
</vector>
+11
View File
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- MingCute icon "code_line" (Apache License 2.0) -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M14.486 3.143a1 1 0 0 1 .692 1.233l-4.43 15.788a1 1 0 0 1-1.926-.54l4.43-15.788a1 1 0 0 1 1.234-.693M7.207 7.05a1 1 0 0 1 0 1.414L3.672 12l3.535 3.535a1 1 0 1 1-1.414 1.415L1.55 12.707a1 1 0 0 1 0-1.414L5.793 7.05a1 1 0 0 1 1.414 0m9.586 1.414a1 1 0 1 1 1.414-1.414l4.243 4.243a1 1 0 0 1 0 1.414l-4.243 4.243a1 1 0 0 1-1.414-1.415L20.328 12z" />
</vector>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- MingCute icon "copyright_line" (Apache License 2.0) -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M12 2c5.523 0 10 4.477 10 10s-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2m0 2a8 8 0 1 0 0 16 8 8 0 0 0 0-16m0 3a4.99 4.99 0 0 1 3.75 1.692 1 1 0 1 1-1.5 1.324 3 3 0 1 0 0 3.968 1 1 0 1 1 1.5 1.324A5 5 0 1 1 12 7" />
</vector>
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- MingCute icon "external_link_line" (Apache License 2.0) -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="#FFFFFFFF"
android:pathData="M11 6a1 1 0 1 1 0 2H5v11h11v-6a1 1 0 1 1 2 0v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2zm9-3a1 1 0 0 1 1 1v5a1 1 0 1 1-2 0V6.414l-8.293 8.293a1 1 0 0 1-1.414-1.414L17.586 5H15a1 1 0 1 1 0-2Z" />
</vector>

Some files were not shown because too many files have changed in this diff Show More