Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2846c58b authored by Sherry Zhou's avatar Sherry Zhou
Browse files

Fix clock/smartspace uses wrong dimension resources in multi-crop preview

For preview, we should use previewContext to load correct dimension

Test: manual
Flag: ACONFIG com.android.systemui.migrate_clocks_to_blueprint STAGING
Bug: 331817016

Change-Id: I28de295136b064cebe19fb7ed29b8b3ac9603a70
parent a6c4eca0
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ object KeyguardPreviewSmartspaceViewBinder {

    @JvmStatic
    fun bind(
        context: Context,
        previewContext: Context,
        smartspace: View,
        splitShadePreview: Boolean,
        viewModel: KeyguardPreviewSmartspaceViewModel,
@@ -46,10 +46,12 @@ object KeyguardPreviewSmartspaceViewBinder {
                                SettingsClockSize.DYNAMIC ->
                                    viewModel.getLargeClockSmartspaceTopPadding(
                                        splitShadePreview,
                                        previewContext,
                                    )
                                SettingsClockSize.SMALL ->
                                    viewModel.getSmallClockSmartspaceTopPadding(
                                        splitShadePreview,
                                        previewContext,
                                    )
                            }
                        smartspace.setTopPadding(topPadding)
+8 −5
Original line number Diff line number Diff line
@@ -327,9 +327,12 @@ constructor(
        smartSpaceView = lockscreenSmartspaceController.buildAndConnectDateView(parentView)

        val topPadding: Int =
            smartspaceViewModel.getLargeClockSmartspaceTopPadding(previewInSplitShade())
        val startPadding: Int = smartspaceViewModel.getSmartspaceStartPadding()
        val endPadding: Int = smartspaceViewModel.getSmartspaceEndPadding()
            smartspaceViewModel.getLargeClockSmartspaceTopPadding(
                previewInSplitShade(),
                previewContext,
            )
        val startPadding: Int = smartspaceViewModel.getSmartspaceStartPadding(previewContext)
        val endPadding: Int = smartspaceViewModel.getSmartspaceEndPadding(previewContext)

        smartSpaceView?.let {
            it.setPaddingRelative(startPadding, topPadding, endPadding, 0)
@@ -411,7 +414,7 @@ constructor(
            setUpClock(previewContext, rootView)
            if (MigrateClocksToBlueprint.isEnabled) {
                KeyguardPreviewClockViewBinder.bind(
                    context,
                    previewContext,
                    keyguardRootView,
                    clockViewModel,
                    ::updateClockAppearance
@@ -429,7 +432,7 @@ constructor(

        smartSpaceView?.let {
            KeyguardPreviewSmartspaceViewBinder.bind(
                context,
                previewContext,
                it,
                previewInSplitShade(),
                smartspaceViewModel
+0 −5
Original line number Diff line number Diff line
@@ -16,13 +16,10 @@

package com.android.systemui.keyguard.ui.viewmodel

import android.content.Context
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.shared.model.SettingsClockSize
import com.android.systemui.plugins.clocks.ClockController
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
@@ -31,9 +28,7 @@ import kotlinx.coroutines.flow.map
class KeyguardPreviewClockViewModel
@Inject
constructor(
    @Application private val context: Context,
    interactor: KeyguardClockInteractor,
    @Application private val applicationScope: CoroutineScope,
) {

    var shouldHighlightSelectedAffordance: Boolean = false
+7 −9
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.systemui.keyguard.ui.viewmodel

import android.content.Context
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.domain.interactor.KeyguardClockInteractor
import com.android.systemui.keyguard.shared.model.SettingsClockSize
import com.android.systemui.res.R
@@ -31,7 +30,6 @@ import kotlinx.coroutines.flow.map
class KeyguardPreviewSmartspaceViewModel
@Inject
constructor(
    @Application private val context: Context,
    interactor: KeyguardClockInteractor,
    val smartspaceViewModel: KeyguardSmartspaceViewModel,
    val clockViewModel: KeyguardClockViewModel,
@@ -55,29 +53,29 @@ constructor(
                }
            }

    fun getSmartspaceStartPadding(): Int {
    fun getSmartspaceStartPadding(context: Context): Int {
        return KeyguardSmartspaceViewModel.getSmartspaceStartMargin(context)
    }

    fun getSmartspaceEndPadding(): Int {
    fun getSmartspaceEndPadding(context: Context): Int {
        return KeyguardSmartspaceViewModel.getSmartspaceEndMargin(context)
    }

    fun getSmallClockSmartspaceTopPadding(splitShadePreview: Boolean): Int {
        return getSmallClockTopPadding(splitShadePreview) +
    fun getSmallClockSmartspaceTopPadding(splitShadePreview: Boolean, context: Context): Int {
        return getSmallClockTopPadding(splitShadePreview, context) +
            context.resources.getDimensionPixelSize(
                com.android.systemui.customization.R.dimen.small_clock_height
            )
    }

    fun getLargeClockSmartspaceTopPadding(splitShadePreview: Boolean): Int {
        return getSmallClockTopPadding(splitShadePreview)
    fun getLargeClockSmartspaceTopPadding(splitShadePreview: Boolean, context: Context): Int {
        return getSmallClockTopPadding(splitShadePreview, context)
    }

    /*
     * SmallClockTopPadding decides the top position of smartspace
     */
    private fun getSmallClockTopPadding(splitShadePreview: Boolean): Int {
    private fun getSmallClockTopPadding(splitShadePreview: Boolean, context: Context): Int {
        return with(context.resources) {
            if (splitShadePreview) {
                getDimensionPixelSize(R.dimen.keyguard_split_shade_top_margin)