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

Commit 45ba4a04 authored by Yuichiro Hanada's avatar Yuichiro Hanada Committed by Android (Google) Code Review
Browse files

Merge "Return the default snap bounds if there is no active desk" into main

parents 5a3600b6 32618b0b
Loading
Loading
Loading
Loading
+8 −28
Original line number Diff line number Diff line
@@ -215,19 +215,6 @@ class DesktopTilingDecorViewModel(
    }

    fun getRightSnapBoundsIfTiled(displayId: Int): Rect {
        val deskId = getCurrentActiveDeskForDisplay(displayId)
        if (deskId == null) {
            logW(
                "Attempted to get right tiling snap bounds with no active desktop for displayId=%d.",
                displayId,
            )
            return Rect()
        }
        val tilingBounds =
            tilingHandlerByUserAndDeskId[currentUserId]?.get(deskId)?.getRightSnapBoundsIfTiled()
        if (tilingBounds != null) {
            return tilingBounds
        }
        val displayLayout = displayController.getDisplayLayout(displayId)
        val stableBounds = Rect()
        displayLayout?.getStableBounds(stableBounds)
@@ -240,23 +227,13 @@ class DesktopTilingDecorViewModel(
                stableBounds.right,
                stableBounds.bottom,
            )
        return snapBounds

        val deskId = getCurrentActiveDeskForDisplay(displayId) ?: return snapBounds
        val tilingHandler = tilingHandlerByUserAndDeskId[currentUserId]?.get(deskId)
        return tilingHandler?.getRightSnapBoundsIfTiled() ?: snapBounds
    }

    fun getLeftSnapBoundsIfTiled(displayId: Int): Rect {
        val deskId = getCurrentActiveDeskForDisplay(displayId)
        if (deskId == null) {
            logW(
                "Attempted to get left tiling snap bounds with no active desktop for displayId=%d.",
                displayId,
            )
            return Rect()
        }
        val tilingBounds =
            tilingHandlerByUserAndDeskId[currentUserId]?.get(deskId)?.getLeftSnapBoundsIfTiled()
        if (tilingBounds != null) {
            return tilingBounds
        }
        val displayLayout = displayController.getDisplayLayout(displayId)
        val stableBounds = Rect()
        displayLayout?.getStableBounds(stableBounds)
@@ -268,7 +245,10 @@ class DesktopTilingDecorViewModel(
                    context.resources.getDimensionPixelSize(R.dimen.split_divider_bar_width) / 2,
                stableBounds.bottom,
            )
        return snapBounds

        val deskId = getCurrentActiveDeskForDisplay(displayId) ?: return snapBounds
        val tilingHandler = tilingHandlerByUserAndDeskId[currentUserId]?.get(deskId)
        return tilingHandler?.getLeftSnapBoundsIfTiled() ?: snapBounds
    }

    /** Notifies tiling of a desk being deactivated. */
+9 −0
Original line number Diff line number Diff line
@@ -400,6 +400,15 @@ class DesktopTilingDecorViewModelTest : ShellTestCase() {
            .isEqualTo(Rect(12, 7, 8, 9))
    }

    @Test
    fun getTiledAppBounds_NoActiveDesk() {
        whenever(desktopRepository.getActiveDeskId(any())).thenReturn(null)
        assertThat(desktopTilingDecorViewModel.getLeftSnapBoundsIfTiled(2))
            .isEqualTo(Rect(6, 7, 2, 9))
        assertThat(desktopTilingDecorViewModel.getRightSnapBoundsIfTiled(2))
            .isEqualTo(Rect(12, 7, 8, 9))
    }

    companion object {
        private val BOUNDS = Rect(1, 2, 3, 4)
        private val STABLE_BOUNDS = Rect(6, 7, 8, 9)