Initial Commit

This commit is contained in:
Ashin Walpola
2026-06-03 14:51:31 +02:00
parent ee122765e1
commit ae17d4fcba
74 changed files with 7126 additions and 0 deletions
@@ -0,0 +1,38 @@
package com.hawhamburg.micr0bu.service
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
/**
* Process-level singleton that bridges [TripRecordingService] (writes) and
* [TripRecordingViewModel] (reads) without requiring a bound service.
*
* The service updates [state] on every relevant change; the ViewModel collects
* it as a cold StateFlow.
*/
object TripServiceBus {
data class State(
val isRecording: Boolean = false,
val currentTripId: Long = -1L,
val elapsedSeconds: Long = 0L,
val brakingCount: Int = 0,
val turningCount: Int = 0,
val stoppingCount: Int = 0,
val currentSpeedMs: Float = 0f,
)
private val _state = MutableStateFlow(State())
val state: StateFlow<State> = _state.asStateFlow()
/** Called exclusively from [TripRecordingService]. */
internal fun update(transform: State.() -> State) {
_state.value = _state.value.transform()
}
/** Resets to idle — called when recording stops. */
internal fun reset() {
_state.value = State()
}
}