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

Commit 4d771903 authored by Anton Potapov's avatar Anton Potapov Committed by Android (Google) Code Review
Browse files

Merge "Use theme in the mapper to load icons" into main

parents 89de725c 22a57b8f
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.qs.tiles.impl.alarm.domain

import android.app.AlarmManager
import android.graphics.drawable.TestStubDrawable
import android.widget.Switch
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -40,7 +41,14 @@ class AlarmTileMapperTest : SysuiTestCase() {
    private val kosmos = Kosmos()
    private val alarmTileConfig = kosmos.qsAlarmTileConfig
    // Using lazy (versus =) to make sure we override the right context -- see b/311612168
    private val mapper by lazy { AlarmTileMapper(context.orCreateTestableResources.resources) }
    private val mapper by lazy {
        AlarmTileMapper(
            context.orCreateTestableResources
                .apply { addOverride(R.drawable.ic_alarm, TestStubDrawable()) }
                .resources,
            context.theme
        )
    }

    @Test
    fun notAlarmSet() {
@@ -100,7 +108,7 @@ class AlarmTileMapperTest : SysuiTestCase() {
    ): QSTileState {
        val label = context.getString(R.string.status_bar_alarm)
        return QSTileState(
            { Icon.Resource(R.drawable.ic_alarm, null) },
            { Icon.Loaded(context.getDrawable(R.drawable.ic_alarm)!!, null) },
            label,
            activationState,
            secondaryLabel,
+16 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.qs.tiles.impl.flashlight.domain

import android.graphics.drawable.TestStubDrawable
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -35,7 +36,17 @@ import org.junit.runner.RunWith
class FlashlightMapperTest : SysuiTestCase() {
    private val kosmos = Kosmos()
    private val qsTileConfig = kosmos.qsFlashlightTileConfig
    private val mapper by lazy { FlashlightMapper(context.orCreateTestableResources.resources) }
    private val mapper by lazy {
        FlashlightMapper(
            context.orCreateTestableResources
                .apply {
                    addOverride(R.drawable.qs_flashlight_icon_off, TestStubDrawable())
                    addOverride(R.drawable.qs_flashlight_icon_on, TestStubDrawable())
                }
                .resources,
            context.theme
        )
    }

    @Test
    fun mapsDisabledDataToInactiveState() {
@@ -56,20 +67,20 @@ class FlashlightMapperTest : SysuiTestCase() {

    @Test
    fun mapsEnabledDataToOnIconState() {
        val expectedIcon = Icon.Resource(R.drawable.qs_flashlight_icon_on, null)

        val tileState: QSTileState = mapper.map(qsTileConfig, FlashlightTileModel(true))

        val expectedIcon =
            Icon.Loaded(context.getDrawable(R.drawable.qs_flashlight_icon_on)!!, null)
        val actualIcon = tileState.icon()
        assertThat(actualIcon).isEqualTo(expectedIcon)
    }

    @Test
    fun mapsDisabledDataToOffIconState() {
        val expectedIcon = Icon.Resource(R.drawable.qs_flashlight_icon_off, null)

        val tileState: QSTileState = mapper.map(qsTileConfig, FlashlightTileModel(false))

        val expectedIcon =
            Icon.Loaded(context.getDrawable(R.drawable.qs_flashlight_icon_off)!!, null)
        val actualIcon = tileState.icon()
        assertThat(actualIcon).isEqualTo(expectedIcon)
    }
+14 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.qs.tiles.impl.location.domain

import android.graphics.drawable.TestStubDrawable
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -36,7 +37,17 @@ class LocationTileMapperTest : SysuiTestCase() {
    private val kosmos = Kosmos()
    private val qsTileConfig = kosmos.qsLocationTileConfig

    private val mapper by lazy { LocationTileMapper(context.orCreateTestableResources.resources) }
    private val mapper by lazy {
        LocationTileMapper(
            context.orCreateTestableResources
                .apply {
                    addOverride(R.drawable.qs_location_icon_off, TestStubDrawable())
                    addOverride(R.drawable.qs_location_icon_on, TestStubDrawable())
                }
                .resources,
            context.theme
        )
    }

    @Test
    fun mapsDisabledDataToInactiveState() {
@@ -56,20 +67,18 @@ class LocationTileMapperTest : SysuiTestCase() {

    @Test
    fun mapsEnabledDataToOnIconState() {
        val expectedIcon = Icon.Resource(R.drawable.qs_location_icon_on, null)

        val tileState: QSTileState = mapper.map(qsTileConfig, LocationTileModel(true))

        val expectedIcon = Icon.Loaded(context.getDrawable(R.drawable.qs_location_icon_on)!!, null)
        val actualIcon = tileState.icon()
        Truth.assertThat(actualIcon).isEqualTo(expectedIcon)
    }

    @Test
    fun mapsDisabledDataToOffIconState() {
        val expectedIcon = Icon.Resource(R.drawable.qs_location_icon_off, null)

        val tileState: QSTileState = mapper.map(qsTileConfig, LocationTileModel(false))

        val expectedIcon = Icon.Loaded(context.getDrawable(R.drawable.qs_location_icon_off)!!, null)
        val actualIcon = tileState.icon()
        Truth.assertThat(actualIcon).isEqualTo(expectedIcon)
    }
+13 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.qs.tiles.impl.saver.domain

import android.graphics.drawable.TestStubDrawable
import android.widget.Switch
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
@@ -37,7 +38,17 @@ class DataSaverTileMapperTest : SysuiTestCase() {
    private val dataSaverTileConfig = kosmos.qsDataSaverTileConfig

    // Using lazy (versus =) to make sure we override the right context -- see b/311612168
    private val mapper by lazy { DataSaverTileMapper(context.orCreateTestableResources.resources) }
    private val mapper by lazy {
        DataSaverTileMapper(
            context.orCreateTestableResources
                .apply {
                    addOverride(R.drawable.qs_data_saver_icon_off, TestStubDrawable())
                    addOverride(R.drawable.qs_data_saver_icon_on, TestStubDrawable())
                }
                .resources,
            context.theme
        )
    }

    @Test
    fun activeStateMatchesEnabledModel() {
@@ -80,7 +91,7 @@ class DataSaverTileMapperTest : SysuiTestCase() {
            else context.resources.getStringArray(R.array.tile_states_saver)[0]

        return QSTileState(
            { Icon.Resource(iconRes, null) },
            { Icon.Loaded(context.getDrawable(iconRes)!!, null) },
            label,
            activationState,
            secondaryLabel,
+11 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.qs.tiles.impl.uimodenight.domain

import android.app.UiModeManager
import android.graphics.drawable.TestStubDrawable
import android.text.TextUtils
import android.view.View
import android.widget.Switch
@@ -41,7 +42,15 @@ class UiModeNightTileMapperTest : SysuiTestCase() {
    private val qsTileConfig = kosmos.qsUiModeNightTileConfig

    private val mapper by lazy {
        UiModeNightTileMapper(context.orCreateTestableResources.resources)
        UiModeNightTileMapper(
            context.orCreateTestableResources
                .apply {
                    addOverride(R.drawable.qs_light_dark_theme_icon_off, TestStubDrawable())
                    addOverride(R.drawable.qs_light_dark_theme_icon_on, TestStubDrawable())
                }
                .resources,
            context.theme
        )
    }

    private fun createUiNightModeTileState(
@@ -60,7 +69,7 @@ class UiModeNightTileMapperTest : SysuiTestCase() {
        expandedAccessibilityClass: KClass<out View>? = Switch::class,
    ): QSTileState {
        return QSTileState(
            { Icon.Resource(iconRes, null) },
            { Icon.Loaded(context.getDrawable(iconRes)!!, null) },
            label,
            activationState,
            secondaryLabel,
Loading