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.qs.panels.ui.viewmodel
18
19 import android.content.res.Configuration
20 import android.content.res.mainResources
21 import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
22 import com.android.systemui.common.ui.domain.interactor.configurationInteractor
23 import com.android.systemui.kosmos.Kosmos
24 import com.android.systemui.kosmos.runCurrent
25 import com.android.systemui.media.controls.ui.controller.mediaHostStatesManager
26 import com.android.systemui.qs.composefragment.dagger.usingMediaInComposeFragment
27 import com.android.systemui.shade.data.repository.shadeRepository
28 import com.android.systemui.shade.domain.interactor.shadeModeInteractor
29
30 val Kosmos.mediaInRowInLandscapeViewModelFactory by
<lambda>null31 Kosmos.Fixture {
32 object : MediaInRowInLandscapeViewModel.Factory {
33 override fun create(inLocation: Int): MediaInRowInLandscapeViewModel {
34 return MediaInRowInLandscapeViewModel(
35 mainResources,
36 configurationInteractor,
37 shadeModeInteractor,
38 mediaHostStatesManager,
39 usingMediaInComposeFragment,
40 inLocation,
41 )
42 }
43 }
44 }
45
setConfigurationForMediaInRownull46 fun Kosmos.setConfigurationForMediaInRow(mediaInRow: Boolean) {
47 shadeRepository.setShadeLayoutWide(!mediaInRow) // media in row only in non wide
48 val config =
49 Configuration(mainResources.configuration).apply {
50 orientation =
51 if (mediaInRow) {
52 Configuration.ORIENTATION_LANDSCAPE
53 } else {
54 Configuration.ORIENTATION_PORTRAIT
55 }
56 screenLayout = Configuration.SCREENLAYOUT_LONG_YES
57 }
58 mainResources.configuration.updateFrom(config)
59 fakeConfigurationRepository.onConfigurationChange(config)
60 runCurrent()
61 }
62