Better disabling of unused reaction modules.

This commit is contained in:
darken
2022-01-18 14:37:53 +01:00
parent 0c95205671
commit 17d2ebf863
2 changed files with 8 additions and 6 deletions
@@ -21,7 +21,8 @@ class AutoConnect @Inject constructor(
private val reactionSettings: ReactionSettings
) {
fun monitor(): Flow<Unit> = podMonitor.mainDevice
fun monitor(): Flow<Unit> = reactionSettings.autoConnect.flow
.flatMapLatest { if (it) podMonitor.mainDevice else emptyFlow() }
.filterNotNull()
.distinctUntilChanged()
.map { podDevice ->
@@ -11,10 +11,7 @@ import eu.darken.capod.common.flow.withPrevious
import eu.darken.capod.monitor.core.PodMonitor
import eu.darken.capod.pods.core.HasEarDetection
import eu.darken.capod.reaction.core.ReactionSettings
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.*
import javax.inject.Inject
@Reusable
@@ -25,7 +22,11 @@ class PlayPause @Inject constructor(
private val mediaControl: MediaControl,
) {
fun monitor() = bluetoothManager.connectedDevices()
fun monitor() = combine(
reactionSettings.autoPlay.flow,
reactionSettings.autoPause.flow,
) { play, pause -> play || pause }
.flatMapLatest { if (it) bluetoothManager.connectedDevices() else emptyFlow() }
.flatMapLatest {
if (it.isEmpty()) {
log(TAG) { "No known devices connected." }