1 /*
2  * Copyright 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.scene.shared.model
18 
19 import com.android.compose.animation.scene.SceneKey
20 
21 /** Models the configuration of the scene container. */
22 data class SceneContainerConfig(
23 
24     /**
25      * The keys to all scenes in the container, sorted by z-order such that the last one renders on
26      * top of all previous ones. Scene keys within the same container must not repeat but it's okay
27      * to have the same scene keys in different containers.
28      *
29      * Note that this doesn't control how back navigation works; for that, we have
30      * [navigationDistances].
31      */
32     val sceneKeys: List<SceneKey>,
33 
34     /**
35      * The key of the scene that is the initial current scene when the container is first set up,
36      * before taking any application state in to account.
37      */
38     val initialSceneKey: SceneKey,
39 
40     /**
41      * Navigation distance of each scene.
42      *
43      * The navigation distance is a measure of how many non-back user action "steps" away from the
44      * starting scene, each scene is.
45      *
46      * The framework uses these to help scene implementations decide which scene to go back to when
47      * the user attempts to navigate back on them, if they need that.
48      *
49      * In general, the more non-back user actions are needed to get to a scene, the greater that
50      * scene's distance should be. Navigating "back" then goes from scenes with a higher distance to
51      * scenes with a lower distance.
52      *
53      * Note that this is not the z-order of rendering; that's determined by the order of declaration
54      * of scenes in the [sceneKeys] list.
55      */
56     val navigationDistances: Map<SceneKey, Int>
57 ) {
58     init {
<lambda>null59         check(sceneKeys.isNotEmpty()) { "A container must have at least one scene key." }
60 
<lambda>null61         check(sceneKeys.contains(initialSceneKey)) {
62             "The initial key \"$initialSceneKey\" is not present in this container."
63         }
64 
<lambda>null65         check(navigationDistances.keys == sceneKeys.toSet()) {
66             "Scene keys and distance map must match."
67         }
68     }
69 }
70