Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -128,13 +132,16 @@ fun TopBar(
val coroutineScope = rememberCoroutineScope()
var debounceJob by remember { mutableStateOf<Job?>(null) }

val isCompactLandscape = WindowUtil.isCompactLandscapeWindow(LocalWindowInfo.current.containerDpSize)

TopAppBar(
modifier =
modifier
.semantics {
isTraversalGroup = true
testTagsAsResourceId = true
}.testTag("toolbar"),
expandedHeight = if (isCompactLandscape) compactToolbarHeight else TopAppBarDefaults.TopAppBarExpandedHeight,
colors =
TopAppBarDefaults.topAppBarColors(
containerColor = MaterialTheme.colorScheme.surface,
Expand Down Expand Up @@ -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() }
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/ee/ria/DigiDoc/ui/theme/Dimensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
33 changes: 33 additions & 0 deletions app/src/main/kotlin/ee/ria/DigiDoc/utils/window/WindowUtil.kt
Original file line number Diff line number Diff line change
@@ -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
}
86 changes: 86 additions & 0 deletions app/src/test/kotlin/ee/ria/DigiDoc/utils/window/WindowUtilTest.kt
Original file line number Diff line number Diff line change
@@ -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))
}
}
Loading