Skip to content

Commit

Permalink
ANDROID-14475 Subtitle color changed in lists (#356)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmartinbTEF authored May 28, 2024
1 parent b1dcc54 commit 432fb54
Show file tree
Hide file tree
Showing 175 changed files with 227 additions and 3 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified library/screenshots/check_ListRowItem_with_32x32_asset.png
Binary file modified library/screenshots/check_ListRowItem_with_64x64_asset.png
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ private fun ListRowItemImp(
Text(
text = it,
style = MisticaTheme.typography.preset2,
color = textColorSecondary,
color = textColorPrimary,
modifier = Modifier
.testTag(ListRowItemTestTags.LIST_ROW_ITEM_SUBTITLE)
.padding(vertical = 2.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import androidx.annotation.DrawableRes
import androidx.annotation.IntDef
import androidx.annotation.LayoutRes
import androidx.appcompat.content.res.AppCompatResources
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.constraintlayout.widget.ConstraintSet
import androidx.core.view.ViewCompat
Expand Down Expand Up @@ -448,8 +450,8 @@ class ListRowView @JvmOverloads constructor(

fun setDefaultSubtitleTextColor(@BackgroundType type: Int = cachedDefaultBackgroundType) {
val themeColor = when (type) {
BackgroundType.TYPE_BOXED_INVERSE -> R.attr.colorTextSecondaryInverse
else -> R.attr.colorTextSecondary
BackgroundType.TYPE_BOXED_INVERSE -> R.attr.colorTextPrimaryInverse
else -> R.attr.colorTextPrimary
}
setSubtitleTextColor(context.getThemeColor(themeColor))
}
Expand Down Expand Up @@ -577,6 +579,7 @@ class ListRowView @JvmOverloads constructor(
private fun showNumericBadge(count: Int, withBadgeDescription: String?) {
Badge.removeBadge(badgeAnchor)
badgeAnchorContainer.visibility = View.VISIBLE
badgeAnchorContainer.setBackgroundColor(Color.Transparent.toArgb())
Badge.showNumericBadgeIn(badgeAnchor, badgeAnchorContainer, count, withBadgeDescription)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private const val LIST_ROW_ITEM_ASSET_TAG = "listRowItemAssetTag"

@RunWith(RobolectricTestRunner::class)
internal class ListRowItemKtTest : ScreenshotsTest() {

@get:Rule
val composeTestRule = createComposeRule()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package com.telefonica.mistica.compose.list

import androidx.compose.material.Surface
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onRoot
import com.telefonica.mistica.compose.theme.MisticaTheme
import com.telefonica.mistica.compose.theme.brand.Brand
import com.telefonica.mistica.list.model.ImageDimensions
import com.telefonica.mistica.testutils.ScreenshotsTest
import com.telefonica.mistica.testutils.TestUtils
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.robolectric.ParameterizedRobolectricTestRunner.Parameters

@RunWith(ParameterizedRobolectricTestRunner::class)
class ListRowItemTest(
private val brand: Brand,
private val smallAsset: Boolean,
private val backgroundType: BackgroundType,
private val darkTheme: Boolean,
) : ScreenshotsTest() {
@get:Rule
val composeTestRule = createComposeRule()

@Test
fun `ListRowItem compose screenshot`() {
composeTestRule.setContent {
MisticaTheme(brand = brand, darkTheme = darkTheme) {
Surface(
color = MisticaTheme.colors.background
) {
val dimensions = if (smallAsset) {
ImageDimensions(width = 32, height = 32)
} else {
ImageDimensions(width = 64, height = 64)
}
ListRowItem(
title = "Title",
subtitle = "Subtitle",
description = "Description",
backgroundType = backgroundType,
isBadgeVisible = true,
badge = "1",
onClick = {},
listRowIcon = ListRowIcon.ImageAsset(
painterResource(id = android.R.drawable.ic_lock_power_off),
dimensions = ImageDimensions(width = dimensions.width, height = dimensions.height),
),
)
}
}
}

val screenshotSuffix = StringBuilder()
screenshotSuffix.append("${backgroundType.name}_")

if (smallAsset) {
screenshotSuffix.append("32x32")
} else {
screenshotSuffix.append("64x64")
}

compareScreenshot(
node = composeTestRule.onRoot(),
component = "ListRowItem",
style = null,
brand = brand,
darkTheme = darkTheme,
extra = screenshotSuffix.toString()
)
}

companion object {
@Suppress("UNUSED")
@JvmStatic
@Parameters
fun brands(): List<Array<Any?>> {
val brands = TestUtils.getAllBrands()
val smallAsset = arrayOf(false, true)
val backgroundType = arrayOf(BackgroundType.TYPE_NORMAL, BackgroundType.TYPE_BOXED, BackgroundType.TYPE_BOXED_INVERSE)
val darkTheme = arrayOf(false, true)

return brands.flatMap { brand ->
smallAsset.flatMap { isSmall ->
backgroundType.flatMap { backgroundType ->
darkTheme.map { darkTheme ->
arrayOf(brand, isSmall, backgroundType, darkTheme)
}

}
}
}
}
}
}
122 changes: 122 additions & 0 deletions library/src/test/java/com/telefonica/mistica/list/ListRowItemTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
package com.telefonica.mistica.list

import android.content.Intent
import android.widget.FrameLayout
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso
import androidx.test.espresso.matcher.ViewMatchers
import androidx.test.ext.junit.rules.activityScenarioRule
import com.telefonica.mistica.DummyActivity
import com.telefonica.mistica.R
import com.telefonica.mistica.compose.theme.brand.Brand
import com.telefonica.mistica.compose.theme.brand.MovistarBrand
import com.telefonica.mistica.list.ListRowView.BackgroundType.Companion.TYPE_BOXED
import com.telefonica.mistica.list.ListRowView.BackgroundType.Companion.TYPE_BOXED_INVERSE
import com.telefonica.mistica.list.ListRowView.BackgroundType.Companion.TYPE_NORMAL
import com.telefonica.mistica.list.ListRowView.Companion.TYPE_SMALL_ICON
import com.telefonica.mistica.list.model.ImageDimensions
import com.telefonica.mistica.testutils.ScreenshotsTest
import com.telefonica.mistica.testutils.TestUtils
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
import org.robolectric.annotation.Config

@RunWith(ParameterizedRobolectricTestRunner::class)
class ListRowItemTest(
private val brand: Brand,
private val smallAsset: Boolean,
@ListRowView.BackgroundType private val backgroundType: Int,
) : ScreenshotsTest() {
private val intent = Intent(ApplicationProvider.getApplicationContext(), DummyActivity::class.java).apply {
this.putExtra(DummyActivity.EXTRA_THEME, TestUtils.getBaseThemeForBrand(brand))
}

@get:Rule
val rule = activityScenarioRule<DummyActivity>(intent)

@Test
fun `ListRowItem XML screenshot light`() {
`listRowItem XML screenshot`(darkTheme = false)
}

@Config(qualifiers = "+night")
@Test
fun `ListRowItem XML screenshot dark`() {
`listRowItem XML screenshot`(darkTheme = true)
}

private fun `listRowItem XML screenshot`(darkTheme: Boolean) {
rule.scenario.onActivity { activity ->
val dimensions = if (smallAsset) {
ImageDimensions(width = 32, height = 32)
} else {
ImageDimensions(width = 64, height = 64)
}
val wrapper: FrameLayout = activity.findViewById(R.id.dummy_activity_wrapper)
val listRowView = ListRowView(activity).apply {
setAssetType(
if(smallAsset) TYPE_SMALL_ICON else ListRowView.TYPE_IMAGE_1_1,
dimensions = ImageDimensions(width = dimensions.width, height = dimensions.height),
)
setTitle("Title")
setSubtitle("Subtitle")
setDescription("Description")
setBadge(show = true)
setNumericBadge(1)
setAssetDrawable(activity.getDrawable(android.R.drawable.ic_lock_power_off))
setBackgroundType(backgroundType)

}

wrapper.removeAllViews()
wrapper.addView(listRowView)

val screenshotSuffix = StringBuilder()
val backgroundTypeName = when (backgroundType) {
TYPE_NORMAL -> "TYPE_NORMAL"
TYPE_BOXED -> "TYPE_BOXED"
TYPE_BOXED_INVERSE -> "TYPE_BOXED_INVERSE"
else -> "TYPE_NORMAL"

}
screenshotSuffix.append("${backgroundTypeName}_")

if (smallAsset) {
screenshotSuffix.append("32x32")
} else {
screenshotSuffix.append("64x64")
}

compareScreenshot(
node = Espresso.onView(ViewMatchers.withId(R.id.dummy_activity_wrapper)),
component = "ListRowItemXML",
style = null,
brand = brand,
darkTheme = darkTheme,
extra = screenshotSuffix.toString()
)
}
}


companion object {
@Suppress("UNUSED")
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters
fun brands(): List<Array<Any?>> {
val brands = TestUtils.getAllBrands()
val smallAsset = arrayOf(false, true)
val backgroundType = arrayOf(TYPE_NORMAL, TYPE_BOXED, TYPE_BOXED_INVERSE)

return brands.flatMap { brand ->
smallAsset.flatMap { isSmall ->
backgroundType.map { backgroundType ->
arrayOf(brand, isSmall, backgroundType)
}
}
}
}
}
}

0 comments on commit 432fb54

Please sign in to comment.