Skip to content
Snippets Groups Projects
Commit 344f94d0 authored by Lucas Silva's avatar Lucas Silva Committed by Android (Google) Code Review
Browse files

Merge "Refactor logic to allow touches to use SceneTransitionLayout APIs" into main

parents b2f8a242 f9a90d86
No related branches found
No related tags found
No related merge requests found
......@@ -79,10 +79,10 @@ fun CommunalContainer(
) {
val coroutineScope = rememberCoroutineScope()
val currentSceneKey: SceneKey by viewModel.currentScene.collectAsState(CommunalScenes.Blank)
val touchesAllowed by viewModel.touchesAllowed.collectAsState(initial = false)
val state: MutableSceneTransitionLayoutState = remember {
MutableSceneTransitionLayoutState(
initialScene = currentSceneKey,
canChangeScene = { _ -> viewModel.canChangeScene() },
transitions = sceneTransitions,
enableInterruptions = false,
)
......@@ -112,14 +112,9 @@ fun CommunalContainer(
scene(
CommunalScenes.Blank,
userActions =
if (touchesAllowed) {
mapOf(
Swipe(SwipeDirection.Left, fromSource = Edge.Right) to
CommunalScenes.Communal
)
} else {
emptyMap()
}
mapOf(
Swipe(SwipeDirection.Left, fromSource = Edge.Right) to CommunalScenes.Communal
)
) {
// This scene shows nothing only allowing for transitions to the communal scene.
Box(modifier = Modifier.fillMaxSize())
......@@ -128,13 +123,7 @@ fun CommunalContainer(
scene(
CommunalScenes.Communal,
userActions =
if (touchesAllowed) {
mapOf(
Swipe(SwipeDirection.Right, fromSource = Edge.Left) to CommunalScenes.Blank
)
} else {
emptyMap()
},
mapOf(Swipe(SwipeDirection.Right, fromSource = Edge.Left) to CommunalScenes.Blank)
) {
CommunalScene(viewModel, colors, dialogFactory, modifier = modifier)
}
......
......@@ -44,11 +44,13 @@ import com.android.systemui.flags.Flags.COMMUNAL_SERVICE_ENABLED
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardRepository
import com.android.systemui.keyguard.shared.model.StatusBarState
import com.android.systemui.kosmos.testScope
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.media.controls.ui.controller.MediaHierarchyManager
import com.android.systemui.media.controls.ui.view.MediaHost
import com.android.systemui.settings.fakeUserTracker
import com.android.systemui.shade.data.repository.fakeShadeRepository
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.smartspace.data.repository.FakeSmartspaceRepository
import com.android.systemui.smartspace.data.repository.fakeSmartspaceRepository
......@@ -59,6 +61,7 @@ import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
......@@ -266,6 +269,26 @@ class CommunalViewModelTest : SysuiTestCase() {
assertThat(isPopupOnDismissCtaShowing).isEqualTo(false)
}
@Test
fun canChangeScene_shadeNotExpanded() =
testScope.runTest {
// On keyguard without any shade expansion.
kosmos.fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD)
kosmos.fakeShadeRepository.setLockscreenShadeExpansion(0f)
runCurrent()
assertThat(underTest.canChangeScene()).isTrue()
}
@Test
fun canChangeScene_shadeExpanded() =
testScope.runTest {
// On keyguard with shade fully expanded.
kosmos.fakeKeyguardRepository.setStatusBarState(StatusBarState.KEYGUARD)
kosmos.fakeShadeRepository.setLockscreenShadeExpansion(1f)
runCurrent()
assertThat(underTest.canChangeScene()).isFalse()
}
private suspend fun setIsMainUser(isMainUser: Boolean) {
whenever(user.isMain).thenReturn(isMainUser)
userRepository.setUserInfos(listOf(user))
......
......@@ -30,7 +30,6 @@ import com.android.systemui.media.controls.ui.view.MediaHost
import com.android.systemui.media.controls.ui.view.MediaHostState
import com.android.systemui.media.dagger.MediaModule
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.util.kotlin.BooleanFlowOperators.not
import javax.inject.Inject
import javax.inject.Named
import kotlinx.coroutines.CoroutineScope
......@@ -57,7 +56,7 @@ constructor(
@Application private val scope: CoroutineScope,
private val communalInteractor: CommunalInteractor,
tutorialInteractor: CommunalTutorialInteractor,
shadeInteractor: ShadeInteractor,
private val shadeInteractor: ShadeInteractor,
deviceEntryInteractor: DeviceEntryInteractor,
@Named(MediaModule.COMMUNAL_HUB) mediaHost: MediaHost,
@CommunalLog logBuffer: LogBuffer,
......@@ -103,9 +102,6 @@ constructor(
val isEnableWorkProfileDialogShowing: Flow<Boolean> =
_isEnableWorkProfileDialogShowing.asStateFlow()
/** Whether touches should be disabled in communal */
val touchesAllowed: Flow<Boolean> = not(shadeInteractor.isAnyFullyExpanded)
val deviceUnlocked: Flow<Boolean> = deviceEntryInteractor.isUnlocked
init {
......@@ -192,6 +188,11 @@ constructor(
delayedHidePopupJob = null
}
/** Whether we can transition to a new scene based on a user gesture. */
fun canChangeScene(): Boolean {
return !shadeInteractor.isAnyFullyExpanded.value
}
companion object {
const val POPUP_AUTO_HIDE_TIMEOUT_MS = 12000L
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment