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

Commit 2d1cd0d5 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB][Chips] Don't add text composable if text is empty.

The Text composable has end padding which will make the icon look
off-center if the text is empty.

Also improves the logging of the chip models.

Fixes: 407526550
Test: Trigger RON chip with empty shortCriticalText -> verify icon isn't
off-center
Flag: android.app.ui_rich_ongoing

Change-Id: Ie5a03d7b264e3f7c7dff2f861b1b6fb0dc1ac0c3
parent 8422e265
Loading
Loading
Loading
Loading
+17 −15
Original line number Diff line number Diff line
@@ -119,6 +119,7 @@ fun ChipContent(

        is OngoingActivityChipModel.Content.Text -> {
            val text = viewModel.text
            if (text.isNotBlank()) {
                Text(
                    text = text,
                    color = textColor,
@@ -135,6 +136,7 @@ fun ChipContent(
                        ),
                )
            }
        }

        is OngoingActivityChipModel.Content.ShortTimeDelta -> {
            val timeRemainingState =
+18 −5
Original line number Diff line number Diff line
@@ -102,13 +102,18 @@ sealed class OngoingActivityChipModel {
        }

        override val logName: String
            get() = "Active.${content::class.simpleName}"
            get() = "Active.${content.logName}"
    }

    /** The content shown in the chip next to the icon. */
    sealed class Content {
        /** Condensed name representing the model, used for logs. */
        abstract val logName: String

        /** This chip shows only an icon and nothing else. */
        data object IconOnly : Content()
        data object IconOnly : Content() {
            override val logName = "IconOnly"
        }

        /** The chip shows a timer, counting up from [startTimeMs]. */
        data class Timer(
@@ -136,7 +141,9 @@ sealed class OngoingActivityChipModel {
             * future. Otherwise, [startTimeMs] should be in the past.
             */
            val isEventInFuture: Boolean = false,
        ) : Content()
        ) : Content() {
            override val logName = "Timer(time=$startTimeMs isFuture=$isEventInFuture)"
        }

        /**
         * The chip shows the time delta between now and [time] in a short format, e.g. "15min" or
@@ -163,6 +170,8 @@ sealed class OngoingActivityChipModel {
            init {
                /* check if */ PromotedNotificationUi.isUnexpectedlyInLegacyMode()
            }

            override val logName = "ShortTimeDelta(time=$time)"
        }

        /**
@@ -172,10 +181,14 @@ sealed class OngoingActivityChipModel {
        data class Countdown(
            /** The number of seconds until an event is started. */
            val secondsUntilStarted: Long
        ) : Content()
        ) : Content() {
            override val logName = "Countdown($secondsUntilStarted)"
        }

        /** This chip shows the specified [text] in the chip. */
        data class Text(val text: String) : Content()
        data class Text(val text: String) : Content() {
            override val logName = "Text($text)"
        }
    }

    /** Represents an icon to show on the chip. */