diff options
12 files changed, 159 insertions, 80 deletions
diff --git a/packages/SystemUI/shared/res/values/ids.xml b/packages/SystemUI/shared/res/values/ids.xml new file mode 100644 index 000000000000..1ff2f0eff215 --- /dev/null +++ b/packages/SystemUI/shared/res/values/ids.xml @@ -0,0 +1,24 @@ +<?xml version="1.0" encoding="utf-8"?><!-- + ~ 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. + --> + +<resources> + <!-- ID of the smartspace card view. --> + <item type="id" name="bc_smartspace_view" /> + <!-- ID of the smartspace date view. --> + <item type="id" name="date_smartspace_view" /> + <!-- ID of the smartspace weather view. --> + <item type="id" name="weather_smartspace_view" /> +</resources> diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardSmartspaceViewBinder.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardSmartspaceViewBinder.kt index e36819b54524..92270ad31664 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardSmartspaceViewBinder.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardSmartspaceViewBinder.kt @@ -28,6 +28,7 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.res.R +import com.android.systemui.shared.R as sharedR import kotlinx.coroutines.launch object KeyguardSmartspaceViewBinder { @@ -69,9 +70,10 @@ object KeyguardSmartspaceViewBinder { smartspaceViewModel.isSmartspaceEnabled && smartspaceViewModel.isDateWeatherDecoupled ) { - val dateView = constraintLayout.requireViewById<View>(smartspaceViewModel.dateId) + val dateView = + constraintLayout.requireViewById<View>(sharedR.id.date_smartspace_view) val weatherView = - constraintLayout.requireViewById<View>(smartspaceViewModel.weatherId) + constraintLayout.requireViewById<View>(sharedR.id.weather_smartspace_view) addView(weatherView) addView(dateView) } @@ -88,8 +90,10 @@ object KeyguardSmartspaceViewBinder { smartspaceViewModel.isSmartspaceEnabled && smartspaceViewModel.isDateWeatherDecoupled ) { - val dateView = smartspaceViewModel.dateView - val weatherView = smartspaceViewModel.weatherView + val dateView = + constraintLayout.requireViewById<View>(sharedR.id.date_smartspace_view) + val weatherView = + constraintLayout.requireViewById<View>(sharedR.id.weather_smartspace_view) removeView(weatherView) removeView(dateView) } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AodBurnInSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AodBurnInSection.kt index d89e1e41d1bc..1ccc6ccf2cec 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AodBurnInSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AodBurnInSection.kt @@ -28,6 +28,7 @@ import com.android.systemui.keyguard.shared.model.KeyguardSection import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel import com.android.systemui.res.R +import com.android.systemui.shared.R as sharedR import javax.inject.Inject /** Adds a layer to group elements for translation for burn-in preventation */ @@ -87,7 +88,7 @@ constructor( burnInLayer.apply { if (smartspaceViewModel.isSmartspaceEnabled) { val smartspaceView = - constraintLayout.requireViewById<View>(smartspaceViewModel.smartspaceViewId) + constraintLayout.requireViewById<View>(sharedR.id.bc_smartspace_view) addView(smartspaceView) } } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AodNotificationIconsSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AodNotificationIconsSection.kt index b429ab4fac0a..f560b5f068c9 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AodNotificationIconsSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/AodNotificationIconsSection.kt @@ -32,6 +32,7 @@ import com.android.systemui.keyguard.shared.KeyguardShadeMigrationNssl import com.android.systemui.keyguard.shared.model.KeyguardSection import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel import com.android.systemui.res.R +import com.android.systemui.shared.R as sharedR import com.android.systemui.statusbar.notification.icon.ui.viewbinder.AlwaysOnDisplayNotificationIconViewStore import com.android.systemui.statusbar.notification.icon.ui.viewbinder.NotificationIconContainerViewBinder import com.android.systemui.statusbar.notification.icon.ui.viewbinder.StatusBarIconViewBindingFailureTracker @@ -117,7 +118,7 @@ constructor( } constraintSet.apply { if (migrateClocksToBlueprint()) { - connect(nicId, TOP, smartspaceViewModel.smartspaceViewId, BOTTOM, bottomMargin) + connect(nicId, TOP, sharedR.id.bc_smartspace_view, BOTTOM, bottomMargin) setGoneMargin(nicId, BOTTOM, bottomMargin) } else { connect(nicId, TOP, R.id.keyguard_status_view, topAlignment, bottomMargin) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt index 656c75c7bfec..b5f32c8a5608 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSection.kt @@ -32,7 +32,6 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor import com.android.systemui.keyguard.shared.model.KeyguardSection import com.android.systemui.keyguard.ui.binder.KeyguardClockViewBinder import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel -import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel import com.android.systemui.plugins.clocks.ClockController import com.android.systemui.plugins.clocks.ClockFaceLayout import com.android.systemui.res.R @@ -55,7 +54,6 @@ open class ClockSection constructor( private val clockInteractor: KeyguardClockInteractor, protected val keyguardClockViewModel: KeyguardClockViewModel, - private val smartspaceViewModel: KeyguardSmartspaceViewModel, private val context: Context, private val splitShadeStateController: SplitShadeStateController, ) : KeyguardSection() { @@ -119,8 +117,8 @@ constructor( com.android.systemui.customization.R.dimen.small_clock_padding_top ) + context.resources.getDimensionPixelSize(R.dimen.keyguard_smartspace_top_offset) - largeClockTopMargin += smartspaceViewModel.getDimen(DATE_WEATHER_VIEW_HEIGHT) - largeClockTopMargin += smartspaceViewModel.getDimen(ENHANCED_SMARTSPACE_HEIGHT) + largeClockTopMargin += getDimen(DATE_WEATHER_VIEW_HEIGHT) + largeClockTopMargin += getDimen(ENHANCED_SMARTSPACE_HEIGHT) if (!keyguardClockViewModel.useLargeClock) { largeClockTopMargin -= context.resources.getDimensionPixelSize( @@ -163,6 +161,12 @@ constructor( } } + private fun getDimen(name: String): Int { + val res = context.packageManager.getResourcesForApplication(context.packageName) + val id = res.getIdentifier(name, "dimen", context.packageName) + return res.getDimensionPixelSize(id) + } + companion object { private const val DATE_WEATHER_VIEW_HEIGHT = "date_weather_view_height" private const val ENHANCED_SMARTSPACE_HEIGHT = "enhanced_smartspace_height" diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultNotificationStackScrollLayoutSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultNotificationStackScrollLayoutSection.kt index e7b6e44450bd..b0eee0a68b1f 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultNotificationStackScrollLayoutSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/DefaultNotificationStackScrollLayoutSection.kt @@ -31,6 +31,7 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel import com.android.systemui.res.R import com.android.systemui.scene.shared.flag.SceneContainerFlags import com.android.systemui.shade.NotificationPanelView +import com.android.systemui.shared.R as sharedR import com.android.systemui.statusbar.notification.stack.AmbientState import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayoutController import com.android.systemui.statusbar.notification.stack.NotificationStackSizeCalculator @@ -80,7 +81,7 @@ constructor( connect( R.id.nssl_placeholder, TOP, - smartspaceViewModel.smartspaceViewId, + sharedR.id.bc_smartspace_view, BOTTOM, bottomMargin ) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSection.kt index 8cd51cd3b1e3..eacd466bc473 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSection.kt @@ -17,6 +17,7 @@ package com.android.systemui.keyguard.ui.view.layout.sections import android.content.Context +import android.view.View import androidx.constraintlayout.widget.ConstraintLayout import androidx.constraintlayout.widget.ConstraintSet import androidx.constraintlayout.widget.ConstraintSet.BOTTOM @@ -44,13 +45,9 @@ constructor( val smartspaceController: LockscreenSmartspaceController, val keyguardUnlockAnimationController: KeyguardUnlockAnimationController, ) : KeyguardSection() { - var smartspaceView by keyguardSmartspaceViewModel::smartspaceView - var weatherView by keyguardSmartspaceViewModel::weatherView - var dateView by keyguardSmartspaceViewModel::dateView - - val smartspaceViewId = keyguardSmartspaceViewModel.smartspaceViewId - val weatherViewId = keyguardSmartspaceViewModel.weatherId - val dateViewId = keyguardSmartspaceViewModel.dateId + private var smartspaceView: View? = null + private var weatherView: View? = null + private var dateView: View? = null override fun addViews(constraintLayout: ConstraintLayout) { if (!migrateClocksToBlueprint()) { diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeClockSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeClockSection.kt index 1302bfa6fc31..19ba1aa4763a 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeClockSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeClockSection.kt @@ -20,7 +20,6 @@ import android.content.Context import androidx.constraintlayout.widget.ConstraintSet import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel -import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel import com.android.systemui.res.R import com.android.systemui.statusbar.policy.SplitShadeStateController import javax.inject.Inject @@ -30,17 +29,9 @@ class SplitShadeClockSection constructor( clockInteractor: KeyguardClockInteractor, keyguardClockViewModel: KeyguardClockViewModel, - smartspaceViewModel: KeyguardSmartspaceViewModel, context: Context, splitShadeStateController: SplitShadeStateController, -) : - ClockSection( - clockInteractor, - keyguardClockViewModel, - smartspaceViewModel, - context, - splitShadeStateController - ) { +) : ClockSection(clockInteractor, keyguardClockViewModel, context, splitShadeStateController) { override fun applyDefaultConstraints(constraints: ConstraintSet) { super.applyDefaultConstraints(constraints) val largeClockEndGuideline = diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeMediaSection.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeMediaSection.kt index 5afdbaa47d95..f20ab06bcda9 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeMediaSection.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/view/layout/sections/SplitShadeMediaSection.kt @@ -35,6 +35,7 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel import com.android.systemui.media.controls.ui.KeyguardMediaController import com.android.systemui.res.R import com.android.systemui.shade.NotificationPanelView +import com.android.systemui.shared.R as sharedR import javax.inject.Inject /** Aligns media on left side for split shade, below smartspace, date, and weather. */ @@ -90,9 +91,9 @@ constructor( Barrier.BOTTOM, 0, *intArrayOf( - keyguardSmartspaceViewModel.smartspaceViewId, - keyguardSmartspaceViewModel.dateId, - keyguardSmartspaceViewModel.weatherId, + sharedR.id.bc_smartspace_view, + sharedR.id.date_smartspace_view, + sharedR.id.weather_smartspace_view, ) ) connect(mediaContainerId, TOP, smartSpaceBarrier, BOTTOM) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModel.kt index 26e7ee8f561b..a1dd720a82f1 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/ui/viewmodel/KeyguardSmartspaceViewModel.kt @@ -16,47 +16,66 @@ package com.android.systemui.keyguard.ui.viewmodel -import android.content.Context -import android.util.Log -import android.view.View import com.android.systemui.dagger.SysUISingleton +import com.android.systemui.dagger.qualifiers.Application import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController import javax.inject.Inject +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.StateFlow +import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.stateIn @SysUISingleton class KeyguardSmartspaceViewModel @Inject -constructor(val context: Context, val smartspaceController: LockscreenSmartspaceController) { +constructor( + @Application applicationScope: CoroutineScope, + smartspaceController: LockscreenSmartspaceController, + keyguardClockViewModel: KeyguardClockViewModel, +) { + /** Whether the smartspace section is available in the build. */ val isSmartspaceEnabled: Boolean = smartspaceController.isEnabled() + /** Whether the weather area is available in the build. */ + // TODO(b/317891876): this should be a Flow as the value can change over time. val isWeatherEnabled: Boolean = smartspaceController.isWeatherEnabled() + /** Whether the data and weather areas are decoupled in the build. */ val isDateWeatherDecoupled: Boolean = smartspaceController.isDateWeatherDecoupled() - val smartspaceViewId: Int - get() = getId("bc_smartspace_view") - val dateId: Int - get() = getId("date_smartspace_view") + /** Whether the date area should be visible. */ + val isDateVisible: StateFlow<Boolean> = + keyguardClockViewModel.hasCustomWeatherDataDisplay + .map { !it } + .stateIn( + scope = applicationScope, + started = SharingStarted.WhileSubscribed(), + initialValue = !keyguardClockViewModel.hasCustomWeatherDataDisplay.value, + ) - val weatherId: Int - get() = getId("weather_smartspace_view") - - var smartspaceView: View? = null - var weatherView: View? = null - var dateView: View? = null - - private fun getId(name: String): Int { - return context.resources.getIdentifier(name, "id", context.packageName).also { - if (it == 0) { - Log.d(TAG, "Cannot resolve id $name") + /** Whether the weather area should be visible. */ + val isWeatherVisible: StateFlow<Boolean> = + keyguardClockViewModel.hasCustomWeatherDataDisplay + .map { clockIncludesCustomWeatherDisplay -> + isWeatherVisible( + clockIncludesCustomWeatherDisplay = clockIncludesCustomWeatherDisplay, + isWeatherEnabled = isWeatherEnabled, + ) } - } - } - fun getDimen(name: String): Int { - val res = context.packageManager.getResourcesForApplication(context.packageName) - val id = res.getIdentifier(name, "dimen", context.packageName) - return res.getDimensionPixelSize(id) - } + .stateIn( + scope = applicationScope, + started = SharingStarted.WhileSubscribed(), + initialValue = + isWeatherVisible( + clockIncludesCustomWeatherDisplay = + keyguardClockViewModel.hasCustomWeatherDataDisplay.value, + isWeatherEnabled = isWeatherEnabled, + ) + ) - companion object { - private val TAG = KeyguardSmartspaceViewModel::class.java.simpleName + private fun isWeatherVisible( + clockIncludesCustomWeatherDisplay: Boolean, + isWeatherEnabled: Boolean, + ): Boolean { + return !clockIncludesCustomWeatherDisplay && isWeatherEnabled } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSectionTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSectionTest.kt index dc0d9c5f987e..070a0ccd1232 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSectionTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/ClockSectionTest.kt @@ -17,21 +17,26 @@ package com.android.systemui.keyguard.ui.view.layout.sections +import android.content.pm.PackageManager +import android.content.res.Resources import androidx.constraintlayout.widget.ConstraintSet import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel -import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel import com.android.systemui.res.R import com.android.systemui.statusbar.policy.SplitShadeStateController import com.android.systemui.util.Utils +import com.android.systemui.util.mockito.eq +import com.android.systemui.util.mockito.mock import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.junit.runners.JUnit4 +import org.mockito.ArgumentMatchers.anyInt +import org.mockito.ArgumentMatchers.anyString import org.mockito.Mock import org.mockito.MockitoAnnotations @@ -40,17 +45,10 @@ import org.mockito.MockitoAnnotations class ClockSectionTest : SysuiTestCase() { @Mock private lateinit var keyguardClockInteractor: KeyguardClockInteractor @Mock private lateinit var keyguardClockViewModel: KeyguardClockViewModel - @Mock private lateinit var smartspaceViewModel: KeyguardSmartspaceViewModel @Mock private lateinit var splitShadeStateController: SplitShadeStateController private lateinit var underTest: ClockSection - // smartspaceViewModel.getDimen("date_weather_view_height") - private val SMART_SPACE_DATE_WEATHER_HEIGHT = 10 - - // smartspaceViewModel.getDimen("enhanced_smartspace_height") - private val ENHANCED_SMART_SPACE_HEIGHT = 11 - private val SMALL_CLOCK_TOP_SPLIT_SHADE = context.resources.getDimensionPixelSize(R.dimen.keyguard_split_shade_top_margin) @@ -75,15 +73,41 @@ class ClockSectionTest : SysuiTestCase() { @Before fun setup() { MockitoAnnotations.initMocks(this) - whenever(smartspaceViewModel.getDimen("date_weather_view_height")) - .thenReturn(SMART_SPACE_DATE_WEATHER_HEIGHT) - whenever(smartspaceViewModel.getDimen("enhanced_smartspace_height")) - .thenReturn(ENHANCED_SMART_SPACE_HEIGHT) + val remoteResources = mock<Resources>() + whenever( + remoteResources.getIdentifier( + anyString(), + eq("dimen"), + anyString(), + ) + ) + .then { invocation -> + val name = invocation.arguments[0] as String + val index = DIMENSION_BY_IDENTIFIER_NAME.indexOfFirst { (key, _) -> key == name } + if (index == -1) { + error( + "No entry for a dimension named \"$name\", please add it to the list above." + ) + } + index + } + whenever( + remoteResources.getDimensionPixelSize( + anyInt(), + ) + ) + .then { invocation -> + val id = invocation.arguments[0] as Int + DIMENSION_BY_IDENTIFIER_NAME[id].second + } + val packageManager = mock<PackageManager>() + whenever(packageManager.getResourcesForApplication(anyString())).thenReturn(remoteResources) + mContext.setMockPackageManager(packageManager) + underTest = ClockSection( keyguardClockInteractor, keyguardClockViewModel, - smartspaceViewModel, mContext, splitShadeStateController, ) @@ -164,4 +188,14 @@ class ClockSectionTest : SysuiTestCase() { assertThat(smallClockConstraint.layout.topToTop).isEqualTo(ConstraintSet.PARENT_ID) assertThat(smallClockConstraint.layout.topMargin).isEqualTo(expectedSmallClockTopMargin) } + + companion object { + private val SMART_SPACE_DATE_WEATHER_HEIGHT = 10 + private val ENHANCED_SMART_SPACE_HEIGHT = 11 + private val DIMENSION_BY_IDENTIFIER_NAME = + listOf( + "date_weather_view_height" to SMART_SPACE_DATE_WEATHER_HEIGHT, + "enhanced_smartspace_height" to ENHANCED_SMART_SPACE_HEIGHT, + ) + } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSectionTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSectionTest.kt index 740110b4fee0..28da957d31b0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSectionTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/ui/view/layout/sections/SmartspaceSectionTest.kt @@ -29,7 +29,9 @@ import com.android.systemui.keyguard.KeyguardUnlockAnimationController import com.android.systemui.keyguard.ui.viewmodel.KeyguardClockViewModel import com.android.systemui.keyguard.ui.viewmodel.KeyguardSmartspaceViewModel import com.android.systemui.res.R +import com.android.systemui.shared.R as sharedR import com.android.systemui.statusbar.lockscreen.LockscreenSmartspaceController +import com.android.systemui.util.mockito.any import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.StateFlow @@ -50,9 +52,9 @@ class SmartspaceSectionTest : SysuiTestCase() { @Mock private lateinit var keyguardUnlockAnimationController: KeyguardUnlockAnimationController @Mock private lateinit var hasCustomWeatherDataDisplay: StateFlow<Boolean> - private val smartspaceView = View(mContext).also { it.id = View.generateViewId() } - private val weatherView = View(mContext).also { it.id = View.generateViewId() } - private val dateView = View(mContext).also { it.id = View.generateViewId() } + private val smartspaceView = View(mContext).also { it.id = sharedR.id.bc_smartspace_view } + private val weatherView = View(mContext).also { it.id = sharedR.id.weather_smartspace_view } + private val dateView = View(mContext).also { it.id = sharedR.id.date_smartspace_view } private lateinit var constraintLayout: ConstraintLayout private lateinit var constraintSet: ConstraintSet @@ -69,13 +71,13 @@ class SmartspaceSectionTest : SysuiTestCase() { keyguardUnlockAnimationController, ) constraintLayout = ConstraintLayout(mContext) - whenever(keyguardSmartspaceViewModel.smartspaceView).thenReturn(smartspaceView) - whenever(keyguardSmartspaceViewModel.weatherView).thenReturn(weatherView) - whenever(keyguardSmartspaceViewModel.dateView).thenReturn(dateView) + whenever(lockscreenSmartspaceController.buildAndConnectView(any())) + .thenReturn(smartspaceView) + whenever(lockscreenSmartspaceController.buildAndConnectWeatherView(any())) + .thenReturn(weatherView) + whenever(lockscreenSmartspaceController.buildAndConnectDateView(any())).thenReturn(dateView) whenever(keyguardClockViewModel.hasCustomWeatherDataDisplay) .thenReturn(hasCustomWeatherDataDisplay) - whenever(keyguardSmartspaceViewModel.smartspaceController) - .thenReturn(lockscreenSmartspaceController) constraintSet = ConstraintSet() } |