[flexiglass] Fixes compose-enabled sysuig build.

Bug: 279501596
Test: built and deployed sysuig with compose build time flag enabled,
disabled, and Compose gallery when the flag is disabled.

Change-Id: I8c48055d90d9f9fa6a994ed035f71d472b1639fd
This commit is contained in:
Alejandro Nijamkin
2023-05-17 16:57:43 -07:00
parent c6eeba236f
commit 72ace2744f
13 changed files with 88 additions and 36 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package com.android.systemui.scene.shared.page
package com.android.systemui.scene.ui.composable
import com.android.systemui.scene.shared.model.Scene
import dagger.Module

View File

@@ -17,7 +17,7 @@
package com.android.systemui.scene.ui.composable
import com.android.systemui.bouncer.ui.composable.BouncerScene
import com.android.systemui.keyguard.ui.composable.LockScreenScene
import com.android.systemui.keyguard.ui.composable.LockscreenScene
import com.android.systemui.qs.ui.composable.QuickSettingsScene
import com.android.systemui.scene.shared.model.Scene
import com.android.systemui.shade.ui.composable.ShadeScene
@@ -30,7 +30,7 @@ object SceneModule {
fun scenes(
bouncer: BouncerScene,
gone: GoneScene,
lockScreen: LockScreenScene,
lockScreen: LockscreenScene,
qs: QuickSettingsScene,
shade: ShadeScene,
): Set<Scene> {

View File

@@ -55,11 +55,13 @@ import kotlinx.coroutines.flow.asStateFlow
class BouncerScene
@Inject
constructor(
private val viewModel: BouncerViewModel,
private val viewModelFactory: BouncerViewModel.Factory,
) : ComposableScene {
override val key = SceneKey.Bouncer
override fun destinationScenes(): StateFlow<Map<UserAction, SceneModel>> =
override fun destinationScenes(
containerName: String,
): StateFlow<Map<UserAction, SceneModel>> =
MutableStateFlow<Map<UserAction, SceneModel>>(
mapOf(
UserAction.Back to SceneModel(SceneKey.Lockscreen),
@@ -67,7 +69,11 @@ constructor(
)
.asStateFlow()
@Composable override fun Content(modifier: Modifier) = BouncerScene(viewModel, modifier)
@Composable
override fun Content(
containerName: String,
modifier: Modifier,
) = BouncerScene(viewModelFactory.create(containerName), modifier)
}
@Composable

View File

@@ -52,25 +52,32 @@ class LockscreenScene
@Inject
constructor(
@Application private val applicationScope: CoroutineScope,
private val viewModel: LockscreenSceneViewModel,
private val viewModelFactory: LockscreenSceneViewModel.Factory,
) : ComposableScene {
override val key = SceneKey.Lockscreen
override fun destinationScenes(): StateFlow<Map<UserAction, SceneModel>> =
viewModel.upDestinationSceneKey
.map { pageKey -> destinationScenes(up = pageKey) }
.stateIn(
scope = applicationScope,
started = SharingStarted.Eagerly,
initialValue = destinationScenes(up = viewModel.upDestinationSceneKey.value)
)
private var unsafeViewModel: LockscreenSceneViewModel? = null
override fun destinationScenes(
containerName: String,
): StateFlow<Map<UserAction, SceneModel>> =
getOrCreateViewModelSingleton(containerName).let { viewModel ->
viewModel.upDestinationSceneKey
.map { pageKey -> destinationScenes(up = pageKey) }
.stateIn(
scope = applicationScope,
started = SharingStarted.Eagerly,
initialValue = destinationScenes(up = viewModel.upDestinationSceneKey.value)
)
}
@Composable
override fun Content(
containerName: String,
modifier: Modifier,
) {
LockscreenScene(
viewModel = viewModel,
viewModel = getOrCreateViewModelSingleton(containerName),
modifier = modifier,
)
}
@@ -83,6 +90,13 @@ constructor(
UserAction.Swipe(Direction.DOWN) to SceneModel(SceneKey.Shade)
)
}
private fun getOrCreateViewModelSingleton(
containerName: String,
): LockscreenSceneViewModel {
return unsafeViewModel
?: viewModelFactory.create(containerName).also { unsafeViewModel = it }
}
}
@Composable

View File

@@ -44,11 +44,13 @@ import kotlinx.coroutines.flow.asStateFlow
class QuickSettingsScene
@Inject
constructor(
private val viewModel: QuickSettingsSceneViewModel,
private val viewModelFactory: QuickSettingsSceneViewModel.Factory,
) : ComposableScene {
override val key = SceneKey.QuickSettings
override fun destinationScenes(): StateFlow<Map<UserAction, SceneModel>> =
override fun destinationScenes(
containerName: String,
): StateFlow<Map<UserAction, SceneModel>> =
MutableStateFlow<Map<UserAction, SceneModel>>(
mapOf(
UserAction.Swipe(Direction.UP) to SceneModel(SceneKey.Shade),
@@ -58,10 +60,11 @@ constructor(
@Composable
override fun Content(
containerName: String,
modifier: Modifier,
) {
QuickSettingsScene(
viewModel = viewModel,
viewModel = viewModelFactory.create(containerName),
modifier = modifier,
)
}

View File

@@ -22,5 +22,5 @@ import com.android.systemui.scene.shared.model.Scene
/** Compose-capable extension of [Scene]. */
interface ComposableScene : Scene {
@Composable fun Content(modifier: Modifier)
@Composable fun Content(containerName: String, modifier: Modifier)
}

View File

@@ -41,7 +41,9 @@ import kotlinx.coroutines.flow.asStateFlow
class GoneScene @Inject constructor() : ComposableScene {
override val key = SceneKey.Gone
override fun destinationScenes(): StateFlow<Map<UserAction, SceneModel>> =
override fun destinationScenes(
containerName: String,
): StateFlow<Map<UserAction, SceneModel>> =
MutableStateFlow<Map<UserAction, SceneModel>>(
mapOf(
UserAction.Swipe(Direction.DOWN) to SceneModel(SceneKey.Shade),
@@ -51,6 +53,7 @@ class GoneScene @Inject constructor() : ComposableScene {
@Composable
override fun Content(
containerName: String,
modifier: Modifier,
) {
/*

View File

@@ -75,6 +75,7 @@ fun SceneContainer(
if (key == currentSceneKey) {
Scene(
scene = composableScene,
containerName = viewModel.containerName,
onSceneChanged = viewModel::setCurrentScene,
modifier = Modifier.fillMaxSize(),
)
@@ -87,6 +88,7 @@ fun SceneContainer(
@Composable
private fun Scene(
scene: ComposableScene,
containerName: String,
onSceneChanged: (SceneModel) -> Unit,
modifier: Modifier = Modifier,
) {
@@ -97,11 +99,12 @@ private fun Scene(
modifier = Modifier.align(Alignment.Center),
) {
scene.Content(
containerName = containerName,
modifier = Modifier,
)
val destinationScenes: Map<UserAction, SceneModel> by
scene.destinationScenes().collectAsState()
scene.destinationScenes(containerName).collectAsState()
val swipeLeftDestinationScene = destinationScenes[UserAction.Swipe(Direction.LEFT)]
val swipeUpDestinationScene = destinationScenes[UserAction.Swipe(Direction.UP)]
val swipeRightDestinationScene = destinationScenes[UserAction.Swipe(Direction.RIGHT)]

View File

@@ -48,25 +48,32 @@ class ShadeScene
@Inject
constructor(
@Application private val applicationScope: CoroutineScope,
private val viewModel: ShadeSceneViewModel,
private val viewModelFactory: ShadeSceneViewModel.Factory,
) : ComposableScene {
override val key = SceneKey.Shade
override fun destinationScenes(): StateFlow<Map<UserAction, SceneModel>> =
viewModel.upDestinationSceneKey
.map { sceneKey -> destinationScenes(up = sceneKey) }
.stateIn(
scope = applicationScope,
started = SharingStarted.Eagerly,
initialValue = destinationScenes(up = viewModel.upDestinationSceneKey.value),
)
private var unsafeViewModel: ShadeSceneViewModel? = null
override fun destinationScenes(
containerName: String,
): StateFlow<Map<UserAction, SceneModel>> =
getOrCreateViewModelSingleton(containerName).let { viewModel ->
viewModel.upDestinationSceneKey
.map { sceneKey -> destinationScenes(up = sceneKey) }
.stateIn(
scope = applicationScope,
started = SharingStarted.Eagerly,
initialValue = destinationScenes(up = viewModel.upDestinationSceneKey.value),
)
}
@Composable
override fun Content(
containerName: String,
modifier: Modifier,
) {
ShadeScene(
viewModel = viewModel,
viewModel = getOrCreateViewModelSingleton(containerName),
modifier = modifier,
)
}
@@ -79,6 +86,13 @@ constructor(
UserAction.Swipe(Direction.DOWN) to SceneModel(SceneKey.QuickSettings),
)
}
private fun getOrCreateViewModelSingleton(
containerName: String,
): ShadeSceneViewModel {
return unsafeViewModel
?: viewModelFactory.create(containerName).also { unsafeViewModel = it }
}
}
@Composable

View File

@@ -20,6 +20,8 @@ import android.content.Context
import com.android.systemui.authentication.shared.model.AuthenticationMethodModel
import com.android.systemui.bouncer.domain.interactor.BouncerInteractor
import com.android.systemui.dagger.qualifiers.Application
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
@@ -34,7 +36,7 @@ constructor(
@Application private val applicationContext: Context,
@Application private val applicationScope: CoroutineScope,
interactorFactory: BouncerInteractor.Factory,
containerName: String,
@Assisted containerName: String,
) {
private val interactor: BouncerInteractor = interactorFactory.create(containerName)
@@ -94,4 +96,11 @@ constructor(
else -> null
}
}
@AssistedFactory
interface Factory {
fun create(
containerName: String,
): BouncerViewModel
}
}

View File

@@ -16,7 +16,7 @@
package com.android.systemui.scene
import com.android.systemui.scene.shared.page.SceneModule
import com.android.systemui.scene.ui.composable.SceneModule
import dagger.Module
@Module(

View File

@@ -59,7 +59,7 @@ interface Scene {
* The API is designed such that it's possible to emit ever-changing values for each
* [UserAction] to enable, disable, or change the destination scene of a given user action.
*/
fun destinationScenes(): StateFlow<Map<UserAction, SceneModel>> =
fun destinationScenes(containerName: String): StateFlow<Map<UserAction, SceneModel>> =
MutableStateFlow(emptyMap<UserAction, SceneModel>()).asStateFlow()
}

View File

@@ -29,7 +29,7 @@ class SceneContainerViewModel
@AssistedInject
constructor(
private val interactor: SceneInteractor,
@Assisted private val containerName: String,
@Assisted val containerName: String,
) {
/**
* Keys of all scenes in the container.