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

Commit 8f3427ed authored by András Kurucz's avatar András Kurucz Committed by Android (Google) Code Review
Browse files

Merge "Fix updating icons with BigPictureIconManager after reinflating the layout" into main

parents 6462a54f b2b15923
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