Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7ff135d authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Remove ringer repository" into main

parents 8baa2e78 25908d56
Loading
Loading
Loading
Loading
+0 −37
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.volume.dialog.ringer.data

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.volume.dialog.ringer.shared.model.VolumeDialogRingerModel
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.update

/** Stores the state of volume dialog ringer model */
@SysUISingleton
class VolumeDialogRingerRepository @Inject constructor() {

    private val mutableRingerModel = MutableStateFlow<VolumeDialogRingerModel?>(null)
    val ringerModel: Flow<VolumeDialogRingerModel> = mutableRingerModel.filterNotNull()

    fun updateRingerModel(update: (current: VolumeDialogRingerModel?) -> VolumeDialogRingerModel) {
        mutableRingerModel.update(update)
    }
}
+7 −11
Original line number Diff line number Diff line
@@ -25,15 +25,15 @@ import com.android.settingslib.volume.shared.model.RingerMode
import com.android.systemui.plugins.VolumeDialogController
import com.android.systemui.volume.dialog.dagger.scope.VolumeDialog
import com.android.systemui.volume.dialog.domain.interactor.VolumeDialogStateInteractor
import com.android.systemui.volume.dialog.ringer.data.VolumeDialogRingerRepository
import com.android.systemui.volume.dialog.ringer.shared.model.VolumeDialogRingerModel
import com.android.systemui.volume.dialog.shared.model.VolumeDialogStateModel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.stateIn

/** Exposes [VolumeDialogRingerModel]. */
@VolumeDialog
@@ -43,17 +43,13 @@ constructor(
    @VolumeDialog private val coroutineScope: CoroutineScope,
    volumeDialogStateInteractor: VolumeDialogStateInteractor,
    private val controller: VolumeDialogController,
    private val repository: VolumeDialogRingerRepository,
) {

    val ringerModel: Flow<VolumeDialogRingerModel> = repository.ringerModel

    init {
    val ringerModel: Flow<VolumeDialogRingerModel> =
        volumeDialogStateInteractor.volumeDialogState
            .mapNotNull { state -> toRingerModel(state) }
            .onEach { ringerModel -> repository.updateRingerModel { ringerModel } }
            .launchIn(coroutineScope)
    }
            .mapNotNull { toRingerModel(it) }
            .stateIn(coroutineScope, SharingStarted.Eagerly, null)
            .filterNotNull()

    private fun toRingerModel(state: VolumeDialogStateModel): VolumeDialogRingerModel? {
        return state.streamModels[AudioManager.STREAM_RING]?.let {
+0 −21
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.volume.dialog.ringer.data

import com.android.systemui.kosmos.Kosmos

val Kosmos.volumeDialogRingerRepository by Kosmos.Fixture { VolumeDialogRingerRepository() }
+0 −2
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.plugins.volumeDialogController
import com.android.systemui.volume.dialog.domain.interactor.volumeDialogStateInteractor
import com.android.systemui.volume.dialog.ringer.data.volumeDialogRingerRepository

val Kosmos.volumeDialogRingerInteractor by
    Kosmos.Fixture {
@@ -28,6 +27,5 @@ val Kosmos.volumeDialogRingerInteractor by
            coroutineScope = applicationCoroutineScope,
            volumeDialogStateInteractor = volumeDialogStateInteractor,
            controller = volumeDialogController,
            repository = volumeDialogRingerRepository,
        )
    }