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

Commit 76b44e08 authored by Beth Thibodeau's avatar Beth Thibodeau
Browse files

Update seekbar position if needed while paused

Fixes: 382386127
Flag: EXEMPT bugfix
Test: manual; atest SeekBarViewModelTest
Change-Id: I38e7f990884b33054b1da278f95527ec8be40ff0
parent 645b36ab
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -93,7 +93,7 @@ constructor(
            scrubbing = false,
            elapsedTime = null,
            duration = 0,
            listening = false
            listening = false,
        )
        set(value) {
            val enabledChanged = value.enabled != field.enabled
@@ -135,7 +135,6 @@ constructor(

            override fun onMetadataChanged(metadata: MediaMetadata?) {
                if (!Flags.mediaControlsPostsOptimization()) return

                val (enabled, duration) = getEnabledStateAndDuration(metadata)
                if (_data.duration != duration) {
                    _data = _data.copy(enabled = enabled, duration = duration)
@@ -323,7 +322,7 @@ constructor(
                    bgExecutor.executeRepeatedly(
                        this::checkPlaybackPosition,
                        0L,
                        POSITION_UPDATE_INTERVAL_MILLIS
                        POSITION_UPDATE_INTERVAL_MILLIS,
                    )
                cancel = Runnable {
                    cancelPolling.run()
@@ -331,6 +330,7 @@ constructor(
                }
            }
        } else {
            checkPlaybackPosition()
            cancel?.run()
            cancel = null
        }
@@ -542,7 +542,7 @@ constructor(
            eventStart: MotionEvent?,
            event: MotionEvent,
            distanceX: Float,
            distanceY: Float
            distanceY: Float,
        ): Boolean {
            return shouldGoToSeekBar
        }
@@ -556,7 +556,7 @@ constructor(
            eventStart: MotionEvent?,
            event: MotionEvent,
            velocityX: Float,
            velocityY: Float
            velocityY: Float,
        ): Boolean {
            if (Math.abs(velocityX) > flingVelocity || Math.abs(velocityY) > flingVelocity) {
                viewModel.onSeekFalse()
+30 −0
Original line number Diff line number Diff line
@@ -64,9 +64,11 @@ public class SeekBarViewModelTest : SysuiTestCase() {
            override fun executeOnDiskIO(runnable: Runnable) {
                runnable.run()
            }

            override fun postToMainThread(runnable: Runnable) {
                runnable.run()
            }

            override fun isMainThread(): Boolean {
                return true
            }
@@ -805,4 +807,32 @@ public class SeekBarViewModelTest : SysuiTestCase() {
        fakeExecutor.runAllReady()
        verify(mockController).unregisterCallback(any())
    }

    @Test
    fun positionUpdatedWhileStopped() {
        // When playback is stopped at one position
        val firstPosition = 200L
        val state =
            PlaybackState.Builder().run {
                setState(PlaybackState.STATE_STOPPED, firstPosition, 1f)
                build()
            }
        whenever(mockController.playbackState).thenReturn(state)
        val captor = ArgumentCaptor.forClass(MediaController.Callback::class.java)
        viewModel.updateController(mockController)
        verify(mockController).registerCallback(captor.capture())
        assertThat(viewModel.progress.value!!.elapsedTime).isEqualTo(firstPosition.toInt())

        // And the state is updated with a new position
        val secondPosition = 42L
        val secondState =
            PlaybackState.Builder().run {
                setState(PlaybackState.STATE_STOPPED, secondPosition, 1f)
                build()
            }
        captor.value.onPlaybackStateChanged(secondState)

        // THEN then elapsed time should be updated
        assertThat(viewModel.progress.value!!.elapsedTime).isEqualTo(secondPosition.toInt())
    }
}