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

Commit 5a874a66 authored by Pragya Bajoria's avatar Pragya Bajoria Committed by Android (Google) Code Review
Browse files

Merge "Update the onTaskChanging method for DesktopTaskChangeListener to...

Merge "Update the onTaskChanging method for DesktopTaskChangeListener to simplify the logic." into main
parents 064262d3 e1ff0bf3
Loading
Loading
Loading
Loading
+6 −18
Original line number Diff line number Diff line
@@ -53,24 +53,12 @@ class DesktopTaskChangeListener(private val desktopUserRepositories: DesktopUser
        // Case 1: When the task change is from a task in the desktop repository which is now
        // fullscreen,
        // remove the task from the desktop repository since it is no longer a freeform task.
        if (!isFreeformTask(taskInfo)) {
            if (desktopRepository.isActiveTask(taskInfo.taskId)) {
        if (!isFreeformTask(taskInfo) && desktopRepository.isActiveTask(taskInfo.taskId)) {
            desktopRepository.removeTask(taskInfo.displayId, taskInfo.taskId)
            }
        } else { // Task change is a freeform task
            if (!desktopRepository.isActiveTask(taskInfo.taskId)) {
                // Case 2: When the task change is a freeform visible task, but the task is not
                // yet active in the desktop repository, adds task to desktop repository.
        } else if (isFreeformTask(taskInfo)) {
            // If the task is already active in the repository, then moves task to the front,
            // else adds the task.
            desktopRepository.addTask(taskInfo.displayId, taskInfo.taskId, taskInfo.isVisible)
            } else {
                // Case 3: When the task change is a freeform task which already exists as an active
                // task in the desktop repository, updates the task state.
                desktopRepository.updateTask(
                    taskInfo.displayId,
                    taskInfo.taskId,
                    taskInfo.isVisible,
                )
            }
        }
    }

+1 −24
Original line number Diff line number Diff line
@@ -119,37 +119,14 @@ class DesktopTaskChangeListenerTest : ShellTestCase() {
    }

    @Test
    fun onTaskChanging_freeformTask_nonActiveTaskInDesktopRepo_addsTaskToDesktopRepo() {
    fun onTaskChanging_freeformTask_addsTaskToDesktopRepo() {
        val task = createFreeformTask().apply { isVisible = true }
        whenever(desktopUserRepositories.current.isActiveTask(task.taskId)).thenReturn(false)

        desktopTaskChangeListener.onTaskChanging(task)

        verify(desktopUserRepositories.current).addTask(task.displayId, task.taskId, task.isVisible)
    }

    @Test
    fun onTaskChanging_freeformTask_activeVisibleTaskInDesktopRepo_updatesTaskVisibility() {
        val task = createFreeformTask().apply { isVisible = true }
        whenever(desktopUserRepositories.current.isActiveTask(task.taskId)).thenReturn(true)

        desktopTaskChangeListener.onTaskChanging(task)

        verify(desktopUserRepositories.current)
            .updateTask(task.displayId, task.taskId, task.isVisible)
    }

    @Test
    fun onTaskChanging_freeformTask_activeNonVisibleTask_updatesTaskVisibility() {
        val task = createFreeformTask().apply { isVisible = false }
        whenever(desktopUserRepositories.current.isActiveTask(task.taskId)).thenReturn(true)

        desktopTaskChangeListener.onTaskChanging(task)

        verify(desktopUserRepositories.current)
            .updateTask(task.displayId, task.taskId, task.isVisible)
    }

    @Test
    fun onTaskMovingToFront_fullscreenTask_activeTaskInDesktopRepo_removesTaskFromRepo() {
        val task = createFullscreenTask().apply { isVisible = true }