Skip to content

Commit

Permalink
[NOJIRA] Fix Default badge type to be Normal in View (#1871)
Browse files Browse the repository at this point in the history
* Fix default badge type to be normal

* Fix def value in type variable

* Updated snapshots

* Fix icon implementation

* Updated snapshots

* Trigger CI

* Trigger CI

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
jaanainkinen and github-actions[bot] authored Feb 7, 2024
1 parent a760fad commit 7bae831
Show file tree
Hide file tree
Showing 31 changed files with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions Backpack/src/main/java/net/skyscanner/backpack/badge/BpkBadge.kt
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ open class BpkBadge @JvmOverloads constructor(
* @property type
* Type of badge. Default Type.Success
*/
var type: Type = Type.Success
var type: Type = Type.Normal
set(value) {
field = value
if (initialized) setup()
Expand All @@ -144,10 +144,6 @@ open class BpkBadge @JvmOverloads constructor(
var icon: Drawable? = null
set(value) {
field = value
?.mutate()
?.apply {
setBounds(0, 0, iconSize, iconSize)
}
updateIcon()
}

Expand All @@ -160,18 +156,13 @@ open class BpkBadge @JvmOverloads constructor(
0,
)

type = Type.fromId(a.getInt(R.styleable.BpkBadge_badgeType, 1))
type = Type.fromId(a.getInt(R.styleable.BpkBadge_badgeType, 8))
message = a.getString(R.styleable.BpkBadge_message)
a.getResourceId(R.styleable.BpkBadge_badgeIcon, 0).let { iconID ->
icon = if (iconID != 0) {
AppCompatResources.getDrawable(context, iconID)
} else {
when (type) {
Type.Success -> AppCompatResources.getDrawable(context, R.drawable.bpk_tick_circle)
Type.Warning -> AppCompatResources.getDrawable(context, R.drawable.bpk_information_circle)
Type.Destructive -> AppCompatResources.getDrawable(context, R.drawable.bpk_exclamation)
else -> null
}
null
}
}

Expand Down Expand Up @@ -208,9 +199,23 @@ open class BpkBadge @JvmOverloads constructor(
}

private fun updateIcon() {
setCompoundDrawablesRelative(icon, null, null, null)
setPadding(iconPadding, 0, iconPadding, 0)
icon?.setTint(context.getColor(type.iconColor))
val currentIcon = if (icon == null) {
when (type) {
Type.Success -> AppCompatResources.getDrawable(context, R.drawable.bpk_tick_circle)
Type.Warning -> AppCompatResources.getDrawable(context, R.drawable.bpk_information_circle)
Type.Destructive -> AppCompatResources.getDrawable(context, R.drawable.bpk_exclamation)
else -> null
}
} else {
icon
}
currentIcon
?.mutate()
?.apply {
setBounds(0, 0, iconSize, iconSize)
setTint(context.getColor(type.iconColor))
setCompoundDrawablesRelative(this, null, null, null)
}
}

internal fun setBackground(
Expand Down
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.

0 comments on commit 7bae831

Please sign in to comment.