Merge "[flexiglass] Fixes compose-enabled sysuig build." into udc-dev

This commit is contained in:
Ale Nijamkin
2023-05-18 19:46:55 +00:00
committed by Android (Google) Code Review
13 changed files with 88 additions and 36 deletions

View File

@@ -14,7 +14,7 @@
* limitations under the License. * 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 com.android.systemui.scene.shared.model.Scene
import dagger.Module import dagger.Module

View File

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

View File

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

View File

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

View File

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

View File

@@ -22,5 +22,5 @@ import com.android.systemui.scene.shared.model.Scene
/** Compose-capable extension of [Scene]. */ /** Compose-capable extension of [Scene]. */
interface ComposableScene : 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 { class GoneScene @Inject constructor() : ComposableScene {
override val key = SceneKey.Gone 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>>( MutableStateFlow<Map<UserAction, SceneModel>>(
mapOf( mapOf(
UserAction.Swipe(Direction.DOWN) to SceneModel(SceneKey.Shade), UserAction.Swipe(Direction.DOWN) to SceneModel(SceneKey.Shade),
@@ -51,6 +53,7 @@ class GoneScene @Inject constructor() : ComposableScene {
@Composable @Composable
override fun Content( override fun Content(
containerName: String,
modifier: Modifier, modifier: Modifier,
) { ) {
/* /*

View File

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

View File

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

View File

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

View File

@@ -16,7 +16,7 @@
package com.android.systemui.scene package com.android.systemui.scene
import com.android.systemui.scene.shared.page.SceneModule import com.android.systemui.scene.ui.composable.SceneModule
import dagger.Module import dagger.Module
@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 * 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. * [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() MutableStateFlow(emptyMap<UserAction, SceneModel>()).asStateFlow()
} }

View File

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