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

Commit f5a43e55 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Removing duplicated Add Widget button from glanceable hub grid" into main

parents 91147a2c 0ce435f3
Loading
Loading
Loading
Loading
+0 −41
Original line number Diff line number Diff line
@@ -669,8 +669,6 @@ private fun CommunalContent(
        is CommunalContentModel.WidgetContent.DisabledWidget ->
            DisabledWidgetPlaceholder(model, viewModel, modifier)
        is CommunalContentModel.CtaTileInViewMode -> CtaTileInViewModeContent(viewModel, modifier)
        is CommunalContentModel.CtaTileInEditMode ->
            CtaTileInEditModeContent(modifier, onOpenWidgetPicker)
        is CommunalContentModel.Smartspace -> SmartspaceContent(model, modifier)
        is CommunalContentModel.Tutorial -> TutorialContent(modifier)
        is CommunalContentModel.Umo -> Umo(viewModel, modifier)
@@ -756,45 +754,6 @@ private fun CtaTileInViewModeContent(
    }
}

/** Presents a CTA tile at the end of the hub in edit mode, to add more widgets. */
@Composable
private fun CtaTileInEditModeContent(
    modifier: Modifier = Modifier,
    onOpenWidgetPicker: (() -> Unit)? = null,
) {
    if (onOpenWidgetPicker == null) {
        throw IllegalArgumentException("onOpenWidgetPicker should not be null.")
    }
    val colors = LocalAndroidColorScheme.current
    Card(
        modifier = modifier,
        colors = CardDefaults.cardColors(containerColor = Color.Transparent),
        border = BorderStroke(1.dp, colors.primary),
        shape = RoundedCornerShape(200.dp),
        onClick = onOpenWidgetPicker,
    ) {
        Column(
            modifier = Modifier.fillMaxSize(),
            verticalArrangement =
                Arrangement.spacedBy(Dimensions.Spacing, Alignment.CenterVertically),
            horizontalAlignment = Alignment.CenterHorizontally,
        ) {
            Icon(
                imageVector = Icons.Outlined.Widgets,
                contentDescription = stringResource(R.string.cta_label_to_open_widget_picker),
                tint = colors.primary,
                modifier = Modifier.size(Dimensions.IconSize),
            )
            Text(
                text = stringResource(R.string.cta_label_to_open_widget_picker),
                style = MaterialTheme.typography.titleLarge,
                color = colors.primary,
                textAlign = TextAlign.Center,
            )
        }
    }
}

@Composable
private fun WidgetContent(
    viewModel: BaseCommunalViewModel,
+3 −9
Original line number Diff line number Diff line
@@ -149,13 +149,11 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
            val communalContent by collectLastValue(underTest.communalContent)

            // Only Widgets and CTA tile are shown.
            assertThat(communalContent?.size).isEqualTo(3)
            assertThat(communalContent?.size).isEqualTo(2)
            assertThat(communalContent?.get(0))
                .isInstanceOf(CommunalContentModel.WidgetContent::class.java)
            assertThat(communalContent?.get(1))
                .isInstanceOf(CommunalContentModel.WidgetContent::class.java)
            assertThat(communalContent?.get(2))
                .isInstanceOf(CommunalContentModel.CtaTileInEditMode::class.java)
        }

    @Test
@@ -195,24 +193,20 @@ class CommunalEditModeViewModelTest : SysuiTestCase() {
            val communalContent by collectLastValue(underTest.communalContent)

            // Widgets and CTA tile are shown.
            assertThat(communalContent?.size).isEqualTo(3)
            assertThat(communalContent?.size).isEqualTo(2)
            assertThat(communalContent?.get(0))
                .isInstanceOf(CommunalContentModel.WidgetContent::class.java)
            assertThat(communalContent?.get(1))
                .isInstanceOf(CommunalContentModel.WidgetContent::class.java)
            assertThat(communalContent?.get(2))
                .isInstanceOf(CommunalContentModel.CtaTileInEditMode::class.java)

            underTest.onDeleteWidget(widgets.get(0).appWidgetId)

            // Only one widget and CTA tile remain.
            assertThat(communalContent?.size).isEqualTo(2)
            assertThat(communalContent?.size).isEqualTo(1)
            val item = communalContent?.get(0)
            val appWidgetId =
                if (item is CommunalContentModel.WidgetContent) item.appWidgetId else null
            assertThat(appWidgetId).isEqualTo(widgets.get(1).appWidgetId)
            assertThat(communalContent?.get(1))
                .isInstanceOf(CommunalContentModel.CtaTileInEditMode::class.java)
        }

    @Test
+0 −7
Original line number Diff line number Diff line
@@ -91,13 +91,6 @@ sealed interface CommunalContentModel {
        override val size = CommunalContentSize.HALF
    }

    /** A CTA tile in the glanceable hub edit model which remains visible in the grid. */
    class CtaTileInEditMode : CommunalContentModel {
        override val key: String = KEY.CTA_TILE_IN_EDIT_MODE_KEY
        // Same as widget size.
        override val size = CommunalContentSize.HALF
    }

    class Tutorial(
        id: Int,
        override var size: CommunalContentSize,
+3 −6
Original line number Diff line number Diff line
@@ -43,7 +43,6 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.withContext

@@ -66,9 +65,7 @@ constructor(

    // Only widgets are editable. The CTA tile comes last in the list and remains visible.
    override val communalContent: Flow<List<CommunalContentModel>> =
        communalInteractor.widgetContent
            .map { widgets -> widgets + listOf(CommunalContentModel.CtaTileInEditMode()) }
            .onEach { models ->
        communalInteractor.widgetContent.onEach { models ->
            logger.d({ "Content updated: $str1" }) { str1 = models.joinToString { it.key } }
        }