Skip to content

Commit

Permalink
ANDROID-14620 Reset text color labels (#353)
Browse files Browse the repository at this point in the history
* ANDROID-14620 Cache backgroundType for reset row texts if needed during a recycling loop.

* ANDROID-14620 Minor renaming
  • Loading branch information
dagonco authored May 8, 2024
1 parent 69ba5f5 commit 1872455
Showing 1 changed file with 42 additions and 23 deletions.
65 changes: 42 additions & 23 deletions library/src/main/java/com/telefonica/mistica/list/ListRowView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class ListRowView @JvmOverloads constructor(
private var assetType: Int = TYPE_SMALL_ICON
private var assetHeight: Float = UNDEFINED
private var assetWidth: Float = UNDEFINED
private var cachedDefaultBackgroundType: Int = BackgroundType.TYPE_NORMAL

init {
LayoutInflater.from(context).inflate(R.layout.list_row_item, this, true)
Expand Down Expand Up @@ -215,6 +216,7 @@ class ListRowView @JvmOverloads constructor(
} else {
BackgroundType.TYPE_NORMAL
}
cachedDefaultBackgroundType = backgroundTypeDefaultValue
setBackgroundType(
styledAttrs.getInt(
R.styleable.ListRowView_listRowBackgroundType,
Expand Down Expand Up @@ -283,7 +285,9 @@ class ListRowView @JvmOverloads constructor(
TYPE_IMAGE_1_1,
TYPE_IMAGE_7_10,
TYPE_IMAGE_16_9,
TYPE_IMAGE_ROUNDED -> assetRoundedImageView
TYPE_IMAGE_ROUNDED,
-> assetRoundedImageView

else -> assetImageView
}.also { imageView ->
imageView.loadUrl(url) {
Expand Down Expand Up @@ -311,7 +315,7 @@ class ListRowView @JvmOverloads constructor(
TYPE_IMAGE_1_1,
TYPE_IMAGE_7_10,
TYPE_IMAGE_16_9,
TYPE_IMAGE_ROUNDED
TYPE_IMAGE_ROUNDED,
-> assetRoundedImageView.setImageDrawable(drawable)

else -> assetImageView.setImageDrawable(drawable)
Expand Down Expand Up @@ -414,38 +418,53 @@ class ListRowView @JvmOverloads constructor(
}

fun setBackgroundType(@BackgroundType type: Int) {
cachedDefaultBackgroundType = type
@DrawableRes val backgroundDrawable: Int = when (type) {
BackgroundType.TYPE_BOXED -> R.drawable.boxed_list_row_background
BackgroundType.TYPE_BOXED_INVERSE -> R.drawable.boxed_inverse_list_row_background
BackgroundType.TYPE_NORMAL -> R.drawable.list_row_background
else -> R.drawable.list_row_background
}
background = AppCompatResources.getDrawable(context, backgroundDrawable)
configureTextViewsColor(type)
setDefaultTitleTextColor(type)
setDefaultSubtitleTextColor(type)
setDefaultDescriptionTextColor(type)
}

private fun configureTextViewsColor(@BackgroundType type: Int) {
val colorPrimary =
context.getThemeColor(
if (type == BackgroundType.TYPE_BOXED_INVERSE) {
R.attr.colorTextPrimaryInverse
} else {
R.attr.colorTextPrimary
}
)
fun setDefaultTitleTextColor(@BackgroundType type: Int = cachedDefaultBackgroundType) {
val themeColor = when (type) {
BackgroundType.TYPE_BOXED_INVERSE -> R.attr.colorTextPrimaryInverse
else -> R.attr.colorTextPrimary
}
setTitleTextColor(context.getThemeColor(themeColor))
}

val colorSecondary =
context.getThemeColor(
if (type == BackgroundType.TYPE_BOXED_INVERSE) {
R.attr.colorTextSecondaryInverse
} else {
R.attr.colorTextSecondary
}
)
fun setDefaultSubtitleTextColor(@BackgroundType type: Int = cachedDefaultBackgroundType) {
val themeColor = when (type) {
BackgroundType.TYPE_BOXED_INVERSE -> R.attr.colorTextSecondaryInverse
else -> R.attr.colorTextSecondary
}
setSubtitleTextColor(context.getThemeColor(themeColor))
}

fun setDefaultDescriptionTextColor(@BackgroundType type: Int = cachedDefaultBackgroundType) {
val themeColor = when (type) {
BackgroundType.TYPE_BOXED_INVERSE -> R.attr.colorTextSecondaryInverse
else -> R.attr.colorTextSecondary
}
setDescriptionTextColor(context.getThemeColor(themeColor))
}

fun setTitleTextColor(textColorOverride: Int) {
titleTextView.setTextColor(textColorOverride)
}

fun setSubtitleTextColor(textColorOverride: Int) {
subtitleTextView.setTextColor(textColorOverride)
}

titleTextView.setTextColor(colorPrimary)
subtitleTextView.setTextColor(colorSecondary)
descriptionTextView.setTextColor(colorSecondary)
fun setDescriptionTextColor(textColorOverride: Int) {
descriptionTextView.setTextColor(textColorOverride)
}

fun setHeadlineVisible(visible: Boolean) {
Expand Down

0 comments on commit 1872455

Please sign in to comment.