Skip to content

Commit

Permalink
Simplify styledColor
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisCAD committed Aug 6, 2021
1 parent 2fc30fb commit 0805b6e
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,9 @@ inline fun appColorSL(@ColorRes colorRes: Int) = appCtx.colorSL(colorRes)

@ColorInt
fun Context.styledColor(@AttrRes attr: Int): Int = withResolvedThemeAttribute(attr) {
when (type) {
in TypedValue.TYPE_FIRST_COLOR_INT..TypedValue.TYPE_LAST_COLOR_INT -> data
TypedValue.TYPE_STRING -> {
if (string.startsWith("res/color/")) color(resourceId)
else illegalArg(unexpectedThemeAttributeTypeErrorMessage(expectedKind = "color"))
}
when {
type in TypedValue.TYPE_FIRST_COLOR_INT..TypedValue.TYPE_LAST_COLOR_INT -> data
type == TypedValue.TYPE_STRING && string.startsWith("res/color/") -> color(resourceId)
else -> illegalArg(unexpectedThemeAttributeTypeErrorMessage(expectedKind = "color"))
}
}
Expand Down

0 comments on commit 0805b6e

Please sign in to comment.