1 /*
2  * Copyright (C) 2023 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 
18 package com.android.systemui.statusbar.notification.stack.domain.interactor
19 
20 import android.content.Context
21 import com.android.systemui.R
22 import com.android.systemui.common.ui.data.repository.ConfigurationRepository
23 import javax.inject.Inject
24 import kotlinx.coroutines.flow.Flow
25 import kotlinx.coroutines.flow.distinctUntilChanged
26 import kotlinx.coroutines.flow.map
27 import kotlinx.coroutines.flow.onStart
28 
29 /** Encapsulates business-logic specifically related to the shared notification stack container. */
30 class SharedNotificationContainerInteractor
31 @Inject
32 constructor(
33     configurationRepository: ConfigurationRepository,
34     private val context: Context,
35 ) {
36     val configurationBasedDimensions: Flow<ConfigurationBasedDimensions> =
37         configurationRepository.onAnyConfigurationChange
38             .onStart { emit(Unit) }
39             .map { _ ->
40                 with(context.resources) {
41                     ConfigurationBasedDimensions(
42                         useSplitShade = getBoolean(R.bool.config_use_split_notification_shade),
43                         useLargeScreenHeader =
44                             getBoolean(R.bool.config_use_large_screen_shade_header),
45                         marginHorizontal =
46                             getDimensionPixelSize(R.dimen.notification_panel_margin_horizontal),
47                         marginBottom =
48                             getDimensionPixelSize(R.dimen.notification_panel_margin_bottom),
49                         marginTop = getDimensionPixelSize(R.dimen.notification_panel_margin_top),
50                         marginTopLargeScreen =
51                             getDimensionPixelSize(R.dimen.large_screen_shade_header_height),
52                     )
53                 }
54             }
55             .distinctUntilChanged()
56 
57     data class ConfigurationBasedDimensions(
58         val useSplitShade: Boolean,
59         val useLargeScreenHeader: Boolean,
60         val marginHorizontal: Int,
61         val marginBottom: Int,
62         val marginTop: Int,
63         val marginTopLargeScreen: Int,
64     )
65 }
66