1 /* <lambda>null2 * 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 package com.android.systemui.shade.domain.interactor 18 19 import com.android.compose.animation.scene.ObservableTransitionState 20 import com.android.systemui.dagger.SysUISingleton 21 import com.android.systemui.dagger.qualifiers.Background 22 import com.android.systemui.scene.domain.interactor.SceneInteractor 23 import com.android.systemui.scene.shared.model.Scenes 24 import com.android.systemui.shade.data.repository.ShadeAnimationRepository 25 import javax.inject.Inject 26 import kotlinx.coroutines.CoroutineScope 27 import kotlinx.coroutines.ExperimentalCoroutinesApi 28 import kotlinx.coroutines.flow.SharingStarted 29 import kotlinx.coroutines.flow.distinctUntilChanged 30 import kotlinx.coroutines.flow.flatMapLatest 31 import kotlinx.coroutines.flow.flowOf 32 import kotlinx.coroutines.flow.map 33 import kotlinx.coroutines.flow.stateIn 34 35 /** Implementation of ShadeAnimationInteractor compatible with the scene container framework. */ 36 @SysUISingleton 37 class ShadeAnimationInteractorSceneContainerImpl 38 @Inject 39 constructor( 40 @Background scope: CoroutineScope, 41 shadeAnimationRepository: ShadeAnimationRepository, 42 sceneInteractor: SceneInteractor, 43 ) : ShadeAnimationInteractor(shadeAnimationRepository) { 44 @OptIn(ExperimentalCoroutinesApi::class) 45 override val isAnyCloseAnimationRunning = 46 sceneInteractor.transitionState 47 .flatMapLatest { state -> 48 when (state) { 49 is ObservableTransitionState.Idle -> flowOf(false) 50 is ObservableTransitionState.Transition -> 51 if ( 52 (state.fromScene == Scenes.Shade && 53 state.toScene != Scenes.QuickSettings) || 54 (state.fromScene == Scenes.QuickSettings && 55 state.toScene != Scenes.Shade) 56 ) { 57 state.isUserInputOngoing.map { !it } 58 } else { 59 flowOf(false) 60 } 61 } 62 } 63 .distinctUntilChanged() 64 .stateIn(scope, SharingStarted.Eagerly, false) 65 } 66