Task 8: Wire StationPreference into StreamResolver
- Add StationPreferenceDao to StreamResolver constructor - Check station_preferences before station.qualityOverride / global prefs - Mock stationPrefDao in StreamResolverTest, add precedence test Made-with: Cursor
This commit is contained in:
@@ -36,7 +36,7 @@ class RadioApplication : Application() {
|
||||
}
|
||||
|
||||
val streamResolver: StreamResolver by lazy {
|
||||
StreamResolver(database.stationStreamDao(), preferences)
|
||||
StreamResolver(database.stationStreamDao(), preferences, database.stationPreferenceDao())
|
||||
}
|
||||
|
||||
val historyWriter: NowPlayingHistoryWriter by lazy {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package xyz.cottongin.radio247.service
|
||||
|
||||
import xyz.cottongin.radio247.data.db.StationPreferenceDao
|
||||
import xyz.cottongin.radio247.data.db.StationStreamDao
|
||||
import xyz.cottongin.radio247.data.model.Station
|
||||
import xyz.cottongin.radio247.data.prefs.RadioPreferences
|
||||
@@ -8,7 +9,8 @@ import org.json.JSONArray
|
||||
|
||||
class StreamResolver(
|
||||
private val streamDao: StationStreamDao,
|
||||
private val preferences: RadioPreferences
|
||||
private val preferences: RadioPreferences,
|
||||
private val stationPreferenceDao: StationPreferenceDao
|
||||
) {
|
||||
/**
|
||||
* Returns an ordered list of stream URLs to try for the given station.
|
||||
@@ -19,7 +21,11 @@ class StreamResolver(
|
||||
val streams = streamDao.getStreamsForStation(station.id)
|
||||
if (streams.isEmpty()) return listOf(station.url)
|
||||
|
||||
val order = parseOrder(station.qualityOverride ?: preferences.qualityPreference.first())
|
||||
val pref = stationPreferenceDao.getByStationId(station.id)
|
||||
val qualityJson = pref?.qualityOverride
|
||||
?: station.qualityOverride
|
||||
?: preferences.qualityPreference.first()
|
||||
val order = parseOrder(qualityJson)
|
||||
val sorted = streams.sortedBy { stream ->
|
||||
val key = "${stream.bitrate}-${if (stream.ssl) "ssl" else "nossl"}"
|
||||
val idx = order.indexOf(key)
|
||||
|
||||
Reference in New Issue
Block a user