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

Commit 5219ede6 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Add categories to tiles for edit mode" into main

parents f9555e6b 29e39741
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -17,9 +17,12 @@

package com.android.systemui.common.ui.compose

import android.content.Context
import androidx.compose.runtime.Composable
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.AnnotatedString
import com.android.systemui.common.shared.model.Text
import com.android.systemui.common.shared.model.Text.Companion.loadText

/** Returns the loaded [String] or `null` if there isn't one. */
@Composable
@@ -29,3 +32,7 @@ fun Text.load(): String? {
        is Text.Resource -> stringResource(res)
    }
}

fun Text.toAnnotatedString(context: Context): AnnotatedString? {
    return loadText(context)?.let { AnnotatedString(it) }
}
+4 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.qs.panels.data.repository
import android.content.ComponentName
import android.content.packageManager
import android.content.pm.PackageManager
import android.content.pm.ServiceInfo
import android.content.pm.UserInfo
import android.graphics.drawable.TestStubDrawable
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -35,6 +34,7 @@ import com.android.systemui.qs.pipeline.data.repository.FakeInstalledTilesCompon
import com.android.systemui.qs.pipeline.data.repository.fakeInstalledTilesRepository
import com.android.systemui.qs.pipeline.data.repository.installedTilesRepository
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.shared.model.TileCategory
import com.android.systemui.settings.FakeUserTracker
import com.android.systemui.settings.fakeUserTracker
import com.android.systemui.testKosmos
@@ -100,6 +100,7 @@ class IconAndNameCustomRepositoryTest : SysuiTestCase() {
                        Icon.Loaded(drawable1, ContentDescription.Loaded(tileService1)),
                        Text.Loaded(tileService1),
                        Text.Loaded(appName1),
                        TileCategory.PROVIDED_BY_APP,
                    )
                val expectedData2 =
                    EditTileData(
@@ -107,6 +108,7 @@ class IconAndNameCustomRepositoryTest : SysuiTestCase() {
                        Icon.Loaded(drawable2, ContentDescription.Loaded(tileService2)),
                        Text.Loaded(tileService2),
                        Text.Loaded(appName2),
                        TileCategory.PROVIDED_BY_APP,
                    )

                assertThat(editTileDataList).containsExactly(expectedData1, expectedData2)
@@ -144,6 +146,7 @@ class IconAndNameCustomRepositoryTest : SysuiTestCase() {
                        Icon.Loaded(drawable1, ContentDescription.Loaded(tileService1)),
                        Text.Loaded(tileService1),
                        Text.Loaded(appName1),
                        TileCategory.PROVIDED_BY_APP,
                    )

                val editTileDataList = underTest.getCustomTileData()
+5 −1
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.qs.panels.shared.model.EditTileData
import com.android.systemui.qs.pipeline.data.repository.FakeInstalledTilesComponentRepository
import com.android.systemui.qs.pipeline.data.repository.fakeInstalledTilesRepository
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.shared.model.TileCategory
import com.android.systemui.qs.tiles.impl.battery.qsBatterySaverTileConfig
import com.android.systemui.qs.tiles.impl.flashlight.qsFlashlightTileConfig
import com.android.systemui.qs.tiles.impl.internet.qsInternetTileConfig
@@ -132,6 +133,7 @@ class EditTilesListInteractorTest : SysuiTestCase() {
                        icon = Icon.Loaded(icon, ContentDescription.Loaded(tileName)),
                        label = Text.Loaded(tileName),
                        appName = Text.Loaded(appName),
                        category = TileCategory.PROVIDED_BY_APP,
                    )

                assertThat(editTiles.customTiles).hasSize(1)
@@ -181,7 +183,8 @@ class EditTilesListInteractorTest : SysuiTestCase() {
                tileSpec = this,
                icon = Icon.Resource(android.R.drawable.star_on, ContentDescription.Loaded(spec)),
                label = Text.Loaded(spec),
                appName = null
                appName = null,
                category = TileCategory.UNKNOWN,
            )
        }

@@ -192,6 +195,7 @@ class EditTilesListInteractorTest : SysuiTestCase() {
                    Icon.Resource(uiConfig.iconRes, ContentDescription.Resource(uiConfig.labelRes)),
                label = Text.Resource(uiConfig.labelRes),
                appName = null,
                category = category,
            )
        }
    }
