summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioRepository.kt5
-rw-r--r--packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt16
2 files changed, 17 insertions, 4 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioRepository.kt b/packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioRepository.kt
index 8204569ce2f8..20b949f4a30f 100644
--- a/packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioRepository.kt
+++ b/packages/SettingsLib/src/com/android/settingslib/volume/data/repository/AudioRepository.kt
@@ -37,6 +37,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.callbackFlow
+import kotlinx.coroutines.flow.conflate
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterIsInstance
@@ -161,6 +162,7 @@ class AudioRepositoryImpl(
},
volumeSettingChanges(audioStream),
)
+ .conflate()
.map { getCurrentAudioStream(audioStream) }
.onStart { emit(getCurrentAudioStream(audioStream)) }
.flowOn(backgroundCoroutineContext)
@@ -184,10 +186,11 @@ class AudioRepositoryImpl(
}
}
- override suspend fun setVolume(audioStream: AudioStream, volume: Int) =
+ override suspend fun setVolume(audioStream: AudioStream, volume: Int) {
withContext(backgroundCoroutineContext) {
audioManager.setStreamVolume(audioStream.value, volume, 0)
}
+ }
override suspend fun setMuted(audioStream: AudioStream, isMuted: Boolean): Boolean {
return withContext(backgroundCoroutineContext) {
diff --git a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt
index 850162e65aa6..c18573ed1545 100644
--- a/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/volume/panel/component/volume/slider/ui/viewmodel/AudioStreamSliderViewModel.kt
@@ -32,9 +32,13 @@ import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlin.math.roundToInt
import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
+import kotlinx.coroutines.flow.filterNotNull
+import kotlinx.coroutines.flow.launchIn
+import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
@@ -49,6 +53,7 @@ constructor(
private val uiEventLogger: UiEventLogger,
) : SliderViewModel {
+ private val volumeChanges = MutableStateFlow<Int?>(null)
private val streamsAffectedByRing =
setOf(
AudioManager.STREAM_RING,
@@ -104,12 +109,17 @@ constructor(
}
.stateIn(coroutineScope, SharingStarted.Eagerly, SliderState.Empty)
+ init {
+ volumeChanges
+ .filterNotNull()
+ .onEach { audioVolumeInteractor.setVolume(audioStream, it) }
+ .launchIn(coroutineScope)
+ }
+
override fun onValueChanged(state: SliderState, newValue: Float) {
val audioViewModel = state as? State
audioViewModel ?: return
- coroutineScope.launch {
- audioVolumeInteractor.setVolume(audioStream, newValue.roundToInt())
- }
+ volumeChanges.tryEmit(newValue.roundToInt())
}
override fun onValueChangeFinished() {