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

Commit b57f65c4 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov Committed by Android (Google) Code Review
Browse files

Merge "[SB][Chips] Don't throw if we can't fetch a StatusBarIconView." into main

parents f8ea6dcc 1182a91d
Loading
Loading
Loading
Loading
+32 −4
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package com.android.systemui.statusbar.chips.ui.compose

import android.annotation.IdRes
import android.content.res.ColorStateList
import android.util.Log
import android.view.ViewGroup
import android.widget.FrameLayout
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
@@ -234,10 +237,35 @@ private fun StatusBarIcon(
    AndroidView(
        modifier = modifier,
        factory = { _ ->
            iconFactory.invoke()?.apply {
            // Use a wrapper frame layout so that we still return a view even if the icon is null
            val wrapperFrameLayout = FrameLayout(context)

            val icon = iconFactory.invoke()
            if (icon == null) {
                Log.e(TAG, "Missing StatusBarIconView for $notificationKey")
            } else {
                icon.apply {
                    id = CUSTOM_ICON_VIEW_ID
                    layoutParams = ViewGroup.LayoutParams(iconSizePx, iconSizePx)
            } ?: throw IllegalStateException("Missing StatusBarIconView for $notificationKey")
                }
                // If needed, remove the icon from its old parent (views can only be attached
                // to 1 parent at a time)
                (icon.parent as? ViewGroup)?.apply {
                    this.removeView(icon)
                    this.removeTransientView(icon)
                }
                wrapperFrameLayout.addView(icon)
            }

            wrapperFrameLayout
        },
        update = { frameLayout ->
            frameLayout.findViewById<StatusBarIconView>(CUSTOM_ICON_VIEW_ID)?.apply {
                this.imageTintList = colorTintList
            }
        },
        update = { iconView -> iconView.imageTintList = colorTintList },
    )
}

private const val TAG = "OngoingActivityChip"
@IdRes private val CUSTOM_ICON_VIEW_ID = R.id.ongoing_activity_chip_custom_icon