+4 −2
Original line number Diff line number Diff line
@@ -16,11 +16,11 @@

package com.android.systemui.qs.panels.ui.compose

import androidx.compose.ui.text.AnnotatedString
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.Text
import com.android.systemui.qs.panels.shared.model.SizedTile
import com.android.systemui.qs.panels.shared.model.SizedTileImpl
import com.android.systemui.qs.panels.ui.model.GridCell
@@ -28,6 +28,7 @@ import com.android.systemui.qs.panels.ui.model.SpacerGridCell
import com.android.systemui.qs.panels.ui.model.TileGridCell
import com.android.systemui.qs.panels.ui.viewmodel.EditTileViewModel
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.shared.model.TileCategory
import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
@@ -141,10 +142,11 @@ class EditTileListStateTest : SysuiTestCase() {
                EditTileViewModel(
                    tileSpec = TileSpec.create(tileSpec),
                    icon = Icon.Resource(0, null),
                    label = Text.Loaded("unused"),
                    label = AnnotatedString("unused"),
                    appName = null,
                    isCurrent = true,
                    availableEditActions = emptySet(),
                    category = TileCategory.UNKNOWN,
                ),
                width,
            )
+14 −6
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.common.shared.model.ContentDescription
import com.android.systemui.common.shared.model.Icon
import com.android.systemui.common.shared.model.Text
import com.android.systemui.common.ui.compose.toAnnotatedString
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
@@ -42,6 +43,7 @@ import com.android.systemui.qs.pipeline.data.repository.fakeMinimumTilesReposito
import com.android.systemui.qs.pipeline.domain.interactor.currentTilesInteractor
import com.android.systemui.qs.pipeline.shared.TileSpec
import com.android.systemui.qs.qsTileFactory
import com.android.systemui.qs.shared.model.TileCategory
import com.android.systemui.qs.tiles.impl.alarm.qsAlarmTileConfig
import com.android.systemui.qs.tiles.impl.battery.qsBatterySaverTileConfig
import com.android.systemui.qs.tiles.impl.flashlight.qsFlashlightTileConfig
@@ -190,7 +192,7 @@ class EditModeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    .forEach {
                        val data = getEditTileData(it.tileSpec)

                        assertThat(it.label).isEqualTo(data.label)
                        assertThat(it.label).isEqualTo(data.label.toAnnotatedString(context))
                        assertThat(it.icon).isEqualTo(data.icon)
                        assertThat(it.appName).isNull()
                    }
@@ -224,15 +226,19 @@ class EditModeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {

                // service1
                val model1 = tiles!!.first { it.tileSpec == TileSpec.create(component1) }
                assertThat(model1.label).isEqualTo(Text.Loaded(tileService1))
                assertThat(model1.appName).isEqualTo(Text.Loaded(appName1))
                assertThat(model1.label)
                    .isEqualTo(Text.Loaded(tileService1).toAnnotatedString(context))
                assertThat(model1.appName)
                    .isEqualTo(Text.Loaded(appName1).toAnnotatedString(context))
                assertThat(model1.icon)
                    .isEqualTo(Icon.Loaded(drawable1, ContentDescription.Loaded(tileService1)))

                // service2
                val model2 = tiles!!.first { it.tileSpec == TileSpec.create(component2) }
                assertThat(model2.label).isEqualTo(Text.Loaded(tileService2))
                assertThat(model2.appName).isEqualTo(Text.Loaded(appName2))
                assertThat(model2.label)
                    .isEqualTo(Text.Loaded(tileService2).toAnnotatedString(context))
                assertThat(model2.appName)
                    .isEqualTo(Text.Loaded(appName2).toAnnotatedString(context))
                assertThat(model2.icon)
                    .isEqualTo(Icon.Loaded(drawable2, ContentDescription.Loaded(tileService2)))
            }
@@ -559,7 +565,8 @@ class EditModeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                tileSpec = this,
                icon = Icon.Resource(R.drawable.star_on, ContentDescription.Loaded(spec)),
                label = Text.Loaded(spec),
                appName = null
                appName = null,
                category = TileCategory.UNKNOWN,
            )
        }

@@ -570,6 +577,7 @@ class EditModeViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                    Icon.Resource(uiConfig.iconRes, ContentDescription.Resource(uiConfig.labelRes)),
                label = Text.Resource(uiConfig.labelRes),
                appName = null,
                category = category,
            )
        }

Loading