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 package com.android.systemui.keyguard.ui.composable 18 19 import androidx.compose.runtime.Composable 20 import androidx.compose.runtime.DisposableEffect 21 import androidx.compose.runtime.getValue 22 import androidx.compose.runtime.rememberCoroutineScope 23 import androidx.compose.ui.Modifier 24 import androidx.compose.ui.platform.LocalView 25 import androidx.lifecycle.compose.collectAsStateWithLifecycle 26 import com.android.compose.animation.scene.SceneScope 27 import com.android.systemui.compose.modifiers.sysuiResTag 28 import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor 29 import com.android.systemui.keyguard.ui.composable.blueprint.ComposableLockscreenSceneBlueprint 30 import com.android.systemui.keyguard.ui.viewmodel.LockscreenContentViewModel 31 32 /** 33 * Renders the content of the lockscreen. 34 * 35 * This is separate from the [LockscreenScene] because it's meant to support usage of this UI from 36 * outside the scene container framework. 37 */ 38 class LockscreenContent( 39 private val viewModel: LockscreenContentViewModel, 40 private val blueprints: Set<@JvmSuppressWildcards ComposableLockscreenSceneBlueprint>, 41 private val clockInteractor: KeyguardClockInteractor, 42 ) { <lambda>null43 private val blueprintByBlueprintId: Map<String, ComposableLockscreenSceneBlueprint> by lazy { 44 blueprints.associateBy { it.id } 45 } 46 47 @Composable Contentnull48 fun SceneScope.Content( 49 modifier: Modifier = Modifier, 50 ) { 51 val coroutineScope = rememberCoroutineScope() 52 val blueprintId by viewModel.blueprintId(coroutineScope).collectAsStateWithLifecycle() 53 val view = LocalView.current 54 DisposableEffect(view) { 55 clockInteractor.clockEventController.registerListeners(view) 56 57 onDispose { clockInteractor.clockEventController.unregisterListeners() } 58 } 59 60 val blueprint = blueprintByBlueprintId[blueprintId] ?: return 61 with(blueprint) { Content(modifier.sysuiResTag("keyguard_root_view")) } 62 } 63 } 64