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

Commit b2b15923 authored by András Kurucz's avatar András Kurucz
Browse files

Fix updating icons with BigPictureIconManager after reinflating the layout

Whenever a new layout is inflated for a BigPictureStyle Notification,
the BigPictureIconManager gets updated with a new DrawableConsumer. The
previous code wasn't following up on those updates.

Fixes: 306369469
Test: atest BigPictureIconManagerTest
Test: observe BigPictureStyle Notifications after theme changes
and updates
Flag: statusbar flag bigpicture_notification_lazy_loading

Change-Id: If7de5ab2a88e422ffbb6fb41fb33462a351b1a98
parent 8e10e17e
Loading
Loading
Loading
Loading
+0 −5
Original line number Diff line number Diff line
@@ -117,11 +117,6 @@ constructor(

    @WorkerThread
    override fun updateIcon(drawableConsumer: NotificationDrawableConsumer, icon: Icon?): Runnable {
        if (this.drawableConsumer != null && this.drawableConsumer != drawableConsumer) {
            Log.wtf(TAG, "A consumer is already set for this iconManager.")
            return Runnable {}
        }

        this.drawableConsumer = drawableConsumer
        this.lastLoadingJob?.cancel()

+31 −5
Original line number Diff line number Diff line
@@ -143,18 +143,44 @@ class BigPictureIconManagerTest : SysuiTestCase() {
        }

    @Test
    fun onIconUpdated_consumerAlreadySet_nothingHappens() =
    fun onIconUpdated_consumerAlreadySet_newConsumerIsUpdatedWithPlaceholder() =
        testScope.runTest {
            // GIVEN a consumer is set
            val otherConsumer: NotificationDrawableConsumer = mock()
            iconManager.updateIcon(mockConsumer, supportedIcon).run()
            clearInvocations(mockConsumer)

            // WHEN a new consumer is set
            iconManager.updateIcon(otherConsumer, unsupportedIcon).run()
            val newConsumer: NotificationDrawableConsumer = mock()
            iconManager.updateIcon(newConsumer, supportedIcon).run()

            // THEN nothing happens
            verifyZeroInteractions(mockConsumer, otherConsumer)
            // THEN the new consumer is updated
            verify(newConsumer).setImageDrawable(drawableCaptor.capture())
            assertIsPlaceHolder(drawableCaptor.value)
            assertSize(drawableCaptor.value)
            // AND nothing happens on the old consumer
            verifyZeroInteractions(mockConsumer)
        }

    @Test
    fun onIconUpdated_consumerAlreadySet_newConsumerIsUpdatedWithFullImage() =
        testScope.runTest {
            // GIVEN a consumer is set
            iconManager.updateIcon(mockConsumer, supportedIcon).run()
            // AND an icon is loaded
            iconManager.onViewShown(true)
            runCurrent()
            clearInvocations(mockConsumer)

            // WHEN a new consumer is set
            val newConsumer: NotificationDrawableConsumer = mock()
            iconManager.updateIcon(newConsumer, supportedIcon).run()

            // THEN the new consumer is updated
            verify(newConsumer).setImageDrawable(drawableCaptor.capture())
            assertIsFullImage(drawableCaptor.value)
            assertSize(drawableCaptor.value)
            // AND nothing happens on the old consumer
            verifyZeroInteractions(mockConsumer)
        }

    @Test