diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ModifierExtension.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ModifierExtension.kt deleted file mode 100644 index 65dcf70..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ModifierExtension.kt +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.eclipse.kuksa.companion.extension - -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.alpha - -fun Modifier.isVisible(isVisible: Boolean): Modifier { - val alpha = if (isVisible) 1F else 0F - - return then(Modifier.alpha(alpha)) -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/StringExtension.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/StringExtension.kt deleted file mode 100644 index 1d4298f..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/StringExtension.kt +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.eclipse.kuksa.companion.extension - -fun String.toVertical(): String { - if (isEmpty()) return this - - val charArray = toCharArray() - val builder = StringBuilder() - charArray.forEach { - builder.appendLine(it) - } - - return builder.toString().dropLast(1) -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AdaptiveConnectionStatusView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AdaptiveConnectionStatusView.kt deleted file mode 100644 index 15e6c8b..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AdaptiveConnectionStatusView.kt +++ /dev/null @@ -1,106 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.eclipse.kuksa.companion.feature.connection.view - -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.PaddingValues -import androidx.compose.material3.windowsizeclass.WindowSizeClass -import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.platform.LocalConfiguration -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP -import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP -import org.eclipse.kuksa.companion.extension.windowSizeClass -import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel -import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel.ConnectionState - -val StatusBarHeight = 50.dp - -@Composable -fun AdaptiveConnectionStatusView( - viewModel: ConnectionStatusViewModel, - windowSizeClass: WindowSizeClass, - modifier: Modifier = Modifier, -) { - if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - HorizontalConnectionStatusView(viewModel, modifier) - } else { - VerticalConnectionStatusView(viewModel, modifier) - } -} - -class ConnectionStatusView private constructor() { - companion object { - fun calculatePaddingValues( - viewModel: ConnectionStatusViewModel, - windowSizeClass: WindowSizeClass, - ): PaddingValues { - if (viewModel.connectionState == ConnectionState.CONNECTED) return PaddingValues(0.dp) - - return if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - PaddingValues(top = StatusBarHeight) - } else { - PaddingValues(start = StatusBarHeight) - } - } - } -} - -@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) -@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) -@Composable -private fun AdaptiveDisconnectedPreview() { - val viewModel = ConnectionStatusViewModel() - viewModel.connectionState = ConnectionState.DISCONNECTED - - val windowSizeClass = LocalConfiguration.current.windowSizeClass - Box { - AdaptiveConnectionStatusView(viewModel = viewModel, windowSizeClass) - } -} - -@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) -@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) -@Composable -private fun AdaptiveConnectingPreview() { - val viewModel = ConnectionStatusViewModel() - viewModel.connectionState = ConnectionState.CONNECTING - - val windowSizeClass = LocalConfiguration.current.windowSizeClass - Box { - AdaptiveConnectionStatusView(viewModel = viewModel, windowSizeClass) - } -} - -@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) -@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) -@Composable -private fun AdaptiveConnectedStatusPreview() { - val viewModel = ConnectionStatusViewModel() - viewModel.connectionState = ConnectionState.CONNECTED - - val windowSizeClass = LocalConfiguration.current.windowSizeClass - Box { - AdaptiveConnectionStatusView(viewModel = viewModel, windowSizeClass) - } -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AnimatedLoadingText.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AnimatedLoadingText.kt deleted file mode 100644 index 22271ab..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AnimatedLoadingText.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.eclipse.kuksa.companion.feature.connection.view - -import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.mutableIntStateOf -import androidx.compose.runtime.remember -import kotlinx.coroutines.delay -import kotlin.time.Duration.Companion.milliseconds - -private const val MaxNumberDots = 3 -private val DelayDuration = 500.milliseconds - -@Composable -fun animateLoadingText( - isAnimating: Boolean, - text: String, -): String { - var animatedText = text - if (isAnimating) { - val numberOfDots = remember { - mutableIntStateOf(0) - } - repeat(numberOfDots.intValue) { - animatedText += "." - } - LaunchedEffect(Unit) { - while (true) { - if (numberOfDots.intValue < MaxNumberDots) { - numberOfDots.intValue += 1 - } else { - numberOfDots.intValue = 0 - } - delay(DelayDuration) - } - } - } - return animatedText -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/HorizontalConnectionStatusView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/HorizontalConnectionStatusView.kt index d97f1e7..3f07428 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/HorizontalConnectionStatusView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/HorizontalConnectionStatusView.kt @@ -22,27 +22,32 @@ package org.eclipse.kuksa.companion.feature.connection.view import androidx.compose.foundation.Image import androidx.compose.foundation.background import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material3.CircularProgressIndicator +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import androidx.constraintlayout.compose.ConstraintLayout import org.eclipse.kuksa.companion.R -import org.eclipse.kuksa.companion.extension.isVisible import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel.ConnectionState +val StatusBarHeight = 50.dp +private val iconSize = 30.dp +private val paddingEnd = 5.dp + @Composable fun HorizontalConnectionStatusView( viewModel: ConnectionStatusViewModel, @@ -50,9 +55,10 @@ fun HorizontalConnectionStatusView( ) { val connectionState = viewModel.connectionState val connectionStateLabel = connectionState.toString() - val backgroundColor = viewModel.backgroundColor + val backgroundColor = MaterialTheme.colorScheme.errorContainer - Row( + Box( + contentAlignment = Alignment.Center, modifier = modifier .fillMaxWidth() .height(StatusBarHeight) @@ -61,42 +67,41 @@ fun HorizontalConnectionStatusView( viewModel.onClickReconnect() }, ) { - val isAnimating = connectionState == ConnectionState.CONNECTING - var text = connectionStateLabel - text = animateLoadingText(isAnimating, text) + Row { + when (connectionState) { + ConnectionState.DISCONNECTED -> { + Image( + painter = painterResource(id = R.drawable.baseline_refresh_24), + contentDescription = "Reconnect", + colorFilter = ColorFilter.tint(MaterialTheme.colorScheme.error), + alignment = Alignment.CenterEnd, + modifier = Modifier + .size(iconSize) + .padding(end = paddingEnd), + ) + } + + ConnectionState.CONNECTING -> { + CircularProgressIndicator( + color = MaterialTheme.colorScheme.error, + modifier = Modifier + .size(iconSize) + .padding(end = paddingEnd), + ) + } + + else -> { + // unused + } + } - ConstraintLayout(modifier = Modifier.height(StatusBarHeight)) { - val (textRef, imageRef) = createRefs() Text( - text, - color = Color.White, + connectionStateLabel, + color = MaterialTheme.colorScheme.error, textAlign = TextAlign.Center, fontWeight = FontWeight.Bold, modifier = Modifier - .fillMaxWidth() - .constrainAs(textRef) { - top.linkTo(parent.top) - bottom.linkTo(parent.bottom) - - start.linkTo(parent.start) - end.linkTo(imageRef.start) - }, - ) - - Image( - painter = painterResource(id = R.drawable.baseline_refresh_24), - contentDescription = "Reconnect", - colorFilter = ColorFilter.tint(Color.White), - alignment = Alignment.CenterEnd, - modifier = Modifier - .constrainAs(imageRef) { - top.linkTo(parent.top) - bottom.linkTo(parent.bottom) - - end.linkTo(parent.end) - } - .padding(10.dp) - .isVisible(connectionState == ConnectionState.DISCONNECTED), + .align(Alignment.CenterVertically), ) } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalConnectionStatusView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalConnectionStatusView.kt deleted file mode 100644 index d852a08..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalConnectionStatusView.kt +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (c) 2023 Contributors to the Eclipse Foundation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -package org.eclipse.kuksa.companion.feature.connection.view - -import androidx.compose.foundation.Image -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.width -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.ColorFilter -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.constraintlayout.compose.ConstraintLayout -import org.eclipse.kuksa.companion.R -import org.eclipse.kuksa.companion.extension.isVisible -import org.eclipse.kuksa.companion.extension.toVertical -import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel - -@Composable -fun VerticalConnectionStatusView( - viewModel: ConnectionStatusViewModel, - modifier: Modifier = Modifier, -) { - val connectionState = viewModel.connectionState - val connectionStateLabel = connectionState.toString() - val backgroundColor = viewModel.backgroundColor - - Column( - modifier = modifier - .fillMaxHeight() - .width(StatusBarHeight) - .background(backgroundColor) - .clickable(enabled = connectionState == ConnectionStatusViewModel.ConnectionState.DISCONNECTED) { - viewModel.onClickReconnect() - }, - ) { - val isAnimating = connectionState == ConnectionStatusViewModel.ConnectionState.CONNECTING - var text = connectionStateLabel - text = animateLoadingText(isAnimating, text) - - ConstraintLayout(modifier = Modifier.fillMaxSize()) { - val (textRef, imageRef) = createRefs() - - Text( - text = text.toVertical(), - color = Color.White, - textAlign = TextAlign.Center, - fontWeight = FontWeight.Bold, - modifier = Modifier - .constrainAs(textRef) { - start.linkTo(parent.start) - end.linkTo(parent.end) - - top.linkTo(parent.top) - bottom.linkTo(imageRef.top) - }, - ) - - Image( - painter = painterResource(id = R.drawable.baseline_refresh_24), - contentDescription = "Reconnect", - colorFilter = ColorFilter.tint(Color.White), - alignment = Alignment.BottomCenter, - modifier = Modifier - .fillMaxWidth() - .constrainAs(imageRef) { - start.linkTo(parent.start) - end.linkTo(parent.end) - - bottom.linkTo(parent.bottom) - } - .padding(10.dp) - .isVisible(connectionState == ConnectionStatusViewModel.ConnectionState.DISCONNECTED), - ) - } - } -} - -@Preview(heightDp = 300) -@Composable -private fun VerticalDisconnectedPreview() { - val viewModel = ConnectionStatusViewModel() - viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.DISCONNECTED - - VerticalConnectionStatusView(viewModel = viewModel) -} - -@Preview(heightDp = 300) -@Composable -private fun VerticalConnectingPreview() { - val viewModel = ConnectionStatusViewModel() - viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTING - VerticalConnectionStatusView(viewModel = viewModel) -} - -@Preview(heightDp = 300) -@Composable -private fun VerticalConnectedPreview() { - val viewModel = ConnectionStatusViewModel() - viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTED - VerticalConnectionStatusView(viewModel = viewModel) -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/viewModel/ConnectionStatusViewModel.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/viewModel/ConnectionStatusViewModel.kt index fa88f5b..78bd3b9 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/viewModel/ConnectionStatusViewModel.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/viewModel/ConnectionStatusViewModel.kt @@ -19,13 +19,10 @@ package org.eclipse.kuksa.companion.feature.connection.viewModel -import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue -import androidx.compose.ui.graphics.Color import androidx.lifecycle.ViewModel -import org.eclipse.kuksa.companion.extension.DarkGreen class ConnectionStatusViewModel : ViewModel() { enum class ConnectionState { @@ -37,14 +34,4 @@ class ConnectionStatusViewModel : ViewModel() { var onClickReconnect: () -> Unit = { } var connectionState by mutableStateOf(ConnectionState.DISCONNECTED) - - val backgroundColor by derivedStateOf { - when (connectionState) { - ConnectionState.CONNECTED -> Color.DarkGreen - - ConnectionState.CONNECTING, - ConnectionState.DISCONNECTED, - -> Color.Red - } - } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveAppScreen.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveAppScreen.kt index f13ee6c..8473611 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveAppScreen.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveAppScreen.kt @@ -22,6 +22,7 @@ package org.eclipse.kuksa.companion.feature.home.view import android.app.Application import android.view.SurfaceHolder import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.PaddingValues import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding import androidx.compose.material3.windowsizeclass.WindowSizeClass @@ -35,15 +36,15 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP import org.eclipse.kuksa.companion.extension.windowSizeClass import org.eclipse.kuksa.companion.feature.connection.repository.ConnectionInfoRepository -import org.eclipse.kuksa.companion.feature.connection.view.AdaptiveConnectionStatusView -import org.eclipse.kuksa.companion.feature.connection.view.ConnectionStatusView +import org.eclipse.kuksa.companion.feature.connection.view.HorizontalConnectionStatusView +import org.eclipse.kuksa.companion.feature.connection.view.StatusBarHeight import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel -import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel.ConnectionState import org.eclipse.kuksa.companion.feature.door.view.DoorControlView import org.eclipse.kuksa.companion.feature.door.view.DoorOverlayView import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel @@ -62,8 +63,9 @@ import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureView import org.eclipse.kuksa.companion.feature.wheel.pressure.view.WheelPressureOverlayView import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel -private const val ZINDEX_CONTENT = 0F -private const val ZINDEX_OVERLAY = 1F +private const val Z_INDEX_CONTENT = 0F +private const val Z_INDEX_OVERLAY = 1F +private const val Z_INDEX_ERROR = 2F /** * Adds an adaptive AppScreen depending on the [WindowWidthSizeClass]. When the device has a [WindowWidthSizeClass] of @@ -87,53 +89,50 @@ fun AdaptiveAppScreen( mutableStateOf(navigationViewModel.selectedNavigationPage) } - Box { - val navigationViewPaddingValues = AdaptiveNavigationView.calculatePaddingValues(windowSizeClass) - if (connectionStatusViewModel.connectionState != ConnectionState.CONNECTED) { - AdaptiveConnectionStatusView( - connectionStatusViewModel, - windowSizeClass, - Modifier - .zIndex(ZINDEX_OVERLAY) - .padding(navigationViewPaddingValues), - ) + AdaptiveColumnRow( + windowSizeClass = windowSizeClass, + modifier = modifier.fillMaxSize(), + ) { + AdaptiveNavigationView(navigationViewModel, windowSizeClass) { page -> + selectedPage = page } - - val connectionStatusViewPaddingValues = - ConnectionStatusView.calculatePaddingValues(connectionStatusViewModel, windowSizeClass) - AdaptiveColumnRow( + AdaptiveSheetView( windowSizeClass = windowSizeClass, - modifier = modifier.fillMaxSize(), - ) { - AdaptiveNavigationView(navigationViewModel, windowSizeClass) { page -> - selectedPage = page - } - AdaptiveSheetView( - windowSizeClass = windowSizeClass, - modifier = Modifier - .fillMaxSize(), - isSheetEnabled = selectedPage.isSheetEnabled, - sheetContent = { - when (selectedPage) { - NavigationPage.DOORS -> DoorControlView(doorControlViewModel) - NavigationPage.TEMPERATURE -> TemperatureControlView(temperatureViewModel) - NavigationPage.LIGHT -> LightControlView(lightControlViewModel) - NavigationPage.WHEELS, - NavigationPage.SETTINGS, - -> { - } + modifier = Modifier + .fillMaxSize(), + isSheetEnabled = selectedPage.isSheetEnabled, + sheetContent = { + when (selectedPage) { + NavigationPage.DOORS -> DoorControlView(doorControlViewModel) + NavigationPage.TEMPERATURE -> TemperatureControlView(temperatureViewModel) + NavigationPage.LIGHT -> LightControlView(lightControlViewModel) + NavigationPage.WHEELS, + NavigationPage.SETTINGS, + -> { } - }, - ) { + } + }, + ) { + Box { + var connectionStatusViewPaddingValues = PaddingValues(0.dp) + if (connectionStatusViewModel.connectionState != ConnectionStatusViewModel.ConnectionState.CONNECTED) { + connectionStatusViewPaddingValues = PaddingValues(top = StatusBarHeight) + HorizontalConnectionStatusView( + connectionStatusViewModel, + Modifier + .zIndex(Z_INDEX_ERROR), + ) + } + RamsesView( callback = callback, modifier = Modifier - .zIndex(ZINDEX_CONTENT) + .zIndex(Z_INDEX_CONTENT) .fillMaxSize(), ) val overlayModifier = Modifier - .zIndex(ZINDEX_OVERLAY) + .zIndex(Z_INDEX_OVERLAY) .fillMaxSize() when (selectedPage) { @@ -152,7 +151,8 @@ fun AdaptiveAppScreen( NavigationPage.LIGHT -> LightOverlayView( lightControlViewModel, windowSizeClass, - overlayModifier, + overlayModifier + .padding(connectionStatusViewPaddingValues), ) NavigationPage.WHEELS -> WheelPressureOverlayView( diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/AdaptiveNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/AdaptiveNavigationView.kt index 8861c4d..aae5eee 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/AdaptiveNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/AdaptiveNavigationView.kt @@ -19,14 +19,12 @@ package org.eclipse.kuksa.companion.feature.navigation.view -import androidx.compose.foundation.layout.PaddingValues import androidx.compose.material3.windowsizeclass.WindowSizeClass import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP import org.eclipse.kuksa.companion.extension.windowSizeClass @@ -52,18 +50,6 @@ fun AdaptiveNavigationView( } } -class AdaptiveNavigationView private constructor() { - companion object { - fun calculatePaddingValues(windowSizeClass: WindowSizeClass): PaddingValues { - return if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - PaddingValues(top = 80.dp) // NavigationBarTokens#ContainerHeight + padding - } else { - PaddingValues(start = 92.dp) // NavigationRailTokens#ContainerWidth + padding - } - } - } -} - @Composable @Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/HorizontalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/HorizontalNavigationView.kt index e50d757..9199072 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/HorizontalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/HorizontalNavigationView.kt @@ -19,12 +19,13 @@ package org.eclipse.kuksa.companion.feature.navigation.view -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.size import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.NavigationBar import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf @@ -47,26 +48,27 @@ fun HorizontalNavigationView( mutableIntStateOf(viewModel.selectedNavigationIndex) } - Column(modifier) { - NavigationBar(Modifier.fillMaxWidth()) { - NavigationPage.entries.forEachIndexed { index, page -> - NavigationBarItem( - selected = index == selectedItemIndex, - onClick = { - selectedItemIndex = index - viewModel.selectedNavigationIndex = index - viewModel.selectedNavigationPage = page - onPageSelected(page) - }, - icon = { - Icon( - painter = painterResource(id = page.iconRes), - contentDescription = page.description, - modifier = Modifier.size(30.dp), - ) - }, - ) - } + NavigationBar( + containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(3.dp), + modifier = modifier.fillMaxWidth(), + ) { + NavigationPage.entries.forEachIndexed { index, page -> + NavigationBarItem( + selected = index == selectedItemIndex, + onClick = { + selectedItemIndex = index + viewModel.selectedNavigationIndex = index + viewModel.selectedNavigationPage = page + onPageSelected(page) + }, + icon = { + Icon( + painter = painterResource(id = page.iconRes), + contentDescription = page.description, + modifier = Modifier.size(30.dp), + ) + }, + ) } } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/VerticalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/VerticalNavigationView.kt index 61674a9..54c8aa0 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/VerticalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/VerticalNavigationView.kt @@ -23,9 +23,11 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme import androidx.compose.material3.NavigationRail import androidx.compose.material3.NavigationRailItem import androidx.compose.material3.Text +import androidx.compose.material3.surfaceColorAtElevation import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf @@ -53,7 +55,10 @@ fun VerticalNavigationView( val pages = NavigationPage.entries.toTypedArray() - NavigationRail(modifier) { + NavigationRail( + containerColor = MaterialTheme.colorScheme.surfaceColorAtElevation(3.dp), + modifier = modifier, + ) { Spacer(Modifier.weight(1f)) pages.forEachIndexed { index, page -> NavigationRailItem( diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/settings/view/SettingsView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/settings/view/SettingsView.kt index bd2ed75..b4e7ab8 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/settings/view/SettingsView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/settings/view/SettingsView.kt @@ -65,7 +65,7 @@ fun SettingsView( Surface(modifier) { Column( modifier = Modifier - .padding(10.dp, 0.dp), + .padding(horizontal = 10.dp), ) { CategorySetting(label = "Connection") EditableTextSetting( diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/SideSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/SideSheetView.kt index 92b29bb..8b0ac3b 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/SideSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/SideSheetView.kt @@ -39,16 +39,21 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ComposeView +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.viewinterop.AndroidView -import androidx.compose.ui.zIndex import androidx.constraintlayout.compose.ConstraintLayout import androidx.coordinatorlayout.widget.CoordinatorLayout import com.google.android.material.sidesheet.SideSheetBehavior +import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP +import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP import org.eclipse.kuksa.companion.R import org.eclipse.kuksa.companion.SHEET_EXPANDED_HEIGHT +import org.eclipse.kuksa.companion.feature.connection.repository.ConnectionInfoRepository +import org.eclipse.kuksa.companion.feature.settings.view.SettingsView +import org.eclipse.kuksa.companion.feature.settings.viewModel.SettingsViewModel @Composable fun SideSheetView( @@ -59,9 +64,7 @@ fun SideSheetView( ) { val sideSheetBehavior: SideSheetBehavior = SideSheetBehavior() ConstraintLayout(modifier = modifier) { - Box(Modifier.fillMaxSize()) { - content() - } + content() if (!isSideSheetEnabled) { return@ConstraintLayout @@ -70,7 +73,6 @@ fun SideSheetView( SideSheetInteractionFAB( sideSheetBehavior = sideSheetBehavior, modifier = Modifier - .zIndex(2F) .constrainAs(createRef()) { end.linkTo(parent.end, 10.dp) bottom.linkTo(parent.bottom, 10.dp) @@ -81,7 +83,6 @@ fun SideSheetView( sheetContent = sheetContent, sideSheetBehavior = sideSheetBehavior, modifier = Modifier - .zIndex(Float.MAX_VALUE) .fillMaxHeight() .width(SHEET_EXPANDED_HEIGHT.dp) .constrainAs(createRef()) { @@ -175,8 +176,14 @@ private fun SideSheetInteractionFAB( } } -@Preview +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) @Composable private fun SideSheetViewPreview() { - SideSheetView(isSideSheetEnabled = true, sheetContent = {}) {} + val context = LocalContext.current + val repository = ConnectionInfoRepository(context) + val settingsViewModel = SettingsViewModel(repository) + + SideSheetView(isSideSheetEnabled = true, sheetContent = {}) { + SettingsView(settingsViewModel = settingsViewModel, Modifier.fillMaxSize()) + } }