Initial release of GPS2Audio

This commit is contained in:
Marcel Mayer
2026-05-05 20:54:05 +02:00
commit b2aa1c167c
48 changed files with 11570 additions and 0 deletions
@@ -0,0 +1,67 @@
package de.waypointaudio.data
import android.content.Context
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.intPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
/**
* Globale Audio-Routing-Einstellungen für Live/PTT.
*
* Gerätekennungen (AudioDeviceInfo.id) sind Sitzungs-spezifisch und können sich nach
* einem Neustart oder nach dem Trennen/Verbinden von Bluetooth-Geräten ändern.
* Wenn ein gespeichertes Gerät nicht mehr verfügbar ist, wird automatisch der
* Systemstandard verwendet.
*
* @param selectedInputDeviceId ID des Eingabegeräts, null = Systemstandard
* @param selectedOutputDeviceId ID des Ausgabegeräts, null = Systemstandard
*/
data class AudioRoutingSettings(
val selectedInputDeviceId: Int? = null,
val selectedOutputDeviceId: Int? = null
)
private val Context.audioRoutingDataStore by preferencesDataStore(name = "audio_routing_settings")
/**
* Persistenz-Schicht für Audio-Routing-Einstellungen via DataStore.
*/
class AudioRoutingStore(private val context: Context) {
private companion object {
val KEY_INPUT_DEVICE_ID = intPreferencesKey("selected_input_device_id")
val KEY_OUTPUT_DEVICE_ID = intPreferencesKey("selected_output_device_id")
// Sentinel: -1 means "use system default" (null cannot be stored as Int)
const val NO_DEVICE = -1
}
val settings: Flow<AudioRoutingSettings> = context.audioRoutingDataStore.data
.map { prefs ->
AudioRoutingSettings(
selectedInputDeviceId = prefs[KEY_INPUT_DEVICE_ID].takeIf { it != null && it != NO_DEVICE },
selectedOutputDeviceId = prefs[KEY_OUTPUT_DEVICE_ID].takeIf { it != null && it != NO_DEVICE }
)
}
suspend fun save(settings: AudioRoutingSettings) {
context.audioRoutingDataStore.edit { prefs ->
prefs[KEY_INPUT_DEVICE_ID] = settings.selectedInputDeviceId ?: NO_DEVICE
prefs[KEY_OUTPUT_DEVICE_ID] = settings.selectedOutputDeviceId ?: NO_DEVICE
}
}
suspend fun clearInputDevice() {
context.audioRoutingDataStore.edit { prefs ->
prefs[KEY_INPUT_DEVICE_ID] = NO_DEVICE
}
}
suspend fun clearOutputDevice() {
context.audioRoutingDataStore.edit { prefs ->
prefs[KEY_OUTPUT_DEVICE_ID] = NO_DEVICE
}
}
}