summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt73
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt78
2 files changed, 151 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt b/packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt
new file mode 100644
index 000000000000..1e55975658a5
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/scene/domain/interactor/SceneInteractor.kt
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.scene.domain.interactor
+
+import com.android.systemui.dagger.SysUISingleton
+import com.android.systemui.scene.data.repository.SceneContainerRepository
+import com.android.systemui.scene.shared.model.SceneKey
+import com.android.systemui.scene.shared.model.SceneModel
+import javax.inject.Inject
+import kotlinx.coroutines.flow.StateFlow
+
+/** Business logic and app state accessors for the scene framework. */
+@SysUISingleton
+class SceneInteractor
+@Inject
+constructor(
+ private val repository: SceneContainerRepository,
+) {
+
+ /**
+ * Returns the keys of all scenes in the container with the given name.
+ *
+ * The scenes will be sorted in z-order such that the last one is the one that should be
+ * rendered on top of all previous ones.
+ */
+ fun allSceneKeys(containerName: String): List<SceneKey> {
+ return repository.allSceneKeys(containerName)
+ }
+
+ /** Sets the scene in the container with the given name. */
+ fun setCurrentScene(containerName: String, scene: SceneModel) {
+ repository.setCurrentScene(containerName, scene)
+ }
+
+ /** The current scene in the container with the given name. */
+ fun currentScene(containerName: String): StateFlow<SceneModel> {
+ return repository.currentScene(containerName)
+ }
+
+ /** Sets the visibility of the container with the given name. */
+ fun setVisible(containerName: String, isVisible: Boolean) {
+ return repository.setVisible(containerName, isVisible)
+ }
+
+ /** Whether the container with the given name is visible. */
+ fun isVisible(containerName: String): StateFlow<Boolean> {
+ return repository.isVisible(containerName)
+ }
+
+ /** Sets scene transition progress to the current scene in the container with the given name. */
+ fun setSceneTransitionProgress(containerName: String, progress: Float) {
+ repository.setSceneTransitionProgress(containerName, progress)
+ }
+
+ /** Progress of the transition into the current scene in the container with the given name. */
+ fun sceneTransitionProgress(containerName: String): StateFlow<Float> {
+ return repository.sceneTransitionProgress(containerName)
+ }
+}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt
new file mode 100644
index 000000000000..c5ce09246862
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/scene/domain/interactor/SceneInteractorTest.kt
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+@file:OptIn(ExperimentalCoroutinesApi::class, ExperimentalCoroutinesApi::class)
+
+package com.android.systemui.scene.domain.interactor
+
+import androidx.test.filters.SmallTest
+import com.android.systemui.SysuiTestCase
+import com.android.systemui.coroutines.collectLastValue
+import com.android.systemui.scene.data.repository.fakeSceneContainerRepository
+import com.android.systemui.scene.data.repository.fakeSceneKeys
+import com.android.systemui.scene.shared.model.SceneKey
+import com.android.systemui.scene.shared.model.SceneModel
+import com.google.common.truth.Truth.assertThat
+import kotlinx.coroutines.ExperimentalCoroutinesApi
+import kotlinx.coroutines.test.runTest
+import org.junit.Test
+import org.junit.runner.RunWith
+import org.junit.runners.JUnit4
+
+@SmallTest
+@RunWith(JUnit4::class)
+class SceneInteractorTest : SysuiTestCase() {
+
+ private val underTest =
+ SceneInteractor(
+ repository = fakeSceneContainerRepository(),
+ )
+
+ @Test
+ fun allSceneKeys() {
+ assertThat(underTest.allSceneKeys("container1")).isEqualTo(fakeSceneKeys())
+ }
+
+ @Test
+ fun sceneTransitions() = runTest {
+ val currentScene by collectLastValue(underTest.currentScene("container1"))
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.LockScreen))
+
+ underTest.setCurrentScene("container1", SceneModel(SceneKey.Shade))
+ assertThat(currentScene).isEqualTo(SceneModel(SceneKey.Shade))
+ }
+
+ @Test
+ fun sceneTransitionProgress() = runTest {
+ val progress by collectLastValue(underTest.sceneTransitionProgress("container1"))
+ assertThat(progress).isEqualTo(1f)
+
+ underTest.setSceneTransitionProgress("container1", 0.55f)
+ assertThat(progress).isEqualTo(0.55f)
+ }
+
+ @Test
+ fun isVisible() = runTest {
+ val isVisible by collectLastValue(underTest.isVisible("container1"))
+ assertThat(isVisible).isTrue()
+
+ underTest.setVisible("container1", false)
+ assertThat(isVisible).isFalse()
+
+ underTest.setVisible("container1", true)
+ assertThat(isVisible).isTrue()
+ }
+}