1 /*
2 * Copyright (C) 2024 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.android.systemui.volume.dialog.shared.model
18
19 import android.content.Context
20 import androidx.annotation.StringRes
21 import com.android.systemui.plugins.VolumeDialogController
22
23 /** Models a state of an audio stream of the Volume Dialog. */
24 data class VolumeDialogStreamModel(
25 val stream: Int,
26 val isDynamic: Boolean = false,
27 val isActive: Boolean,
28 val level: Int = 0,
29 val levelMin: Int = 0,
30 val levelMax: Int = 0,
31 val muted: Boolean = false,
32 val muteSupported: Boolean = false,
33 /** You likely need to use [streamLabel] instead. */
34 @StringRes val name: Int = 0,
35 /** You likely need to use [streamLabel] instead. */
36 val remoteLabel: String? = null,
37 val routedToBluetooth: Boolean = false,
38 ) {
39 constructor(
40 stream: Int,
41 isActive: Boolean,
42 legacyState: VolumeDialogController.StreamState,
43 ) : this(
44 stream = stream,
45 isActive = isActive,
46 isDynamic = legacyState.dynamic,
47 level = legacyState.level,
48 levelMin = legacyState.levelMin,
49 levelMax = legacyState.levelMax,
50 muted = legacyState.muted,
51 muteSupported = legacyState.muteSupported,
52 name = legacyState.name,
53 remoteLabel = legacyState.remoteLabel,
54 routedToBluetooth = legacyState.routedToBluetooth,
55 )
56 }
57
streamLabelnull58 fun VolumeDialogStreamModel.streamLabel(context: Context): String {
59 if (remoteLabel != null) {
60 return remoteLabel
61 }
62 return context.resources.getString(name)
63 }
64