diff options
11 files changed, 248 insertions, 164 deletions
diff --git a/packages/SystemUI/compose/facade/disabled/src/com/android/systemui/compose/ComposeFacade.kt b/packages/SystemUI/compose/facade/disabled/src/com/android/systemui/compose/ComposeFacade.kt index ddd1c67bd5fa..e369773f37f1 100644 --- a/packages/SystemUI/compose/facade/disabled/src/com/android/systemui/compose/ComposeFacade.kt +++ b/packages/SystemUI/compose/facade/disabled/src/com/android/systemui/compose/ComposeFacade.kt @@ -22,7 +22,7 @@ import android.view.View import android.view.WindowInsets import androidx.activity.ComponentActivity import androidx.lifecycle.LifecycleOwner -import com.android.systemui.communal.ui.viewmodel.CommunalViewModel +import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel import com.android.systemui.people.ui.viewmodel.PeopleViewModel import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel import com.android.systemui.scene.shared.model.Scene @@ -67,12 +67,12 @@ object ComposeFacade : BaseComposeFacade { override fun createCommunalView( context: Context, - viewModel: CommunalViewModel, + viewModel: BaseCommunalViewModel, ): View { throwComposeUnavailableError() } - override fun createCommunalContainer(context: Context, viewModel: CommunalViewModel): View { + override fun createCommunalContainer(context: Context, viewModel: BaseCommunalViewModel): View { throwComposeUnavailableError() } diff --git a/packages/SystemUI/compose/facade/enabled/src/com/android/systemui/compose/ComposeFacade.kt b/packages/SystemUI/compose/facade/enabled/src/com/android/systemui/compose/ComposeFacade.kt index eeda6c63b68f..7aba4308053b 100644 --- a/packages/SystemUI/compose/facade/enabled/src/com/android/systemui/compose/ComposeFacade.kt +++ b/packages/SystemUI/compose/facade/enabled/src/com/android/systemui/compose/ComposeFacade.kt @@ -32,7 +32,7 @@ import com.android.systemui.common.ui.compose.windowinsets.DisplayCutout import com.android.systemui.common.ui.compose.windowinsets.DisplayCutoutProvider import com.android.systemui.communal.ui.compose.CommunalContainer import com.android.systemui.communal.ui.compose.CommunalHub -import com.android.systemui.communal.ui.viewmodel.CommunalViewModel +import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel import com.android.systemui.people.ui.compose.PeopleScreen import com.android.systemui.people.ui.viewmodel.PeopleViewModel import com.android.systemui.qs.footer.ui.compose.FooterActions @@ -98,14 +98,14 @@ object ComposeFacade : BaseComposeFacade { override fun createCommunalView( context: Context, - viewModel: CommunalViewModel, + viewModel: BaseCommunalViewModel, ): View { return ComposeView(context).apply { setContent { PlatformTheme { CommunalHub(viewModel = viewModel) } } } } - override fun createCommunalContainer(context: Context, viewModel: CommunalViewModel): View { + override fun createCommunalContainer(context: Context, viewModel: BaseCommunalViewModel): View { return ComposeView(context).apply { setContent { PlatformTheme { CommunalContainer(viewModel = viewModel) } } } diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt index 09706bed1921..ce84c19a53ee 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContainer.kt @@ -32,7 +32,7 @@ import com.android.compose.animation.scene.Swipe import com.android.compose.animation.scene.SwipeDirection import com.android.compose.animation.scene.transitions import com.android.systemui.communal.shared.model.CommunalSceneKey -import com.android.systemui.communal.ui.viewmodel.CommunalViewModel +import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel import kotlinx.coroutines.flow.transform object Communal { @@ -59,7 +59,7 @@ val sceneTransitions = transitions { @Composable fun CommunalContainer( modifier: Modifier = Modifier, - viewModel: CommunalViewModel, + viewModel: BaseCommunalViewModel, ) { val currentScene: SceneKey by viewModel.currentScene @@ -129,7 +129,7 @@ private fun BlankScene( /** Scene containing the glanceable hub UI. */ @Composable private fun SceneScope.CommunalScene( - viewModel: CommunalViewModel, + viewModel: BaseCommunalViewModel, modifier: Modifier = Modifier, ) { Box(modifier.element(Communal.Elements.Content)) { CommunalHub(viewModel = viewModel) } diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt index c80902e22a56..4891a680e2e1 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt @@ -51,7 +51,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView import com.android.systemui.communal.domain.model.CommunalContentModel import com.android.systemui.communal.shared.model.CommunalContentSize -import com.android.systemui.communal.ui.viewmodel.CommunalViewModel +import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel import com.android.systemui.media.controls.ui.MediaHierarchyManager import com.android.systemui.media.controls.ui.MediaHostState import com.android.systemui.res.R @@ -59,7 +59,7 @@ import com.android.systemui.res.R @Composable fun CommunalHub( modifier: Modifier = Modifier, - viewModel: CommunalViewModel, + viewModel: BaseCommunalViewModel, ) { val communalContent by viewModel.communalContent.collectAsState(initial = emptyList()) Box( @@ -109,7 +109,7 @@ fun CommunalHub( @Composable private fun CommunalContent( model: CommunalContentModel, - viewModel: CommunalViewModel, + viewModel: BaseCommunalViewModel, size: SizeF, deleteOnClick: (id: Int) -> Unit, modifier: Modifier = Modifier, @@ -173,7 +173,7 @@ private fun TutorialContent(modifier: Modifier = Modifier) { } @Composable -private fun Umo(viewModel: CommunalViewModel, modifier: Modifier = Modifier) { +private fun Umo(viewModel: BaseCommunalViewModel, modifier: Modifier = Modifier) { AndroidView( modifier = modifier, factory = { diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt new file mode 100644 index 000000000000..32f4d075a873 --- /dev/null +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt @@ -0,0 +1,148 @@ +/* + * 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.communal.view.viewmodel + +import android.app.smartspace.SmartspaceTarget +import android.provider.Settings +import android.widget.RemoteViews +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import com.android.systemui.SysuiTestCase +import com.android.systemui.communal.data.repository.FakeCommunalMediaRepository +import com.android.systemui.communal.data.repository.FakeCommunalRepository +import com.android.systemui.communal.data.repository.FakeCommunalTutorialRepository +import com.android.systemui.communal.data.repository.FakeCommunalWidgetRepository +import com.android.systemui.communal.domain.interactor.CommunalInteractorFactory +import com.android.systemui.communal.domain.model.CommunalContentModel +import com.android.systemui.communal.shared.model.CommunalWidgetContentModel +import com.android.systemui.communal.ui.viewmodel.CommunalViewModel +import com.android.systemui.coroutines.collectLastValue +import com.android.systemui.keyguard.data.repository.FakeKeyguardRepository +import com.android.systemui.media.controls.ui.MediaHost +import com.android.systemui.smartspace.data.repository.FakeSmartspaceRepository +import com.android.systemui.util.mockito.mock +import com.android.systemui.util.mockito.whenever +import com.google.common.truth.Truth.assertThat +import kotlinx.coroutines.test.TestScope +import kotlinx.coroutines.test.runTest +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.Mockito +import org.mockito.MockitoAnnotations + +@SmallTest +@RunWith(AndroidJUnit4::class) +class CommunalViewModelTest : SysuiTestCase() { + @Mock private lateinit var mediaHost: MediaHost + + private lateinit var testScope: TestScope + + private lateinit var keyguardRepository: FakeKeyguardRepository + private lateinit var communalRepository: FakeCommunalRepository + private lateinit var tutorialRepository: FakeCommunalTutorialRepository + private lateinit var widgetRepository: FakeCommunalWidgetRepository + private lateinit var smartspaceRepository: FakeSmartspaceRepository + private lateinit var mediaRepository: FakeCommunalMediaRepository + + private lateinit var underTest: CommunalViewModel + + @Before + fun setUp() { + MockitoAnnotations.initMocks(this) + + testScope = TestScope() + + val withDeps = CommunalInteractorFactory.create() + keyguardRepository = withDeps.keyguardRepository + communalRepository = withDeps.communalRepository + tutorialRepository = withDeps.tutorialRepository + widgetRepository = withDeps.widgetRepository + smartspaceRepository = withDeps.smartspaceRepository + mediaRepository = withDeps.mediaRepository + + underTest = + CommunalViewModel( + withDeps.communalInteractor, + withDeps.tutorialInteractor, + mediaHost, + ) + } + + @Test + fun tutorial_tutorialNotCompletedAndKeyguardVisible_showTutorialContent() = + testScope.runTest { + // Keyguard showing, and tutorial not started. + keyguardRepository.setKeyguardShowing(true) + keyguardRepository.setKeyguardOccluded(false) + tutorialRepository.setTutorialSettingState( + Settings.Secure.HUB_MODE_TUTORIAL_NOT_STARTED + ) + + val communalContent by collectLastValue(underTest.communalContent) + + assertThat(communalContent!!).isNotEmpty() + communalContent!!.forEach { model -> + assertThat(model is CommunalContentModel.Tutorial).isTrue() + } + } + + @Test + fun ordering_smartspaceBeforeUmoBeforeWidgets() = + testScope.runTest { + tutorialRepository.setTutorialSettingState(Settings.Secure.HUB_MODE_TUTORIAL_COMPLETED) + + // Widgets available. + val widgets = + listOf( + CommunalWidgetContentModel( + appWidgetId = 0, + priority = 30, + providerInfo = mock(), + ), + CommunalWidgetContentModel( + appWidgetId = 1, + priority = 20, + providerInfo = mock(), + ), + ) + widgetRepository.setCommunalWidgets(widgets) + + // Smartspace available. + val target = Mockito.mock(SmartspaceTarget::class.java) + whenever(target.smartspaceTargetId).thenReturn("target") + whenever(target.featureType).thenReturn(SmartspaceTarget.FEATURE_TIMER) + whenever(target.remoteViews).thenReturn(Mockito.mock(RemoteViews::class.java)) + smartspaceRepository.setLockscreenSmartspaceTargets(listOf(target)) + + // Media playing. + mediaRepository.mediaPlaying.value = true + + val communalContent by collectLastValue(underTest.communalContent) + + // Order is smart space, then UMO, then widget content. + assertThat(communalContent?.size).isEqualTo(4) + assertThat(communalContent?.get(0)) + .isInstanceOf(CommunalContentModel.Smartspace::class.java) + assertThat(communalContent?.get(1)).isInstanceOf(CommunalContentModel.Umo::class.java) + assertThat(communalContent?.get(2)) + .isInstanceOf(CommunalContentModel.Widget::class.java) + assertThat(communalContent?.get(3)) + .isInstanceOf(CommunalContentModel.Widget::class.java) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt index 7391a5e8e5fc..927bf024215d 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt @@ -32,7 +32,6 @@ import javax.inject.Inject import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow -import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.flatMapLatest import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map @@ -47,7 +46,6 @@ constructor( private val widgetRepository: CommunalWidgetRepository, mediaRepository: CommunalMediaRepository, smartspaceRepository: SmartspaceRepository, - tutorialInteractor: CommunalTutorialInteractor, private val appWidgetHost: AppWidgetHost, private val editWidgetsActivityStarter: EditWidgetsActivityStarter ) { @@ -86,20 +84,8 @@ constructor( /** Delete a widget by id. */ fun deleteWidget(id: Int) = widgetRepository.deleteWidget(id) - /** A list of all the communal content to be displayed in the communal hub. */ - @OptIn(ExperimentalCoroutinesApi::class) - val communalContent: Flow<List<CommunalContentModel>> = - tutorialInteractor.isTutorialAvailable.flatMapLatest { isTutorialMode -> - if (isTutorialMode) { - return@flatMapLatest flowOf(tutorialContent) - } - combine(smartspaceContent, umoContent, widgetContent) { smartspace, umo, widgets -> - smartspace + umo + widgets - } - } - /** A list of widget content to be displayed in the communal hub. */ - private val widgetContent: Flow<List<CommunalContentModel.Widget>> = + val widgetContent: Flow<List<CommunalContentModel.Widget>> = widgetRepository.communalWidgets.map { widgets -> widgets.map Widget@{ widget -> return@Widget CommunalContentModel.Widget( @@ -111,7 +97,7 @@ constructor( } /** A flow of available smartspace content. Currently only showing timer targets. */ - private val smartspaceContent: Flow<List<CommunalContentModel.Smartspace>> = + val smartspaceContent: Flow<List<CommunalContentModel.Smartspace>> = if (!smartspaceRepository.isSmartspaceRemoteViewsEnabled) { flowOf(emptyList()) } else { @@ -133,7 +119,7 @@ constructor( } /** A list of tutorial content to be displayed in the communal hub in tutorial mode. */ - private val tutorialContent: List<CommunalContentModel.Tutorial> = + val tutorialContent: List<CommunalContentModel.Tutorial> = listOf( CommunalContentModel.Tutorial(id = 0, CommunalContentSize.FULL), CommunalContentModel.Tutorial(id = 1, CommunalContentSize.THIRD), @@ -145,7 +131,7 @@ constructor( CommunalContentModel.Tutorial(id = 7, CommunalContentSize.HALF), ) - private val umoContent: Flow<List<CommunalContentModel.Umo>> = + val umoContent: Flow<List<CommunalContentModel.Umo>> = mediaRepository.mediaPlaying.flatMapLatest { mediaPlaying -> if (mediaPlaying) { // TODO(b/310254801): support HALF and FULL layouts diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt new file mode 100644 index 000000000000..10e9ee855be0 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt @@ -0,0 +1,45 @@ +/* + * 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.communal.ui.viewmodel + +import com.android.systemui.communal.domain.interactor.CommunalInteractor +import com.android.systemui.communal.domain.model.CommunalContentModel +import com.android.systemui.communal.shared.model.CommunalSceneKey +import com.android.systemui.media.controls.ui.MediaHost +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow + +/** The base view model for the communal hub. */ +abstract class BaseCommunalViewModel( + private val communalInteractor: CommunalInteractor, + val mediaHost: MediaHost, +) { + val currentScene: StateFlow<CommunalSceneKey> = communalInteractor.desiredScene + + fun onSceneChanged(scene: CommunalSceneKey) { + communalInteractor.onSceneChanged(scene) + } + + /** A list of all the communal content to be displayed in the communal hub. */ + abstract val communalContent: Flow<List<CommunalContentModel>> + + /** Called as the UI requests deleting a widget. */ + open fun onDeleteWidget(id: Int) {} + + /** Called as the UI requests opening the widget editor. */ + open fun onOpenWidgetEditor() {} +} diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt index 14edc8e0a88c..eaf2d5741e23 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt @@ -17,34 +17,43 @@ package com.android.systemui.communal.ui.viewmodel import com.android.systemui.communal.domain.interactor.CommunalInteractor +import com.android.systemui.communal.domain.interactor.CommunalTutorialInteractor import com.android.systemui.communal.domain.model.CommunalContentModel -import com.android.systemui.communal.shared.model.CommunalSceneKey import com.android.systemui.dagger.SysUISingleton import com.android.systemui.media.controls.ui.MediaHost import com.android.systemui.media.dagger.MediaModule import javax.inject.Inject import javax.inject.Named +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.flatMapLatest +import kotlinx.coroutines.flow.flowOf +/** The default view model used for showing the communal hub. */ @SysUISingleton class CommunalViewModel @Inject constructor( private val communalInteractor: CommunalInteractor, - @Named(MediaModule.COMMUNAL_HUB) val mediaHost: MediaHost, -) { - val currentScene: StateFlow<CommunalSceneKey> = communalInteractor.desiredScene - fun onSceneChanged(scene: CommunalSceneKey) { - communalInteractor.onSceneChanged(scene) - } + tutorialInteractor: CommunalTutorialInteractor, + @Named(MediaModule.COMMUNAL_HUB) mediaHost: MediaHost, +) : BaseCommunalViewModel(communalInteractor, mediaHost) { - /** A list of all the communal content to be displayed in the communal hub. */ - val communalContent: Flow<List<CommunalContentModel>> = communalInteractor.communalContent + @OptIn(ExperimentalCoroutinesApi::class) + override val communalContent: Flow<List<CommunalContentModel>> = + tutorialInteractor.isTutorialAvailable.flatMapLatest { isTutorialMode -> + if (isTutorialMode) { + return@flatMapLatest flowOf(communalInteractor.tutorialContent) + } + combine( + communalInteractor.smartspaceContent, + communalInteractor.umoContent, + communalInteractor.widgetContent, + ) { smartspace, umo, widgets -> + smartspace + umo + widgets + } + } - /** Delete a widget by id. */ - fun onDeleteWidget(id: Int) = communalInteractor.deleteWidget(id) - - /** Open the widget editor */ - fun onOpenWidgetEditor() = communalInteractor.showWidgetEditor() + override fun onOpenWidgetEditor() = communalInteractor.showWidgetEditor() } diff --git a/packages/SystemUI/src/com/android/systemui/compose/BaseComposeFacade.kt b/packages/SystemUI/src/com/android/systemui/compose/BaseComposeFacade.kt index 4bdea75d9d71..38c120da614b 100644 --- a/packages/SystemUI/src/com/android/systemui/compose/BaseComposeFacade.kt +++ b/packages/SystemUI/src/com/android/systemui/compose/BaseComposeFacade.kt @@ -22,7 +22,7 @@ import android.view.View import android.view.WindowInsets import androidx.activity.ComponentActivity import androidx.lifecycle.LifecycleOwner -import com.android.systemui.communal.ui.viewmodel.CommunalViewModel +import com.android.systemui.communal.ui.viewmodel.BaseCommunalViewModel import com.android.systemui.people.ui.viewmodel.PeopleViewModel import com.android.systemui.qs.footer.ui.viewmodel.FooterActionsViewModel import com.android.systemui.scene.shared.model.Scene @@ -77,9 +77,9 @@ interface BaseComposeFacade { /** Create a [View] to represent [viewModel] on screen. */ fun createCommunalView( context: Context, - viewModel: CommunalViewModel, + viewModel: BaseCommunalViewModel, ): View /** Creates a container that hosts the communal UI and handles gesture transitions. */ - fun createCommunalContainer(context: Context, viewModel: CommunalViewModel): View + fun createCommunalContainer(context: Context, viewModel: BaseCommunalViewModel): View } diff --git a/packages/SystemUI/tests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt b/packages/SystemUI/tests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt index e0567a4c6de5..16cfa2398fd5 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt @@ -18,7 +18,6 @@ package com.android.systemui.communal.domain.interactor import android.app.smartspace.SmartspaceTarget -import android.provider.Settings import android.provider.Settings.Secure.HUB_MODE_TUTORIAL_COMPLETED import android.widget.RemoteViews import androidx.test.ext.junit.runners.AndroidJUnit4 @@ -99,24 +98,6 @@ class CommunalInteractorTest : SysuiTestCase() { } @Test - fun tutorial_tutorialNotCompletedAndKeyguardVisible_showTutorialContent() = - testScope.runTest { - // Keyguard showing, and tutorial not started. - keyguardRepository.setKeyguardShowing(true) - keyguardRepository.setKeyguardOccluded(false) - tutorialRepository.setTutorialSettingState( - Settings.Secure.HUB_MODE_TUTORIAL_NOT_STARTED - ) - - val communalContent by collectLastValue(underTest.communalContent) - - assertThat(communalContent!!).isNotEmpty() - communalContent!!.forEach { model -> - assertThat(model is CommunalContentModel.Tutorial).isTrue() - } - } - - @Test fun widget_tutorialCompletedAndWidgetsAvailable_showWidgetContent() = testScope.runTest { // Keyguard showing, and tutorial completed. @@ -145,12 +126,11 @@ class CommunalInteractorTest : SysuiTestCase() { ) widgetRepository.setCommunalWidgets(widgets) - val communalContent by collectLastValue(underTest.communalContent) + val widgetContent by collectLastValue(underTest.widgetContent) - assertThat(communalContent!!).isNotEmpty() - communalContent!!.forEachIndexed { index, model -> - assertThat((model as CommunalContentModel.Widget).appWidgetId) - .isEqualTo(widgets[index].appWidgetId) + assertThat(widgetContent!!).isNotEmpty() + widgetContent!!.forEachIndexed { index, model -> + assertThat(model.appWidgetId).isEqualTo(widgets[index].appWidgetId) } } @@ -183,48 +163,9 @@ class CommunalInteractorTest : SysuiTestCase() { val targets = listOf(target1, target2, target3) smartspaceRepository.setLockscreenSmartspaceTargets(targets) - val communalContent by collectLastValue(underTest.communalContent) - assertThat(communalContent?.size).isEqualTo(1) - assertThat(communalContent?.get(0)?.key).isEqualTo("smartspace_target3") - } - - @Test - fun smartspace_smartspaceAndWidgetsAvailable_showSmartspaceAndWidgetContent() = - testScope.runTest { - // Keyguard showing, and tutorial completed. - keyguardRepository.setKeyguardShowing(true) - keyguardRepository.setKeyguardOccluded(false) - tutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED) - - // Widgets available. - val widgets = - listOf( - CommunalWidgetContentModel( - appWidgetId = 0, - priority = 30, - providerInfo = mock(), - ), - CommunalWidgetContentModel( - appWidgetId = 1, - priority = 20, - providerInfo = mock(), - ), - ) - widgetRepository.setCommunalWidgets(widgets) - - // Smartspace available. - val target = mock(SmartspaceTarget::class.java) - whenever(target.smartspaceTargetId).thenReturn("target") - whenever(target.featureType).thenReturn(SmartspaceTarget.FEATURE_TIMER) - whenever(target.remoteViews).thenReturn(mock(RemoteViews::class.java)) - smartspaceRepository.setLockscreenSmartspaceTargets(listOf(target)) - - val communalContent by collectLastValue(underTest.communalContent) - - assertThat(communalContent?.size).isEqualTo(3) - assertThat(communalContent?.get(0)?.key).isEqualTo("smartspace_target") - assertThat(communalContent?.get(1)?.key).isEqualTo("widget_0") - assertThat(communalContent?.get(2)?.key).isEqualTo("widget_1") + val smartspaceContent by collectLastValue(underTest.smartspaceContent) + assertThat(smartspaceContent?.size).isEqualTo(1) + assertThat(smartspaceContent?.get(0)?.key).isEqualTo("smartspace_target3") } @Test @@ -236,55 +177,11 @@ class CommunalInteractorTest : SysuiTestCase() { // Media is playing. mediaRepository.mediaPlaying.value = true - val communalContent by collectLastValue(underTest.communalContent) - - assertThat(communalContent?.size).isEqualTo(1) - assertThat(communalContent?.get(0)).isInstanceOf(CommunalContentModel.Umo::class.java) - assertThat(communalContent?.get(0)?.key).isEqualTo(CommunalContentModel.UMO_KEY) - } - - @Test - fun ordering_smartspaceBeforeUmoBeforeWidgets() = - testScope.runTest { - tutorialRepository.setTutorialSettingState(HUB_MODE_TUTORIAL_COMPLETED) - - // Widgets available. - val widgets = - listOf( - CommunalWidgetContentModel( - appWidgetId = 0, - priority = 30, - providerInfo = mock(), - ), - CommunalWidgetContentModel( - appWidgetId = 1, - priority = 20, - providerInfo = mock(), - ), - ) - widgetRepository.setCommunalWidgets(widgets) - - // Smartspace available. - val target = mock(SmartspaceTarget::class.java) - whenever(target.smartspaceTargetId).thenReturn("target") - whenever(target.featureType).thenReturn(SmartspaceTarget.FEATURE_TIMER) - whenever(target.remoteViews).thenReturn(mock(RemoteViews::class.java)) - smartspaceRepository.setLockscreenSmartspaceTargets(listOf(target)) - - // Media playing. - mediaRepository.mediaPlaying.value = true + val umoContent by collectLastValue(underTest.umoContent) - val communalContent by collectLastValue(underTest.communalContent) - - // Order is smart space, then UMO, then widget content. - assertThat(communalContent?.size).isEqualTo(4) - assertThat(communalContent?.get(0)) - .isInstanceOf(CommunalContentModel.Smartspace::class.java) - assertThat(communalContent?.get(1)).isInstanceOf(CommunalContentModel.Umo::class.java) - assertThat(communalContent?.get(2)) - .isInstanceOf(CommunalContentModel.Widget::class.java) - assertThat(communalContent?.get(3)) - .isInstanceOf(CommunalContentModel.Widget::class.java) + assertThat(umoContent?.size).isEqualTo(1) + assertThat(umoContent?.get(0)).isInstanceOf(CommunalContentModel.Umo::class.java) + assertThat(umoContent?.get(0)?.key).isEqualTo(CommunalContentModel.UMO_KEY) } @Test diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorFactory.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorFactory.kt index 3aee889d55f4..b27926c8ba50 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorFactory.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/communal/domain/interactor/CommunalInteractorFactory.kt @@ -65,7 +65,6 @@ object CommunalInteractorFactory { widgetRepository, mediaRepository, smartspaceRepository, - withDeps.communalTutorialInteractor, appWidgetHost, editWidgetsActivityStarter, ), |