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

Commit e8b7d81f authored by Anton Potapov's avatar Anton Potapov
Browse files

Add base logic for the Volume Dialog sliders.

This change creates barebone interactors, viewmodel and viewbinders for
the future changes to implement.

Flag: com.android.systemui.volume_redesign
Test: passes presubmits
Bug: 369992924
Change-Id: Ib701f846e2ea1c5371ae9d714cbf6eafeb1c518b
parent fb9677f2
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -14,7 +14,6 @@

package com.android.systemui.plugins;

import android.annotation.IntegerRes;
import android.content.ComponentName;
import android.media.AudioManager;
import android.media.AudioSystem;
@@ -22,6 +21,8 @@ import android.os.Handler;
import android.os.VibrationEffect;
import android.util.SparseArray;

import androidx.annotation.StringRes;

import com.android.systemui.plugins.VolumeDialogController.Callbacks;
import com.android.systemui.plugins.VolumeDialogController.State;
import com.android.systemui.plugins.VolumeDialogController.StreamState;
@@ -90,7 +91,7 @@ public interface VolumeDialogController {
        public int levelMax;
        public boolean muted;
        public boolean muteSupported;
        public @IntegerRes int name;
        public @StringRes int name;
        public String remoteLabel;
        public boolean routedToBluetooth;

+2 −3
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ import android.view.accessibility.CaptioningManager;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import androidx.lifecycle.Observer;

import com.android.internal.annotations.GuardedBy;
@@ -110,8 +109,8 @@ public class VolumeDialogControllerImpl implements VolumeDialogController, Dumpa
    // It is safe to use 99 as the broadcast stream now. There are only 10+ default audio
    // streams defined in AudioSystem for now and audio team is in the middle of restructure,
    // no new default stream is preferred.
    @VisibleForTesting static final int DYNAMIC_STREAM_BROADCAST = 99;
    private static final int DYNAMIC_STREAM_REMOTE_START_INDEX = 100;
    public static final int DYNAMIC_STREAM_BROADCAST = 99;
    public static final int DYNAMIC_STREAM_REMOTE_START_INDEX = 100;
    private static final AudioAttributes SONIFICIATION_VIBRATION_ATTRIBUTES =
            new AudioAttributes.Builder()
                    .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
+2 −2
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import com.android.systemui.plugins.VolumeDialogController

/** Models a state of the Volume Dialog. */
data class VolumeDialogStateModel(
    val states: Map<Int, VolumeDialogStreamStateModel>,
    val states: Map<Int, VolumeDialogStreamModel>,
    val ringerModeInternal: Int = 0,
    val ringerModeExternal: Int = 0,
    val zenMode: Int = 0,
@@ -39,7 +39,7 @@ data class VolumeDialogStateModel(
    constructor(
        legacyState: VolumeDialogController.State
    ) : this(
        states = legacyState.states.mapToMap { VolumeDialogStreamStateModel(it) },
        states = legacyState.states.mapToMap { VolumeDialogStreamModel(it) },
        ringerModeInternal = legacyState.ringerModeInternal,
        ringerModeExternal = legacyState.ringerModeExternal,
        zenMode = legacyState.zenMode,
+3 −3
Original line number Diff line number Diff line
@@ -16,18 +16,18 @@

package com.android.systemui.volume.dialog.domain.model

import android.annotation.IntegerRes
import androidx.annotation.StringRes
import com.android.systemui.plugins.VolumeDialogController

/** Models a state of an audio stream of the Volume Dialog. */
data class VolumeDialogStreamStateModel(
data class VolumeDialogStreamModel(
    val isDynamic: Boolean = false,
    val level: Int = 0,
    val levelMin: Int = 0,
    val levelMax: Int = 0,
    val muted: Boolean = false,
    val muteSupported: Boolean = false,
    @IntegerRes val name: Int = 0,
    @StringRes val name: Int = 0,
    val remoteLabel: String? = null,
    val routedToBluetooth: Boolean = false,
) {
+54 −0
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.sliders.domain.interactor

import com.android.systemui.plugins.VolumeDialogController
import com.android.systemui.volume.dialog.dagger.scope.VolumeDialogScope
import com.android.systemui.volume.dialog.domain.interactor.VolumeDialogStateInteractor
import com.android.systemui.volume.dialog.domain.model.VolumeDialogStreamModel
import com.android.systemui.volume.dialog.sliders.domain.model.VolumeDialogSliderType
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.mapNotNull

/** Operates a state of particular slider of the Volume Dialog. */
class VolumeDialogSliderInteractor
@AssistedInject
constructor(
    @Assisted private val sliderType: VolumeDialogSliderType,
    volumeDialogStateInteractor: VolumeDialogStateInteractor,
    private val volumeDialogController: VolumeDialogController,
) {

    val slider: Flow<VolumeDialogStreamModel> =
        volumeDialogStateInteractor.volumeDialogState.mapNotNull {
            it.states[sliderType.audioStream]
        }

    fun setStreamVolume(userLevel: Int) {
        volumeDialogController.setStreamVolume(sliderType.audioStream, userLevel)
    }

    @VolumeDialogScope
    @AssistedFactory
    interface Factory {

        fun create(sliderType: VolumeDialogSliderType): VolumeDialogSliderInteractor
    }
}
Loading