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

Commit 1063ac01 authored by András Kurucz's avatar András Kurucz
Browse files

Make BigPictureIconManager reload the image on each icon update

This way we reload the URI every time a BigPicture Notification is
reinflated, which means that when the system theme changes the app is
given an opportunity to provide a version of the image for the current
system theme. This matches the behaviour before the lazy loading.

Bug: 283082473
Test: atest BigPictureIconManager
Change-Id: I54cf91bd42f0eb760774caf88005150f0a4cec3d
parent 1ef586cb
Loading
Loading
Loading
Loading
+0 −15
Original line number Diff line number Diff line
@@ -120,12 +120,6 @@ constructor(
            return Runnable {}
        }

        if (displayedState.iconSameAs(icon)) {
            // We're already handling this icon, nothing to do here.
            log("skipping updateIcon for consumer:$drawableConsumer with icon:$icon")
            return Runnable {}
        }

        this.drawableConsumer = drawableConsumer
        this.displayedState = Empty(icon)
        this.lastLoadingJob?.cancel()
@@ -256,15 +250,6 @@ constructor(
        data class PlaceHolder(override val icon: Icon, val drawableSize: Size) :
            DrawableState(icon)
        data class FullImage(override val icon: Icon, val drawableSize: Size) : DrawableState(icon)

        fun iconSameAs(other: Icon?): Boolean {
            val displayedIcon = icon
            return when {
                displayedIcon == null && other == null -> true
                displayedIcon != null && other != null -> displayedIcon.sameAs(other)
                else -> false
            }
        }
    }
}

+45 −1
Original line number Diff line number Diff line
@@ -111,6 +111,16 @@ class BigPictureIconManagerTest : SysuiTestCase() {
            assertSize(drawableCaptor.value)
        }

    @Test
    fun onIconUpdated_withNull_drawableIsNull() =
        testScope.runTest {
            // WHEN update with null
            iconManager.updateIcon(mockConsumer, null).run()

            // THEN consumer is updated with null
            verify(mockConsumer).setImageDrawable(null)
        }

    @Test
    fun onIconUpdated_invalidIcon_drawableIsNull() =
        testScope.runTest {
@@ -152,6 +162,24 @@ class BigPictureIconManagerTest : SysuiTestCase() {
            assertSize(drawableCaptor.value)
        }

    @Test
    fun onIconUpdated_iconAlreadySetForTheSameIcon_loadsIconAgain() =
        testScope.runTest {
            // GIVEN an icon is set
            iconManager.updateIcon(mockConsumer, supportedIcon).run()
            // AND the view is shown
            iconManager.onViewShown(true)
            runCurrent()
            reset(mockConsumer)
            // WHEN the icon is set again
            iconManager.updateIcon(mockConsumer, supportedIcon).run()

            // THEN consumer is updated with the new image
            verify(mockConsumer).setImageDrawable(drawableCaptor.capture())
            assertIsFullImage(drawableCaptor.value)
            assertSize(drawableCaptor.value)
        }

    @Test
    fun onIconUpdated_iconAlreadySetForUnsupportedIcon_loadsNewIcon() =
        testScope.runTest {
@@ -159,6 +187,7 @@ class BigPictureIconManagerTest : SysuiTestCase() {
            iconManager.updateIcon(mockConsumer, unsupportedIcon).run()
            // AND the view is shown
            iconManager.onViewShown(true)
            runCurrent()
            reset(mockConsumer)

            // WHEN a new icon is set
@@ -282,6 +311,21 @@ class BigPictureIconManagerTest : SysuiTestCase() {
            verifyZeroInteractions(mockConsumer)
        }

    @Test
    fun onViewShown_nullSetForIcon_nothingHappens() =
        testScope.runTest {
            // GIVEN null is set for the icon
            iconManager.updateIcon(mockConsumer, null).run()
            reset(mockConsumer)

            // WHEN the view is shown
            iconManager.onViewShown(true)
            runCurrent()

            // THEN nothing happens
            verifyZeroInteractions(mockConsumer)
        }

    @Test
    fun onViewHidden_unsupportedIconLoadedAndViewIsShown_nothingHappens() =
        testScope.runTest {