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

Commit c420ad71 authored by Darrell Shi's avatar Darrell Shi
Browse files

Show allowlisted widgets in communal hub

- Update the layout library to pass the size information back to the
  composable
- Each AppWidgetHostView updates the provider with the correct size
  information provided above
- Before the local database is set up, the repository unbinds each
  previously bound widget, and rebinds each widget from the allowlist

Test: atest CommunalWidgetRepositoryImplTest
Test: verified widgets showing by following go/enable_glanceable_hub
Bug: 305284915
Fix: 305284915

Change-Id: I50ca3d68538bb4efcb8b6356e96b34a4330df360
parent a549ad5e
Loading
Loading
Loading
Loading
+9 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.systemui.communal.layout.ui.compose
package com.android.systemui.communal.layout.ui.compose


import android.util.SizeF
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Row
@@ -54,7 +55,14 @@ fun CommunalGridLayout(
                        Row(
                        Row(
                            modifier = Modifier.height(layoutConfig.cardHeight(cardInfo.size)),
                            modifier = Modifier.height(layoutConfig.cardHeight(cardInfo.size)),
                        ) {
                        ) {
                            cardInfo.card.Content(Modifier.fillMaxSize())
                            cardInfo.card.Content(
                                modifier = Modifier.fillMaxSize(),
                                size =
                                    SizeF(
                                        layoutConfig.cardWidth.value,
                                        layoutConfig.cardHeight(cardInfo.size).value,
                                    ),
                            )
                        }
                        }
                    }
                    }
                }
                }
+5 −1
Original line number Original line Diff line number Diff line
@@ -16,6 +16,7 @@


package com.android.systemui.communal.layout.ui.compose.config
package com.android.systemui.communal.layout.ui.compose.config


import android.util.SizeF
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.Modifier


@@ -26,8 +27,11 @@ abstract class CommunalGridLayoutCard {
     *
     *
     * To host non-Compose views, see
     * To host non-Compose views, see
     * https://developer.android.com/jetpack/compose/migrate/interoperability-apis/views-in-compose.
     * https://developer.android.com/jetpack/compose/migrate/interoperability-apis/views-in-compose.
     *
     * @param size The size given to the card. Content of the card should fill all this space, given
     *   that margins and paddings have been taken care of by the layout.
     */
     */
    @Composable abstract fun Content(modifier: Modifier)
    @Composable abstract fun Content(modifier: Modifier, size: SizeF)


    /**
    /**
     * Sizes supported by the card.
     * Sizes supported by the card.
+2 −1
Original line number Original line Diff line number Diff line
package com.android.systemui.communal.layout
package com.android.systemui.communal.layout


import android.util.SizeF
import androidx.compose.material3.Card
import androidx.compose.material3.Card
import androidx.compose.runtime.Composable
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.Modifier
@@ -91,7 +92,7 @@ class CommunalLayoutEngineTest {
            override val supportedSizes = listOf(size)
            override val supportedSizes = listOf(size)


            @Composable
            @Composable
            override fun Content(modifier: Modifier) {
            override fun Content(modifier: Modifier, size: SizeF) {
                Card(modifier = modifier, content = {})
                Card(modifier = modifier, content = {})
            }
            }
        }
        }
+38 −2
Original line number Original line Diff line number Diff line
package com.android.systemui.communal.ui.compose
package com.android.systemui.communal.ui.compose


import android.appwidget.AppWidgetHostView
import android.os.Bundle
import android.util.SizeF
import androidx.compose.foundation.background
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxSize
@@ -12,9 +15,12 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.res.integerResource
import androidx.compose.ui.res.integerResource
import androidx.compose.ui.viewinterop.AndroidView
import com.android.systemui.communal.layout.ui.compose.CommunalGridLayout
import com.android.systemui.communal.layout.ui.compose.CommunalGridLayout
import com.android.systemui.communal.layout.ui.compose.config.CommunalGridLayoutCard
import com.android.systemui.communal.layout.ui.compose.config.CommunalGridLayoutCard
import com.android.systemui.communal.layout.ui.compose.config.CommunalGridLayoutConfig
import com.android.systemui.communal.layout.ui.compose.config.CommunalGridLayoutConfig
import com.android.systemui.communal.shared.model.CommunalContentSize
import com.android.systemui.communal.ui.model.CommunalContentUiModel
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.res.R
import com.android.systemui.res.R


@@ -24,6 +30,7 @@ fun CommunalHub(
    viewModel: CommunalViewModel,
    viewModel: CommunalViewModel,
) {
) {
    val showTutorial by viewModel.showTutorialContent.collectAsState(initial = false)
    val showTutorial by viewModel.showTutorialContent.collectAsState(initial = false)
    val widgetContent by viewModel.widgetContent.collectAsState(initial = emptyList())
    Box(
    Box(
        modifier = modifier.fillMaxSize().background(Color.White),
        modifier = modifier.fillMaxSize().background(Color.White),
    ) {
    ) {
@@ -36,7 +43,7 @@ fun CommunalHub(
                    gridHeight = dimensionResource(R.dimen.communal_grid_height),
                    gridHeight = dimensionResource(R.dimen.communal_grid_height),
                    gridColumnsPerCard = integerResource(R.integer.communal_grid_columns_per_card),
                    gridColumnsPerCard = integerResource(R.integer.communal_grid_columns_per_card),
                ),
                ),
            communalCards = if (showTutorial) tutorialContent else emptyList(),
            communalCards = if (showTutorial) tutorialContent else widgetContent.map(::contentCard),
        )
        )
    }
    }
}
}
@@ -58,8 +65,37 @@ private fun tutorialCard(size: CommunalGridLayoutCard.Size): CommunalGridLayoutC
        override val supportedSizes = listOf(size)
        override val supportedSizes = listOf(size)


        @Composable
        @Composable
        override fun Content(modifier: Modifier) {
        override fun Content(modifier: Modifier, size: SizeF) {
            Card(modifier = modifier, content = {})
            Card(modifier = modifier, content = {})
        }
        }
    }
    }
}
}

private fun contentCard(model: CommunalContentUiModel): CommunalGridLayoutCard {
    return object : CommunalGridLayoutCard() {
        override val supportedSizes = listOf(convertToCardSize(model.size))
        override val priority = model.priority

        @Composable
        override fun Content(modifier: Modifier, size: SizeF) {
            AndroidView(
                modifier = modifier,
                factory = {
                    model.view.apply {
                        if (this is AppWidgetHostView) {
                            updateAppWidgetSize(Bundle(), listOf(size))
                        }
                    }
                },
            )
        }
    }
}

private fun convertToCardSize(size: CommunalContentSize): CommunalGridLayoutCard.Size {
    return when (size) {
        CommunalContentSize.FULL -> CommunalGridLayoutCard.Size.FULL
        CommunalContentSize.HALF -> CommunalGridLayoutCard.Size.HALF
        CommunalContentSize.THIRD -> CommunalGridLayoutCard.Size.THIRD
    }
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -16,7 +16,7 @@


package com.android.systemui.communal.data.model
package com.android.systemui.communal.data.model


import com.android.systemui.communal.shared.CommunalContentSize
import com.android.systemui.communal.shared.model.CommunalContentSize


/** Metadata for the default widgets */
/** Metadata for the default widgets */
data class CommunalWidgetMetadata(
data class CommunalWidgetMetadata(
Loading