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

Commit f4c3467a authored by Austin Tankiang's avatar Austin Tankiang
Browse files

Change how the toolbar spinner total progress is calculated

Before it used a byte count, but byte counts aren't available for queued
items. So just use an average of the percents instead.

Bug: 400352300
Test: atest -c 'DocumentsUIGoogleTests:com.android.documentsui.JobPanelControllerTest'
Flag: com.android.documentsui.flags.visual_signals_ro
Change-Id: I0625e04ad17eef7167a33388318b92336a2e3f87
parent 5616feab
Loading
Loading
Loading
Loading
+9 −16
Original line number Diff line number Diff line
@@ -339,9 +339,8 @@ class JobPanelController(private val activityContext: Context) : BroadcastReceiv
    }

    private fun updateProgress(progresses: List<JobProgress>) {
        var requiredBytes = 0L
        var currentBytes = 0L
        var allFinished = true
        var currentPercent = 0f
        var allIndeterminate = true

        for (jobProgress in progresses) {
            Log.d(TAG, "Received $jobProgress")
@@ -350,25 +349,19 @@ class JobPanelController(private val activityContext: Context) : BroadcastReceiv
            }
        }
        for ((jobProgress, _) in currentJobs.values) {
            if (jobProgress.state != Job.STATE_COMPLETED) {
                allFinished = false
            }
            if (jobProgress.requiredBytes != -1L && jobProgress.currentBytes != -1L) {
                requiredBytes += jobProgress.requiredBytes
                currentBytes += jobProgress.currentBytes
            if (!jobProgress.isIndeterminate) {
                allIndeterminate = false
                currentPercent += jobProgress.toPercent()
            }
        }

        if (currentJobs.isEmpty()) {
            menuIconState = MenuIconState.INVISIBLE
        } else if (requiredBytes != 0L) {
            menuIconState = MenuIconState.VISIBLE
            totalProgress = (MAX_PROGRESS * currentBytes / requiredBytes).toInt()
        } else if (allFinished) {
            menuIconState = MenuIconState.VISIBLE
            totalProgress = MAX_PROGRESS
        } else {
        } else if (allIndeterminate) {
            menuIconState = MenuIconState.INDETERMINATE
        } else {
            menuIconState = MenuIconState.VISIBLE
            totalProgress = (currentPercent / currentJobs.size).toInt()
        }
        updateMenuItem(animate = true)
        progressListAdapter?.submitList(ArrayList(currentJobs.values))
+2 −2
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ data class JobProgress @JvmOverloads constructor(
                (currentBytes == -1L || requiredBytes == -1L || requiredBytes == 0L)

    fun toPercent(): Float = when (state) {
        in Job.STATE_CREATED..Job.STATE_STARTED -> 0f
        Job.STATE_COMPLETED -> 100f
        Job.STATE_CREATED, Job.STATE_STARTED -> 0f
        Job.STATE_COMPLETED, Job.STATE_CANCELED -> 100f
        else -> 100f * currentBytes / requiredBytes
    }

+37 −3
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ class JobPanelControllerTest {
            msg = "Job started",
            hasFailures = false,
            currentBytes = 0,
            requiredBytes = 40,
            requiredBytes = 50,
            msRemaining = -1
        )
        sendProgress(arrayListOf(progress1.toJobProgress(), progress2.toJobProgress()))
@@ -161,7 +161,7 @@ class JobPanelControllerTest {

        assertTrue(menuItem.isVisible())
        assertTrue(menuItem.isEnabled())
        assertEquals(8, progressBar.progress)
        assertEquals(20, progressBar.progress)

        progress1.apply {
            state = Job.STATE_COMPLETED
@@ -172,7 +172,7 @@ class JobPanelControllerTest {

        assertTrue(menuItem.isVisible())
        assertTrue(menuItem.isEnabled())
        assertEquals(20, progressBar.progress)
        assertEquals(50, progressBar.progress)

        progress2.apply {
            state = Job.STATE_SET_UP
@@ -196,4 +196,38 @@ class JobPanelControllerTest {
        assertTrue(menuItem.isEnabled())
        assertEquals(100, progressBar.progress)
    }

    @Test
    fun testIndeterminateJobs() {
        val indeterminate = MutableJobProgress(
            id = "indeterminate",
            operationType = FileOperationService.OPERATION_MOVE,
            state = Job.STATE_SET_UP,
            msg = "Job started",
            hasFailures = false,
            currentBytes = -1,
            requiredBytes = -1,
            msRemaining = -1
        )
        val determinate = MutableJobProgress(
            id = "determinate",
            operationType = FileOperationService.OPERATION_COPY,
            state = Job.STATE_SET_UP,
            msg = "Job started",
            hasFailures = false,
            currentBytes = 40,
            requiredBytes = 100,
            msRemaining = -1
        )
        sendProgress(arrayListOf(indeterminate.toJobProgress()))

        assertTrue(menuItem.isVisible())
        assertTrue(progressBar.isIndeterminate)

        sendProgress(arrayListOf(indeterminate.toJobProgress(), determinate.toJobProgress()))

        assertTrue(menuItem.isVisible())
        assertFalse(progressBar.isIndeterminate)
        assertEquals(20, progressBar.progress)
    }
}