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

Commit cd18c514 authored by Wes Okuhara's avatar Wes Okuhara
Browse files

[SettingsLib] Dynamically update StatusBannerPreference icon tint

Prior to this change, the icon tint was only set during initialization
based on the icon or icon level. This allows the icon tint to be
dynamically updated based on a respective icon level change. Setting
the icon level whenthere is no icon defined is a no-op.

Bug: 400999418
Test: Manual
Flag: EXEMPT bugfix
Change-Id: I37d4cf890ecf9152013ac5c53cb60bc55fb26643
parent 014ffc85
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ class StatusBannerPreference @JvmOverloads constructor(
    var iconLevel: BannerStatus = BannerStatus.GENERIC
        set(value) {
            field = value
            updateIconTint(value)
            notifyChanged()
        }
    var buttonLevel: BannerStatus = BannerStatus.GENERIC
@@ -81,7 +82,7 @@ class StatusBannerPreference @JvmOverloads constructor(
            if (icon == null) {
                icon = getIconDrawable(iconLevel)
            } else {
                icon!!.setTintList(ColorStateList.valueOf(getBackgroundColor(iconLevel)))
                updateIconTint(iconLevel)
            }
            buttonLevel = getInteger(R.styleable.StatusBanner_buttonLevel, 0).toBannerStatus()
            buttonText = getString(R.styleable.StatusBanner_buttonText) ?: ""
@@ -252,4 +253,12 @@ class StatusBannerPreference @JvmOverloads constructor(
            )
        }
    }

    /**
     * Sets the icon's tint color based on the icon level. If an icon is not defined, this is a
     * no-op.
     */
    private fun updateIconTint(iconLevel: BannerStatus) {
        icon?.setTintList(ColorStateList.valueOf(getBackgroundColor(iconLevel)))
    }
}