From 37a7140825076e4682b28126e3df6d40fcbd0193 Mon Sep 17 00:00:00 2001 From: Marten Rebane Date: Wed, 2 Sep 2026 12:31:36 +0300 Subject: [PATCH] Reduce top bar height on landscape mode --- .../ria/DigiDoc/ui/component/shared/TopBar.kt | 10 ++- .../ee/ria/DigiDoc/ui/theme/Dimensions.kt | 2 +- .../ee/ria/DigiDoc/utils/window/WindowUtil.kt | 33 +++++++ .../DigiDoc/utils/window/WindowUtilTest.kt | 86 +++++++++++++++++++ 4 files changed, 129 insertions(+), 2 deletions(-) create mode 100644 app/src/main/kotlin/ee/ria/DigiDoc/utils/window/WindowUtil.kt create mode 100644 app/src/test/kotlin/ee/ria/DigiDoc/utils/window/WindowUtilTest.kt diff --git a/app/src/main/kotlin/ee/ria/DigiDoc/ui/component/shared/TopBar.kt b/app/src/main/kotlin/ee/ria/DigiDoc/ui/component/shared/TopBar.kt index f70121737..2ca4acd26 100644 --- a/app/src/main/kotlin/ee/ria/DigiDoc/ui/component/shared/TopBar.kt +++ b/app/src/main/kotlin/ee/ria/DigiDoc/ui/component/shared/TopBar.kt @@ -51,6 +51,7 @@ import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.layout.onGloballyPositioned import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.platform.LocalWindowInfo import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.stringResource import androidx.compose.ui.res.vectorResource @@ -59,10 +60,13 @@ import androidx.compose.ui.semantics.isTraversalGroup import androidx.compose.ui.semantics.popup import androidx.compose.ui.semantics.semantics import androidx.compose.ui.semantics.testTagsAsResourceId +import androidx.compose.ui.text.style.TextOverflow import androidx.core.net.toUri import androidx.lifecycle.asFlow import ee.ria.DigiDoc.R +import ee.ria.DigiDoc.ui.theme.Dimensions.compactToolbarHeight import ee.ria.DigiDoc.ui.theme.Dimensions.iconSizeXXS +import ee.ria.DigiDoc.utils.window.WindowUtil import ee.ria.DigiDoc.utilsLib.text.TextUtil import ee.ria.DigiDoc.viewmodel.shared.SharedMenuViewModel import kotlinx.coroutines.CoroutineScope @@ -128,6 +132,8 @@ fun TopBar( val coroutineScope = rememberCoroutineScope() var debounceJob by remember { mutableStateOf(null) } + val isCompactLandscape = WindowUtil.isCompactLandscapeWindow(LocalWindowInfo.current.containerDpSize) + TopAppBar( modifier = modifier @@ -135,6 +141,7 @@ fun TopBar( isTraversalGroup = true testTagsAsResourceId = true }.testTag("toolbar"), + expandedHeight = if (isCompactLandscape) compactToolbarHeight else TopAppBarDefaults.TopAppBarExpandedHeight, colors = TopAppBarDefaults.topAppBarColors( containerColor = MaterialTheme.colorScheme.surface, @@ -183,7 +190,8 @@ fun TopBar( PreventResize { Text( text = stringResource(id = title), - maxLines = 2, + maxLines = if (isCompactLandscape) 1 else 2, + overflow = if (isCompactLandscape) TextOverflow.Ellipsis else TextOverflow.Clip, modifier = modifier .semantics { heading() } diff --git a/app/src/main/kotlin/ee/ria/DigiDoc/ui/theme/Dimensions.kt b/app/src/main/kotlin/ee/ria/DigiDoc/ui/theme/Dimensions.kt index 254472768..1c652a409 100644 --- a/app/src/main/kotlin/ee/ria/DigiDoc/ui/theme/Dimensions.kt +++ b/app/src/main/kotlin/ee/ria/DigiDoc/ui/theme/Dimensions.kt @@ -25,7 +25,7 @@ import androidx.compose.ui.unit.dp object Dimensions { // Heights - val toolbarHeight = 48.dp + val compactToolbarHeight = 48.dp val dividerHeight = 0.1.dp val invisibleElementHeight = 1.dp diff --git a/app/src/main/kotlin/ee/ria/DigiDoc/utils/window/WindowUtil.kt b/app/src/main/kotlin/ee/ria/DigiDoc/utils/window/WindowUtil.kt new file mode 100644 index 000000000..5f31bdb1d --- /dev/null +++ b/app/src/main/kotlin/ee/ria/DigiDoc/utils/window/WindowUtil.kt @@ -0,0 +1,33 @@ +/* + * Copyright 2017 - 2026 Riigi Infosüsteemi Amet + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +@file:Suppress("PackageName") + +package ee.ria.DigiDoc.utils.window + +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp + +object WindowUtil { + private val compactHeightBreakpoint = 480.dp + private val mediumWidthBreakpoint = 600.dp + + fun isCompactLandscapeWindow(windowSize: DpSize): Boolean = + windowSize.height < compactHeightBreakpoint && windowSize.width >= mediumWidthBreakpoint +} diff --git a/app/src/test/kotlin/ee/ria/DigiDoc/utils/window/WindowUtilTest.kt b/app/src/test/kotlin/ee/ria/DigiDoc/utils/window/WindowUtilTest.kt new file mode 100644 index 000000000..4482402dd --- /dev/null +++ b/app/src/test/kotlin/ee/ria/DigiDoc/utils/window/WindowUtilTest.kt @@ -0,0 +1,86 @@ +/* + * Copyright 2017 - 2026 Riigi Infosüsteemi Amet + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +@file:Suppress("PackageName") + +package ee.ria.DigiDoc.utils.window + +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp +import org.junit.Assert.assertFalse +import org.junit.Assert.assertTrue +import org.junit.Test + +class WindowUtilTest { + @Test + fun windowUtil_isCompactLandscapeWindow_phoneLandscapeReturnsTrue() { + assertTrue(WindowUtil.isCompactLandscapeWindow(DpSize(915.dp, 411.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_phonePortraitReturnsFalse() { + assertFalse(WindowUtil.isCompactLandscapeWindow(DpSize(411.dp, 915.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_phonePortraitSplitScreenReturnsFalse() { + // Landscape-shaped but far too narrow for a single-line title + assertFalse(WindowUtil.isCompactLandscapeWindow(DpSize(411.dp, 400.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_phoneLandscapeSideBySideSplitReturnsFalse() { + assertFalse(WindowUtil.isCompactLandscapeWindow(DpSize(453.dp, 412.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_tabletLandscapeReturnsFalse() { + assertFalse(WindowUtil.isCompactLandscapeWindow(DpSize(1280.dp, 800.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_tabletPortraitReturnsFalse() { + assertFalse(WindowUtil.isCompactLandscapeWindow(DpSize(800.dp, 1280.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_smallestDisplaySizePhoneLandscapeReturnsFalse() { + assertFalse(WindowUtil.isCompactLandscapeWindow(DpSize(1075.dp, 484.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_heightExactlyAtBreakpointReturnsFalse() { + assertFalse(WindowUtil.isCompactLandscapeWindow(DpSize(915.dp, 480.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_widthExactlyAtBreakpointReturnsTrue() { + assertTrue(WindowUtil.isCompactLandscapeWindow(DpSize(600.dp, 479.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_widthJustBelowBreakpointReturnsFalse() { + assertFalse(WindowUtil.isCompactLandscapeWindow(DpSize(599.dp, 479.dp))) + } + + @Test + fun windowUtil_isCompactLandscapeWindow_zeroSizeReturnsFalse() { + assertFalse(WindowUtil.isCompactLandscapeWindow(DpSize.Zero)) + } +}