4.7 KiB
4.7 KiB
Settings Panel Design
Overview
Add four new feature sections to the existing SettingsScreen: SomaFM quality preference, now-playing history file logging, reset customizations, and restart app.
1. SomaFM Quality Preference
Data Model
New station_streams table:
| Column | Type | Notes |
|---|---|---|
| id | Long PK | Auto-generated |
| stationId | Long FK | References stations.id |
| bitrate | Int | 128 or 256 |
| ssl | Boolean | true = HTTPS, false = HTTP |
| url | String | Full stream URL |
URL patterns:
- SSL:
https://ice1.somafm.com/{streamId}-{bitrate}-mp3 - Non-SSL:
http://ice1.somafm.com/{streamId}-{bitrate}-mp3
Stations with only 128kbps support get 2 rows; stations with 256kbps get 4 rows.
Preference Storage
- Global preference in
RadioPreferences: ordered list stored as JSON string, e.g.["256-ssl","256-nossl","128-ssl","128-nossl"]. Users can reorder in settings. - Per-station override: nullable
qualityOverridecolumn onStation. When non-null, overrides the global preference with the same JSON format. When null, uses the global default.
Playback Resolution
New StreamResolver utility:
- Queries
station_streamsfor the station's available streams. - Orders them by the applicable preference (per-station override or global default).
- Returns the first URL. On connection failure,
AudioEngine/RadioPlaybackServicetries the next URL in the chain.
Non-SomaFM stations use station.url directly — no streams table involvement.
Settings UI
- Draggable list showing the 4 quality tiers in current preference order
- Per-station: accessible from station long-press menu or edit dialog
2. Now Playing History (File Logging)
Preference Keys in RadioPreferences
historyEnabled: Boolean— defaultfalsehistoryFormat: String—"csv","json", or"plain"(default"csv")historyFilePath: String— default: app's external files directory
File Formats
- CSV:
"2026-03-10 09:30:15","Groove Salad","Tycho","A Walk" - JSON lines:
{"timestamp":"2026-03-10T09:30:15","station":"Groove Salad","artist":"Tycho","title":"A Walk"} - Plain text:
2026-03-10 09:30 | Groove Salad | Tycho - A Walk
File names: now-playing-history.csv, .jsonl, or .txt based on format.
Writer
NowPlayingHistoryWriter class:
- Called from
RadioPlaybackServiceaftermetadataSnapshotDao.insert()when ICY metadata changes - Checks
historyEnabledpreference; if true, appends a line to the file in the chosen format - Thread-safe file writes on
Dispatchers.IO
Settings UI
- Toggle: "Enable Now Playing History"
- Dropdown/chips: format selector (CSV, JSON, Plain Text)
- Current path display + "Choose Directory" button (launches
ACTION_OPEN_DOCUMENT_TREE)
3. Reset Customizations
Behavior
A "Reset All Customizations" button with a companion toggle: "Also delete saved stations/playlists".
Confirmation dialog adapts its message based on the toggle state.
Always resets (in a single DB transaction):
starred = falseon all stationssortOrderrestored to original seed indexisHidden = falseon all stationsqualityOverride = nullon all stations
If toggle is on, also:
- Deletes all non-built-in playlists and their stations
Error handling:
- Wrapped in try/catch
- Shows a Toast on failure
- Fails gracefully — partial reset should not corrupt state (transaction rollback)
4. Restart App
Behavior
A "Restart App" button that:
- Calls
RadioController.stop()for graceful shutdown - Waits up to 3 seconds for
PlaybackState.Idle - If still not idle, force-stops the service via
stopService() - Restarts: launches
MainActivitywithFLAG_ACTIVITY_NEW_TASK | FLAG_ACTIVITY_CLEAR_TASK, thenRuntime.getRuntime().exit(0)
No external libraries needed.
Files Affected
New files:
data/model/StationStream.kt— Room entitydata/db/StationStreamDao.kt— DAOservice/StreamResolver.kt— URL resolution logicdata/logging/NowPlayingHistoryWriter.kt— file logger
Modified files:
data/model/Station.kt— addqualityOverridecolumndata/db/RadioDatabase.kt— add entity, bump version, add migrationdata/db/SomaFmSeedData.kt— seedstation_streamsrowsdata/prefs/RadioPreferences.kt— add quality, history prefsservice/RadioPlaybackService.kt— useStreamResolver, call history writerui/screens/settings/SettingsScreen.kt— add all 4 new sectionsui/screens/settings/SettingsViewModel.kt— add reset/restart/quality/history logicRadioApplication.kt— expose history writer