From 86538dcb2e9e3de01c3a75e05d41819ab9cfb51d Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Mon, 22 Jan 2024 14:17:49 +0100 Subject: [PATCH 01/28] feature: Optimize Views for Landscape Closes: #20 Signed-off-by: Andre Weber --- app/build.gradle.kts | 2 + .../kuksa/companion/CompanionApplication.kt | 3 + .../eclipse/kuksa/companion/MainActivity.kt | 41 ++-- .../extension/ConfigurationExtension.kt | 36 ++++ .../extension/ConstraintScopeExtension.kt | 79 ++++++++ .../companion/extension/ModifierExtension.kt | 29 +++ .../view/AdaptiveConnectionStatusView.kt | 85 +++++++++ .../connection/view/AnimatedLoadingText.kt | 58 ++++++ ...w.kt => HorizontalConnectionStatusView.kt} | 66 +++---- .../view/VerticalConnectionStatusView.kt | 125 ++++++++++++ .../feature/connection/view/VerticalText.kt | 81 ++++++++ .../door/surface/DoorVehicleSurface.kt | 12 +- .../feature/door/view/DoorControlView.kt | 124 ++---------- .../feature/door/view/DoorOverlayView.kt | 167 ++++++++++++++++ .../feature/home/view/AdaptiveAppScreen.kt | 179 ++++++++++++++++++ .../feature/home/view/AdaptiveColumnRow.kt | 48 +++++ .../home/view/AdaptiveFlowRowColumn.kt | 51 +++++ .../feature/home/view/HomeNavigation.kt | 57 ------ .../companion/feature/home/view/HomeScreen.kt | 96 ---------- .../companion/feature/home/view/TabRowHost.kt | 141 -------------- .../view/navigation/AdaptiveNavigationView.kt | 56 ++++++ .../navigation/HorizontalNavigationView.kt | 67 +++++++ .../home/view/navigation/NavigationPage.kt | 55 ++++++ .../view/navigation/VerticalNavigationView.kt | 65 +++++++ .../feature/home/view/sheet/AdaptiveLine.kt | 110 +++++++++++ .../home/view/sheet/AdaptiveSheetLayout.kt | 116 ++++++++++++ .../feature/light/view/LightControlView.kt | 101 +--------- .../feature/light/view/LightOverlayView.kt | 119 ++++++++++++ .../settings/navigation/SettingsNavigation.kt | 45 ----- .../feature/settings/view/SettingsView.kt | 33 +--- .../view/TemperatureControlView.kt | 101 +--------- .../view/TemperatureOverlayView.kt | 128 +++++++++++++ ...rolView.kt => WheelPressureOverlayView.kt} | 59 ++++-- .../res/drawable/baseline_settings_24.xml | 5 + app/src/main/res/values-land/values.xml | 27 +++ app/src/main/res/values/values.xml | 27 +++ 36 files changed, 1833 insertions(+), 761 deletions(-) create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConfigurationExtension.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ModifierExtension.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AdaptiveConnectionStatusView.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AnimatedLoadingText.kt rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/{ConnectionStatusView.kt => HorizontalConnectionStatusView.kt} (67%) create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalConnectionStatusView.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalText.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveAppScreen.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveColumnRow.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowRowColumn.kt delete mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/HomeNavigation.kt delete mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/HomeScreen.kt delete mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/TabRowHost.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt delete mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/settings/navigation/SettingsNavigation.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/{WheelPressureControlView.kt => WheelPressureOverlayView.kt} (57%) create mode 100644 app/src/main/res/drawable/baseline_settings_24.xml create mode 100644 app/src/main/res/values-land/values.xml create mode 100644 app/src/main/res/values/values.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 72f2e08..57ba2a9 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -142,6 +142,8 @@ dependencies { implementation(libs.hilt.android) kapt(libs.hilt.android.compiler) + + implementation("androidx.compose.material3:material3-window-size-class:1.1.2") } // Allow references to generated code diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt index 8eee365..ffee8d1 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt @@ -22,5 +22,8 @@ package org.eclipse.kuksa.companion import android.app.Application import dagger.hilt.android.HiltAndroidApp +const val PREVIEW_WIDTH_DP = 400 +const val PREVIEW_HEIGHT_DP = 900 + @HiltAndroidApp class CompanionApplication : Application() diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt index d5c0ed9..15a6f30 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt @@ -24,9 +24,9 @@ import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.viewModels +import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi +import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass import androidx.lifecycle.lifecycleScope -import androidx.navigation.compose.NavHost -import androidx.navigation.compose.rememberNavController import dagger.hilt.android.AndroidEntryPoint import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch @@ -45,12 +45,8 @@ import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.C import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.Companion.DOOR_ALL_OPEN import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.Companion.TRUNK_CLOSED import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.Companion.TRUNK_OPEN -import org.eclipse.kuksa.companion.feature.home.view.HOME_SCREEN -import org.eclipse.kuksa.companion.feature.home.view.RamsesView -import org.eclipse.kuksa.companion.feature.home.view.homeScreen +import org.eclipse.kuksa.companion.feature.home.view.AdaptiveAppScreen import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel -import org.eclipse.kuksa.companion.feature.settings.navigation.navigateToSettingsScreen -import org.eclipse.kuksa.companion.feature.settings.navigation.settingsScreen import org.eclipse.kuksa.companion.feature.settings.viewModel.SettingsViewModel import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel @@ -142,32 +138,25 @@ class MainActivity : ComponentActivity() { } // region: Lifecycle + @OptIn(ExperimentalMaterial3WindowSizeClassApi::class) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) doorVehicleScene = doorVehicleSurface.loadScene(doorControlViewModel) setContent { + val windowSizeClass = calculateWindowSizeClass(activity = this@MainActivity) KuksaCompanionTheme { - val navController = rememberNavController() - RamsesView(callback = doorVehicleSurface) - NavHost(navController, startDestination = HOME_SCREEN) { - homeScreen( - connectionStatusViewModel = connectionStatusViewModel, - doorControlViewModel = doorControlViewModel, - temperatureViewModel = temperatureViewModel, - lightControlViewModel = lightControlViewModel, - wheelPressureViewModel = wheelPressureViewModel, - onNavigateToSettingsScreen = { navController.navigateToSettingsScreen() }, - ) - - settingsScreen( - settingsViewModel = settingsViewModel, - onNavigateBack = { - navController.navigateUp() - }, - ) - } + AdaptiveAppScreen( + callback = doorVehicleSurface, + connectionStatusViewModel = connectionStatusViewModel, + doorControlViewModel = doorControlViewModel, + temperatureViewModel = temperatureViewModel, + lightControlViewModel = lightControlViewModel, + wheelPressureViewModel = wheelPressureViewModel, + settingsViewModel = settingsViewModel, + windowSizeClass = windowSizeClass, + ) } } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConfigurationExtension.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConfigurationExtension.kt new file mode 100644 index 0000000..1808d5f --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConfigurationExtension.kt @@ -0,0 +1,36 @@ +/* + * 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 android.content.res.Configuration +import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi +import androidx.compose.material3.windowsizeclass.WindowSizeClass +import androidx.compose.runtime.Composable +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp + +@OptIn(ExperimentalMaterial3WindowSizeClassApi::class) +@Composable +fun Configuration.getWindowSizeClass(): WindowSizeClass { + val screenWidth = screenWidthDp + val screenHeight = screenHeightDp + val size = DpSize(screenWidth.dp, screenHeight.dp) + return WindowSizeClass.calculateFromSize(size) +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt new file mode 100644 index 0000000..69352cd --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt @@ -0,0 +1,79 @@ +/* + * 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.material3.windowsizeclass.WindowSizeClass +import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass +import androidx.constraintlayout.compose.ConstrainScope +import androidx.constraintlayout.compose.ConstrainedLayoutReference +import org.eclipse.kuksa.companion.feature.door.view.horizontalMarginAnchorToDoor +import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToBackDoor +import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToDoor + +fun ConstrainScope.alignDriverFrontDoor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + end.linkTo(anchorPoint.start, horizontalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, verticalMarginAnchorToDoor) + } else { + end.linkTo(anchorPoint.start, verticalMarginAnchorToDoor) + bottom.linkTo(anchorPoint.top, horizontalMarginAnchorToDoor) + } +} + +fun ConstrainScope.alignPassengerFrontDoor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + start.linkTo(anchorPoint.end, horizontalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, verticalMarginAnchorToDoor) + } else { + end.linkTo(anchorPoint.start, verticalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, horizontalMarginAnchorToDoor) + } +} + + +fun ConstrainScope.alignDriverBackDoor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + end.linkTo(anchorPoint.start, horizontalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, verticalMarginAnchorToBackDoor) + } else { + end.linkTo(anchorPoint.start, verticalMarginAnchorToBackDoor) + bottom.linkTo(anchorPoint.top, horizontalMarginAnchorToDoor) + } +} + +fun ConstrainScope.alignPassengerBackDoor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + start.linkTo(anchorPoint.end, horizontalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, verticalMarginAnchorToBackDoor) + } else { + end.linkTo(anchorPoint.start, verticalMarginAnchorToBackDoor) + top.linkTo(anchorPoint.bottom, horizontalMarginAnchorToDoor) + } +} + +fun ConstrainScope.alignTrunk(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + centerHorizontallyTo(anchorPoint) + bottom.linkTo(parent.bottom) + } else { + centerVerticallyTo(anchorPoint) + start.linkTo(parent.start) + } +} 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 new file mode 100644 index 0000000..65dcf70 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ModifierExtension.kt @@ -0,0 +1,29 @@ +/* + * 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/feature/connection/view/AdaptiveConnectionStatusView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AdaptiveConnectionStatusView.kt new file mode 100644 index 0000000..a02ce84 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AdaptiveConnectionStatusView.kt @@ -0,0 +1,85 @@ +/* + * 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.material3.Surface +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 org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP +import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP +import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel + +@Composable +fun AdaptiveConnectionStatusView( + viewModel: ConnectionStatusViewModel, + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, +) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + HorizontalConnectionStatusView(viewModel, modifier) + } else { + VerticalConnectionStatusView(viewModel, modifier) + } +} + +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) +@Composable +private fun AdaptiveConnectionStatusViewPreview_Disconnected() { + val viewModel = ConnectionStatusViewModel() + viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.DISCONNECTED + + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + 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 AdaptiveConnectionStatusViewPreview_Connecting() { + val viewModel = ConnectionStatusViewModel() + viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTING + + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + 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 AdaptiveConnectionStatusViewPreview_Connected() { + val viewModel = ConnectionStatusViewModel() + viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTED + + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + 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 new file mode 100644 index 0000000..8f0c8cf --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/AnimatedLoadingText.kt @@ -0,0 +1,58 @@ +/* + * 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 org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel.ConnectionState +import kotlin.time.Duration.Companion.milliseconds + +private const val MAX_NUMBER_OF_DOTS = 3 +private val DelayDuration = 500.milliseconds + +@Composable +fun animateLoadingText( + connectionState: ConnectionState, + text: String, +): String { + var animatedText = text + if (connectionState == ConnectionState.CONNECTING) { + val numberOfDots = remember { + mutableIntStateOf(0) + } + repeat(numberOfDots.intValue) { + animatedText += "." + } + LaunchedEffect(Unit) { + while (true) { + if (numberOfDots.intValue < MAX_NUMBER_OF_DOTS) { + 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/ConnectionStatusView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/HorizontalConnectionStatusView.kt similarity index 67% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/ConnectionStatusView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/HorizontalConnectionStatusView.kt index 91f3aab..8563762 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/ConnectionStatusView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/HorizontalConnectionStatusView.kt @@ -22,17 +22,11 @@ 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.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.mutableIntStateOf -import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -42,19 +36,15 @@ 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 kotlinx.coroutines.delay +import androidx.constraintlayout.compose.ConstraintLayout import org.eclipse.kuksa.companion.R import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel.ConnectionState -import kotlin.time.Duration.Companion.milliseconds -private const val MAX_NUMBER_OF_DOTS = 3 - -private val StatusBarHeight = 30.dp -private val DelayDuration = 500.milliseconds +val StatusBarHeight = 30.dp @Composable -fun ConnectionStatusView( +fun HorizontalConnectionStatusView( viewModel: ConnectionStatusViewModel, modifier: Modifier = Modifier, ) { @@ -72,26 +62,10 @@ fun ConnectionStatusView( }, ) { var text = connectionStateLabel - if (connectionState == ConnectionState.CONNECTING) { - val numberOfDots = remember { - mutableIntStateOf(0) - } - repeat(numberOfDots.intValue) { - text += "." - } - LaunchedEffect(Unit) { - while (true) { - if (numberOfDots.intValue < MAX_NUMBER_OF_DOTS) { - numberOfDots.intValue += 1 - } else { - numberOfDots.intValue = 0 - } - delay(DelayDuration) - } - } - } + text = animateLoadingText(connectionState = connectionState, text = text) - Box(contentAlignment = Alignment.Center, modifier = Modifier.fillMaxSize()) { + ConstraintLayout(modifier = Modifier.height(StatusBarHeight)) { + val (textRef, imageRef) = createRefs() Text( text, color = Color.White, @@ -99,7 +73,13 @@ fun ConnectionStatusView( fontWeight = FontWeight.Bold, modifier = Modifier .fillMaxWidth() - .wrapContentHeight(), + .constrainAs(textRef) { + top.linkTo(parent.top) + bottom.linkTo(parent.bottom) + + start.linkTo(parent.start) + end.linkTo(imageRef.start) + }, ) if (connectionState == ConnectionState.DISCONNECTED) { @@ -108,7 +88,13 @@ fun ConnectionStatusView( contentDescription = "Reconnect", colorFilter = ColorFilter.tint(Color.White), alignment = Alignment.CenterEnd, - modifier = Modifier.fillMaxSize(), + modifier = Modifier + .constrainAs(imageRef) { + top.linkTo(parent.top) + bottom.linkTo(parent.bottom) + + end.linkTo(parent.end) + }, ) } } @@ -117,25 +103,25 @@ fun ConnectionStatusView( @Preview @Composable -fun ConnectionStatusPreview_Disconnected() { +private fun HorizontalConnectionStatusPreview_Disconnected() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionState.DISCONNECTED - ConnectionStatusView(viewModel = viewModel) + HorizontalConnectionStatusView(viewModel = viewModel) } @Preview @Composable -fun ConnectionStatusPreview_Connecting() { +private fun HorizontalConnectionStatusPreview_Connecting() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionState.CONNECTING - ConnectionStatusView(viewModel = viewModel) + HorizontalConnectionStatusView(viewModel = viewModel) } @Preview @Composable -fun ConnectionStatusPreview_Connected() { +private fun HorizontalConnectionStatusPreview_Connected() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionState.CONNECTED - ConnectionStatusView(viewModel = viewModel) + HorizontalConnectionStatusView(viewModel = viewModel) } 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 new file mode 100644 index 0000000..b08dee4 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalConnectionStatusView.kt @@ -0,0 +1,125 @@ +/* + * 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.width +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.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 + +@Composable +fun VerticalConnectionStatusView( + viewModel: ConnectionStatusViewModel, + modifier: Modifier = Modifier, +) { + val connectionState = viewModel.connectionState + val connectionStateLabel = connectionState.toString().lowercase() + val backgroundColor = viewModel.backgroundColor + + Column( + modifier = modifier + .fillMaxHeight() + .width(StatusBarHeight) + .background(backgroundColor) + .clickable(enabled = connectionState == ConnectionStatusViewModel.ConnectionState.DISCONNECTED) { + viewModel.onClickReconnect() + }, + ) { + var text = connectionStateLabel + text = animateLoadingText(connectionState, text) + + ConstraintLayout(modifier = Modifier.fillMaxSize()) { + val (textRef, imageRef) = createRefs() + + VerticalText( + text, + 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) + } + .isVisible(connectionState == ConnectionStatusViewModel.ConnectionState.DISCONNECTED), + ) + } + } +} + +@Preview(heightDp = 300) +@Composable +private fun VerticalConnectionStatusPreview_Disconnected() { + val viewModel = ConnectionStatusViewModel() + viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.DISCONNECTED + + VerticalConnectionStatusView(viewModel = viewModel) +} + +@Preview(heightDp = 300) +@Composable +private fun VerticalConnectionStatusPreview_Connecting() { + val viewModel = ConnectionStatusViewModel() + viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTING + VerticalConnectionStatusView(viewModel = viewModel) +} + +@Preview(heightDp = 300) +@Composable +private fun VerticalConnectionStatusPreview_Connected() { + val viewModel = ConnectionStatusViewModel() + viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTED + VerticalConnectionStatusView(viewModel = viewModel) +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalText.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalText.kt new file mode 100644 index 0000000..c1f7a3d --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalText.kt @@ -0,0 +1,81 @@ +/* + * 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.material3.LocalTextStyle +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.text.TextLayoutResult +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontStyle +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextDecoration +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.TextUnit + +@Composable +fun VerticalText( + text: String, + modifier: Modifier = Modifier, + color: Color = Color.Unspecified, + fontSize: TextUnit = TextUnit.Unspecified, + fontStyle: FontStyle? = null, + fontWeight: FontWeight? = null, + fontFamily: FontFamily? = null, + letterSpacing: TextUnit = TextUnit.Unspecified, + textDecoration: TextDecoration? = null, + textAlign: TextAlign? = null, + lineHeight: TextUnit = TextUnit.Unspecified, + overflow: TextOverflow = TextOverflow.Clip, + softWrap: Boolean = true, + maxLines: Int = Int.MAX_VALUE, + minLines: Int = 1, + onTextLayout: (TextLayoutResult) -> Unit = {}, + style: TextStyle = LocalTextStyle.current, +) { + val charArray = text.toCharArray() + val verticalTextBuilder = StringBuilder() + charArray.forEach { verticalTextBuilder.append(it).append(System.lineSeparator()) } + val verticalText = verticalTextBuilder.toString() + + Text( + verticalText, + modifier, + color, + fontSize, + fontStyle, + fontWeight, + fontFamily, + letterSpacing, + textDecoration, + textAlign, + lineHeight, + overflow, + softWrap, + maxLines, + minLines, + onTextLayout, + style, + ) +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/surface/DoorVehicleSurface.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/surface/DoorVehicleSurface.kt index 866ecd1..df7b382 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/surface/DoorVehicleSurface.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/surface/DoorVehicleSurface.kt @@ -22,6 +22,7 @@ package org.eclipse.kuksa.companion.feature.door.surface import android.app.Application import android.util.Log import android.view.SurfaceHolder +import org.eclipse.kuksa.companion.R import org.eclipse.kuksa.companion.extension.TAG import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel import org.eclipse.kuksa.companion.ramses.AndroidRamsesSurface @@ -37,10 +38,15 @@ class DoorVehicleSurface : AndroidRamsesSurface + selectedPage = page + } + Box(modifier = Modifier.fillMaxSize()) { + val paddingBottom = resources.getInteger(R.integer.RAMSES_VIEW_PADDING_BOTTOM) + val paddingEnd = resources.getInteger(R.integer.RAMSES_VIEW_PADDING_END) + RamsesView( + callback = callback, + modifier = Modifier + .zIndex(1F) + .fillMaxSize() + .padding(bottom = paddingBottom.dp, end = paddingEnd.dp), // AdaptiveSheetPadding + ) + + val overlayModifier = Modifier + .zIndex(2F) + .fillMaxSize() + .padding(bottom = paddingBottom.dp, end = paddingEnd.dp) // AdaptiveSheetPadding + + val controlModifier = Modifier + .zIndex(2F) + .fillMaxSize() + + when (selectedPage) { + NavigationPage.DOORS -> { + DoorOverlayView(doorControlViewModel, windowSizeClass, overlayModifier) + AdaptiveSheetView(windowSizeClass, controlModifier) { + DoorControlView(doorControlViewModel) + } + } + + NavigationPage.TEMPERATURE -> { + TemperatureOverlayView(temperatureViewModel, windowSizeClass, overlayModifier) + AdaptiveSheetView(windowSizeClass, controlModifier) { + TemperatureControlView(temperatureViewModel) + } + } + + NavigationPage.LIGHT -> { + LightOverlayView(lightControlViewModel, windowSizeClass, overlayModifier) + AdaptiveSheetView(windowSizeClass, controlModifier) { + LightControlView(lightControlViewModel) + } + } + + NavigationPage.WHEELS -> { + WheelPressureOverlayView(wheelPressureViewModel, windowSizeClass, overlayModifier) + AdaptiveSheetView(windowSizeClass) { + WheelPressureOverlayView(wheelPressureViewModel, windowSizeClass) + } + } + + NavigationPage.SETTINGS -> SettingsView(settingsViewModel, overlayModifier) + } + } + } +} + +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) +@Composable +private fun AdaptiveAppScreenPreview() { + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val callback = object : SurfaceHolder.Callback { + override fun surfaceCreated(holder: SurfaceHolder) { + // unused + } + + override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { + // unused + } + + override fun surfaceDestroyed(holder: SurfaceHolder) { + // unused + } + } + + val application = Application() + val context = LocalContext.current + val repository = ConnectionInfoRepository(context) + AdaptiveAppScreen( + callback, + ConnectionStatusViewModel(), + DoorControlViewModel(application), + TemperatureViewModel(), + LightControlViewModel(), + WheelPressureViewModel(), + SettingsViewModel(repository), + windowSizeClass, + ) +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveColumnRow.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveColumnRow.kt new file mode 100644 index 0000000..106d490 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveColumnRow.kt @@ -0,0 +1,48 @@ +/* + * 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.home.view + +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Row +import androidx.compose.material3.windowsizeclass.WindowSizeClass +import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +/** + * Adds an adaptive Column or Row depending on the [WindowWidthSizeClass] of the device. If the device has a + * [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] a Column will be used, otherwise a Row will be used. + */ +@Composable +fun AdaptiveColumnRow( + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, + content: @Composable () -> Unit, +) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + Column(modifier) { + content() + } + } else { + Row(modifier) { + content() + } + } +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowRowColumn.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowRowColumn.kt new file mode 100644 index 0000000..a887ef1 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowRowColumn.kt @@ -0,0 +1,51 @@ +/* + * 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.home.view + +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.FlowColumn +import androidx.compose.foundation.layout.FlowRow +import androidx.compose.material3.windowsizeclass.WindowSizeClass +import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +/** + * Adds an adaptive FlowRow or FlowColumn depending on the [WindowWidthSizeClass] of the device. + * If the device has a [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] a FlowColumn will + * be used, while otherwise a FlowRow will be used. + */ +@OptIn(ExperimentalLayoutApi::class) +@Composable +fun AdaptiveFlowRowColumn( + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, + content: @Composable () -> Unit, +) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + FlowColumn(modifier) { + content() + } + } else { + FlowRow(modifier) { + content() + } + } +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/HomeNavigation.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/HomeNavigation.kt deleted file mode 100644 index 420322f..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/HomeNavigation.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.home.view - -import androidx.navigation.NavController -import androidx.navigation.NavGraphBuilder -import androidx.navigation.NavOptions -import androidx.navigation.compose.composable -import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel -import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel -import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel -import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel -import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel - -const val HOME_SCREEN = "home" - -@Suppress("LongParameterList") // calls compose code for which LongParameterList is disabled -fun NavGraphBuilder.homeScreen( - connectionStatusViewModel: ConnectionStatusViewModel, - doorControlViewModel: DoorControlViewModel, - temperatureViewModel: TemperatureViewModel, - lightControlViewModel: LightControlViewModel, - wheelPressureViewModel: WheelPressureViewModel, - onNavigateToSettingsScreen: () -> Unit, -) { - composable(HOME_SCREEN) { - HomeScreen( - connectionStatusViewModel = connectionStatusViewModel, - doorControlViewModel = doorControlViewModel, - temperatureViewModel = temperatureViewModel, - lightControlViewModel = lightControlViewModel, - wheelPressureViewModel = wheelPressureViewModel, - onNavigateToSettingsScreen = onNavigateToSettingsScreen, - ) - } -} - -fun NavController.navigateToMainScreen(navOptions: NavOptions? = null) { - navigate(HOME_SCREEN, navOptions) -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/HomeScreen.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/HomeScreen.kt deleted file mode 100644 index d683857..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/HomeScreen.kt +++ /dev/null @@ -1,96 +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.home.view - -import android.app.Application -import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.consumeWindowInsets -import androidx.compose.foundation.layout.padding -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Settings -import androidx.compose.material3.FloatingActionButton -import androidx.compose.material3.Scaffold -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.tooling.preview.Preview -import org.eclipse.kuksa.companion.feature.connection.view.ConnectionStatusView -import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel -import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel -import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel -import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel -import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel - -@OptIn(ExperimentalLayoutApi::class) -@Composable -fun HomeScreen( - connectionStatusViewModel: ConnectionStatusViewModel, - doorControlViewModel: DoorControlViewModel, - temperatureViewModel: TemperatureViewModel, - lightControlViewModel: LightControlViewModel, - wheelPressureViewModel: WheelPressureViewModel, - modifier: Modifier = Modifier, - onNavigateToSettingsScreen: () -> Unit, -) { - Scaffold( - containerColor = Color.White.copy(alpha = 0f), - modifier = modifier, - ) { - Column( - modifier = Modifier - .consumeWindowInsets(it) - .padding(it), - ) { - ConnectionStatusView( - viewModel = connectionStatusViewModel, - ) - TabRowHost( - doorControlViewModel = doorControlViewModel, - temperatureViewModel = temperatureViewModel, - lightControlViewModel = lightControlViewModel, - wheelPressureViewModel = wheelPressureViewModel, - ) { - FloatingActionButton( - onClick = { onNavigateToSettingsScreen() }, - ) { - Image( - imageVector = Icons.Filled.Settings, - contentDescription = "Settings", - ) - } - } - } - } -} - -@Preview -@Composable -fun MainScreenPreview() { - HomeScreen( - connectionStatusViewModel = ConnectionStatusViewModel(), - doorControlViewModel = DoorControlViewModel(Application()), - temperatureViewModel = TemperatureViewModel(), - lightControlViewModel = LightControlViewModel(), - wheelPressureViewModel = WheelPressureViewModel(), - onNavigateToSettingsScreen = { }, - ) -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/TabRowHost.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/TabRowHost.kt deleted file mode 100644 index 5db1abb..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/TabRowHost.kt +++ /dev/null @@ -1,141 +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.home.view - -import android.app.Application -import androidx.annotation.DrawableRes -import androidx.compose.foundation.Image -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.offset -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Settings -import androidx.compose.material3.FloatingActionButton -import androidx.compose.material3.Icon -import androidx.compose.material3.Tab -import androidx.compose.material3.TabRow -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableIntStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.res.painterResource -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import org.eclipse.kuksa.companion.R -import org.eclipse.kuksa.companion.feature.door.view.DoorControlView -import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel -import org.eclipse.kuksa.companion.feature.light.view.LightControlView -import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel -import org.eclipse.kuksa.companion.feature.temperature.view.TemperatureControlView -import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel -import org.eclipse.kuksa.companion.feature.wheel.pressure.view.WheelPressureControlView -import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel - -private const val TAB_INDEX_DOORS = 0 -private const val TAB_INDEX_TEMPERATURE = 1 -private const val TAB_INDEX_LIGHT = 2 -private const val TAB_INDEX_WHEEL_PRESSURE = 3 - -private const val FAB_OFFSET_X = -10 -private const val FAB_OFFSET_Y = 10 - -@Composable -fun TabRowHost( - doorControlViewModel: DoorControlViewModel, - temperatureViewModel: TemperatureViewModel, - lightControlViewModel: LightControlViewModel, - wheelPressureViewModel: WheelPressureViewModel, - modifier: Modifier = Modifier, - fabContent: @Composable () -> Unit, -) { - var selectedTabIndex by remember { mutableIntStateOf(TAB_INDEX_DOORS) } - - val tabData = listOf( - TabData(R.drawable.baseline_sensor_door_24, "Doors"), - TabData(R.drawable.baseline_device_thermostat_24, "Temperature"), - TabData(R.drawable.baseline_light_mode_24, "Lights"), - TabData(R.drawable.baseline_sports_volleyball_24, "Wheel Pressure"), - ) - - Column(modifier = modifier) { - TabRow( - selectedTabIndex = selectedTabIndex, - modifier = Modifier - .fillMaxWidth(), - ) { - tabData.forEachIndexed { index, tabData -> - Tab( - selected = selectedTabIndex == index, - onClick = { selectedTabIndex = index }, - modifier = Modifier.height(50.dp), - ) { - Icon( - painter = painterResource(id = tabData.drawableRes), - contentDescription = tabData.description, - ) - } - } - } - - Box { - when (selectedTabIndex) { - TAB_INDEX_DOORS -> DoorControlView(doorControlViewModel) - TAB_INDEX_TEMPERATURE -> TemperatureControlView(temperatureViewModel) - TAB_INDEX_LIGHT -> LightControlView(lightControlViewModel) - TAB_INDEX_WHEEL_PRESSURE -> WheelPressureControlView(wheelPressureViewModel) - } - Column( - modifier = Modifier - .align(Alignment.TopEnd) - .offset(FAB_OFFSET_X.dp, FAB_OFFSET_Y.dp), - ) { - fabContent() - } - } - } -} - -@Preview(showBackground = true) -@Composable -private fun BottomBarPreview() { - TabRowHost( - DoorControlViewModel(Application()), - TemperatureViewModel(), - LightControlViewModel(), - WheelPressureViewModel(), - ) { - FloatingActionButton(onClick = {}) { - Image( - imageVector = Icons.Filled.Settings, - contentDescription = "Settings", - ) - } - } -} - -private data class TabData( - @DrawableRes val drawableRes: Int, - val description: String, -) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt new file mode 100644 index 0000000..7e3e9be --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt @@ -0,0 +1,56 @@ +/* + * 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.home.view.navigation + +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 org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP +import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP +import org.eclipse.kuksa.companion.extension.getWindowSizeClass + +/** + * AdaptiveNavigationView will add depending on the [WindowWidthSizeClass] of the device a horizontal or vertical + * NavigationBar. If the device has a [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] it will use a horizontal + * NavigationBar, while otherwise a Vertical NavigationRail is used. + */ +@Composable +fun AdaptiveNavigationView( + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, + onPageSelected: (NavigationPage) -> Unit = {}, +) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + HorizontalNavigationView(modifier, onPageSelected) + } else { + VerticalNavigationView(modifier, onPageSelected) + } +} + +@Composable +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) +private fun AdaptiveNavigationViewPreview() { + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + AdaptiveNavigationView(windowSizeClass = windowSizeClass) +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt new file mode 100644 index 0000000..3f754ec --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt @@ -0,0 +1,67 @@ +/* + * 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.home.view.navigation + +import androidx.compose.foundation.layout.Column +import androidx.compose.material3.Icon +import androidx.compose.material3.NavigationBar +import androidx.compose.material3.NavigationBarItem +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview + +@Composable +fun HorizontalNavigationView( + modifier: Modifier = Modifier, + onPageSelected: (NavigationPage) -> Unit = {}, +) { + var selectedItemIndex by remember { mutableIntStateOf(0) } + + Column(modifier) { + NavigationBar { + NavigationPage.entries.forEachIndexed { index, page -> + NavigationBarItem( + selected = index == selectedItemIndex, + onClick = { + selectedItemIndex = index + onPageSelected(page) + }, + icon = { + Icon( + painter = painterResource(id = page.iconRes), + contentDescription = page.description, + ) + }, + ) + } + } + } +} + +@Preview(showBackground = true) +@Composable +private fun HorizontalNavigationViewPreview() { + HorizontalNavigationView() +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt new file mode 100644 index 0000000..1b850a1 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt @@ -0,0 +1,55 @@ +/* + * 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.home.view.navigation + +import androidx.annotation.DrawableRes +import org.eclipse.kuksa.companion.R + +enum class NavigationPage( + @DrawableRes val iconRes: Int, + val title: String, + val description: String, +) { + DOORS( + R.drawable.baseline_sensor_door_24, + "Door Control", + "Show status of the doors and trunk, (un-)lock and open/close them", + ), + TEMPERATURE( + R.drawable.baseline_device_thermostat_24, + "Temperature Control", + "Check the temperature inside the car, increase or decrease the temperature. ", + ), + LIGHT( + R.drawable.baseline_light_mode_24, + "Light Control", + "Check the status of the light, turn them on and off to check their functionality", + ), + WHEELS( + R.drawable.baseline_sports_volleyball_24, + "Wheel Pressure", + "Check the pressure of the wheels", + ), + SETTINGS( + R.drawable.baseline_settings_24, + "Settings", + "Settings", + ), +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt new file mode 100644 index 0000000..f3c3223 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt @@ -0,0 +1,65 @@ +/* + * 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.home.view.navigation + +import androidx.compose.foundation.layout.Row +import androidx.compose.material3.Icon +import androidx.compose.material3.NavigationRail +import androidx.compose.material3.NavigationRailItem +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.tooling.preview.Preview + +@Composable +fun VerticalNavigationView( + modifier: Modifier = Modifier, + onPageSelected: (NavigationPage) -> Unit = {}, +) { + var selectedItemIndex by remember { mutableIntStateOf(0) } + val pages = NavigationPage.entries.toTypedArray() + Row(modifier) { + NavigationRail { + pages.forEachIndexed { index, item -> + + NavigationRailItem( + label = { Text(item.title) }, + icon = { Icon(painterResource(id = item.iconRes), contentDescription = item.title) }, + selected = selectedItemIndex == index, + onClick = { + selectedItemIndex = index + onPageSelected(item) + }, + ) + } + } + } +} + +@Preview +@Composable +private fun VerticalNavigationViewPreview() { + VerticalNavigationView() +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt new file mode 100644 index 0000000..c7f1a9b --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt @@ -0,0 +1,110 @@ +/* + * 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.home.view.sheet + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +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.graphics.Color +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.Dp +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.getWindowSizeClass + +/** + * AdaptiveLine draws a line depending on the [WindowWidthSizeClass] of the device. If the device has a + * [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] it will draw a horizontal line, otherwise it will draw a + * horizontal line. + */ +@Composable +fun AdaptiveLine( + modifier: Modifier = Modifier, + length: Dp = 50.dp, + thickness: Dp = 4.dp, + color: Color = Color.LightGray, + windowSizeClass: WindowSizeClass, +) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + HorizontalLine(modifier, length, thickness, color) + } else { + VerticalLine(modifier, length, thickness, color) + } +} + +@Composable +fun HorizontalLine( + modifier: Modifier = Modifier, + length: Dp = 50.dp, + thickness: Dp = 4.dp, + color: Color = Color.LightGray, +) { + Spacer( + modifier = modifier + .background(color) + .width(length) + .height(thickness), + ) +} + +@Composable +fun VerticalLine( + modifier: Modifier = Modifier, + length: Dp = 50.dp, + thickness: Dp = 4.dp, + color: Color = Color.LightGray, +) { + Spacer( + modifier = modifier + .background(color) + .width(thickness) + .height(length), + ) +} + +@Composable +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) +private fun AdaptiveLinePreview() { + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + Box { + AdaptiveLine(windowSizeClass = windowSizeClass) + } +} + +@Composable +@Preview +private fun HorizontalLinePreview() { + HorizontalLine() +} + +@Composable +@Preview +private fun VerticalLinePreview() { + VerticalLine() +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt new file mode 100644 index 0000000..86ecadb --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt @@ -0,0 +1,116 @@ +/* + * 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.home.view.sheet + +import androidx.compose.foundation.background +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.width +import androidx.compose.material3.windowsizeclass.WindowSizeClass +import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.zIndex +import androidx.constraintlayout.compose.ConstrainScope +import androidx.constraintlayout.compose.ConstraintLayout +import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP +import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP +import org.eclipse.kuksa.companion.extension.getWindowSizeClass + +private val WIDTH_EXPANDED = 300.dp +private val WIDTH_NOT_EXPANDED = 50.dp + +/** + * AdaptiveSheetView adds a lash, which can be expanded on click to contain additional content. While it will be placed + * on the bottom for devices with a [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] it will be placed on the + * "end" for devices with a WindowWidthSizeClass which is higher. + */ +@Composable +fun AdaptiveSheetView( + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, + sheetContent: @Composable () -> Unit, +) { + var isExpanded by remember { + mutableStateOf(false) + } + + ConstraintLayout(modifier = modifier.fillMaxSize()) { + val sheetRef = createRef() + + val sheetModifier = when (windowSizeClass.widthSizeClass) { + WindowWidthSizeClass.Compact -> { + Modifier + .height(if (isExpanded) WIDTH_EXPANDED else WIDTH_NOT_EXPANDED) + .fillMaxWidth() + .zIndex(2F) + .clickable { isExpanded = !isExpanded } + .background(Color.White) + .constrainAs(sheetRef) { + bottom.linkTo(parent.bottom) + } + } + + else -> { + Modifier + .fillMaxHeight() + .width(if (isExpanded) WIDTH_EXPANDED else WIDTH_NOT_EXPANDED) + .zIndex(2F) + .clickable { isExpanded = !isExpanded } + .background(Color.White) + .constrainAs(sheetRef) { + end.linkTo(parent.end) + } + } + } + + Box( + modifier = sheetModifier, + ) { + if (isExpanded) { + sheetContent() + } else { + AdaptiveLine(modifier = Modifier.align(Alignment.Center), windowSizeClass = windowSizeClass) + } + } + } +} + +@Composable +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) +private fun AdaptiveSheetViewPreview() { + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + AdaptiveSheetView(windowSizeClass) { + } +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightControlView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightControlView.kt index 7871cbf..44933bc 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightControlView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightControlView.kt @@ -19,65 +19,35 @@ package org.eclipse.kuksa.companion.feature.light.view -import androidx.annotation.DrawableRes -import androidx.compose.foundation.Image import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ExperimentalLayoutApi import androidx.compose.foundation.layout.Row -import androidx.compose.foundation.layout.consumeWindowInsets -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding -import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.width -import androidx.compose.material3.BottomSheetScaffold import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults -import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.runtime.Composable import androidx.compose.ui.Alignment.Companion.CenterHorizontally 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 org.eclipse.kuksa.companion.R import org.eclipse.kuksa.companion.extension.DarkGreen import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel import org.eclipse.kuksa.vsscore.model.VssProperty -@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) @Composable fun LightControlView( viewModel: LightControlViewModel, modifier: Modifier = Modifier, ) { - BottomSheetScaffold( - sheetContent = { BottomSheetContent(viewModel) }, - containerColor = Color.White.copy(alpha = 0f), - modifier = modifier, - ) { - Column( - modifier = Modifier - .fillMaxSize() - .padding(it) - .consumeWindowInsets(paddingValues = it), - ) { - LightOverlay(viewModel) - } - } -} - -@Composable -private fun BottomSheetContent(viewModel: LightControlViewModel) { Column( horizontalAlignment = CenterHorizontally, - modifier = Modifier + modifier = modifier .fillMaxWidth() .padding(top = 10.dp), ) { @@ -156,67 +126,6 @@ private fun LightButton( } } -@Composable -private fun LightDashboardSymbol( - isLightEnabled: Boolean, - @DrawableRes painterResource: Int, - contentDescription: String, -) { - val color = if (isLightEnabled) Color.Green else Color.Red - Image( - painter = painterResource(id = painterResource), - contentDescription = contentDescription, - colorFilter = ColorFilter.tint(color), - modifier = Modifier.size(50.dp), - ) -} - -@Composable -private fun LightOverlay(viewModel: LightControlViewModel) { - Column(modifier = Modifier.padding(10.dp)) { - LightDashboardSymbol( - isLightEnabled = viewModel.isHighBeamLightOn.value, - painterResource = R.drawable.lights_beam_high_24, - contentDescription = "High Beam Lights", - ) - LightDashboardSymbol( - isLightEnabled = viewModel.isLowBeamLightOn.value, - painterResource = R.drawable.lights_beam_low_24, - contentDescription = "Low Beam Lights", - ) - LightDashboardSymbol( - isLightEnabled = viewModel.isDirectionIndicatorSignaling, - painterResource = viewModel.directionIndicatorRes, - contentDescription = "Direction Indicator", - ) - LightDashboardSymbol( - isLightEnabled = viewModel.isFogLightFrontOn.value, - painterResource = R.drawable.lights_fog_front_24, - contentDescription = "Fog Lights Front", - ) - LightDashboardSymbol( - isLightEnabled = viewModel.isFogLightRearOn.value, - painterResource = R.drawable.lights_fog_rear_24, - contentDescription = "Fog Lights Rear", - ) - LightDashboardSymbol( - isLightEnabled = viewModel.isRunningLightOn.value, - painterResource = R.drawable.lights_daylight_running_light_24, - contentDescription = "Running Lights", - ) - LightDashboardSymbol( - isLightEnabled = viewModel.isParkingLightOn.value, - painterResource = R.drawable.lights_parking_24, - contentDescription = "Parking Lights", - ) - LightDashboardSymbol( - isLightEnabled = viewModel.isHazardLightSignalling.value, - painterResource = R.drawable.lights_hazard_24, - contentDescription = "Hazard Lights", - ) - } -} - @Preview @Composable private fun LightControlViewPreview() { @@ -224,11 +133,3 @@ private fun LightControlViewPreview() { LightControlView(LightControlViewModel()) } } - -@Preview -@Composable -private fun BottomSheetPreview() { - Surface { - BottomSheetContent(LightControlViewModel()) - } -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt new file mode 100644 index 0000000..f7380db --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt @@ -0,0 +1,119 @@ +/* + * 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.light.view + +import androidx.annotation.DrawableRes +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material3.Surface +import androidx.compose.material3.windowsizeclass.WindowSizeClass +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.ColorFilter +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.res.painterResource +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.R +import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.feature.home.view.AdaptiveFlowRowColumn +import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel + +@Composable +fun LightOverlayView( + viewModel: LightControlViewModel, + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, +) { + AdaptiveFlowRowColumn(windowSizeClass, modifier = modifier.padding(10.dp)) { + LightDashboardSymbol( + isLightEnabled = viewModel.isHighBeamLightOn.value, + painterResource = R.drawable.lights_beam_high_24, + contentDescription = "High Beam Lights", + ) + LightDashboardSymbol( + isLightEnabled = viewModel.isLowBeamLightOn.value, + painterResource = R.drawable.lights_beam_low_24, + contentDescription = "Low Beam Lights", + ) + LightDashboardSymbol( + isLightEnabled = viewModel.isDirectionIndicatorSignaling, + painterResource = viewModel.directionIndicatorRes, + contentDescription = "Direction Indicator", + ) + LightDashboardSymbol( + isLightEnabled = viewModel.isFogLightFrontOn.value, + painterResource = R.drawable.lights_fog_front_24, + contentDescription = "Fog Lights Front", + ) + LightDashboardSymbol( + isLightEnabled = viewModel.isFogLightRearOn.value, + painterResource = R.drawable.lights_fog_rear_24, + contentDescription = "Fog Lights Rear", + ) + LightDashboardSymbol( + isLightEnabled = viewModel.isRunningLightOn.value, + painterResource = R.drawable.lights_daylight_running_light_24, + contentDescription = "Running Lights", + ) + LightDashboardSymbol( + isLightEnabled = viewModel.isParkingLightOn.value, + painterResource = R.drawable.lights_parking_24, + contentDescription = "Parking Lights", + ) + LightDashboardSymbol( + isLightEnabled = viewModel.isHazardLightSignalling.value, + painterResource = R.drawable.lights_hazard_24, + contentDescription = "Hazard Lights", + ) + } +} + +@Composable +private fun LightDashboardSymbol( + isLightEnabled: Boolean, + @DrawableRes painterResource: Int, + contentDescription: String, +) { + val color = if (isLightEnabled) Color.Green else Color.Red + Image( + painter = painterResource(id = painterResource), + contentDescription = contentDescription, + colorFilter = ColorFilter.tint(color), + modifier = Modifier.size(50.dp), + ) +} + +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) +@Composable +private fun LightControlViewPreview() { + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val viewModel = LightControlViewModel() + Surface { + LightOverlayView(viewModel, windowSizeClass) + } +} + + diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/settings/navigation/SettingsNavigation.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/settings/navigation/SettingsNavigation.kt deleted file mode 100644 index ac98df6..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/settings/navigation/SettingsNavigation.kt +++ /dev/null @@ -1,45 +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.settings.navigation - -import androidx.navigation.NavController -import androidx.navigation.NavGraphBuilder -import androidx.navigation.NavOptions -import androidx.navigation.compose.composable -import org.eclipse.kuksa.companion.feature.settings.view.SettingsView -import org.eclipse.kuksa.companion.feature.settings.viewModel.SettingsViewModel - -const val SETTINGS_VIEW = "settings" - -fun NavGraphBuilder.settingsScreen( - settingsViewModel: SettingsViewModel, - onNavigateBack: () -> Unit, -) { - composable(SETTINGS_VIEW) { - SettingsView( - settingsViewModel = settingsViewModel, - onNavigateBack = onNavigateBack, - ) - } -} - -fun NavController.navigateToSettingsScreen(navOptions: NavOptions? = null) { - navigate(SETTINGS_VIEW, navOptions) -} 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 ae8675f..f4c699f 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 @@ -41,20 +41,13 @@ import androidx.compose.foundation.layout.width import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions -import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.ArrowBack import androidx.compose.material3.Button -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Scaffold import androidx.compose.material3.Surface import androidx.compose.material3.Switch import androidx.compose.material3.Text import androidx.compose.material3.TextField -import androidx.compose.material3.TopAppBar -import androidx.compose.material3.TopAppBarDefaults import androidx.compose.material3.contentColorFor import androidx.compose.runtime.Composable import androidx.compose.runtime.getValue @@ -82,7 +75,6 @@ import org.eclipse.kuksa.companion.feature.settings.viewModel.SettingsViewModel fun SettingsView( settingsViewModel: SettingsViewModel, modifier: Modifier = Modifier, - onNavigateBack: () -> Unit, ) { val connectionInfoState by settingsViewModel.connectionInfoFlow.collectAsStateWithLifecycle(initialValue = ConnectionInfo()) @@ -92,7 +84,6 @@ fun SettingsView( } Scaffold( - topBar = { TopBar(onNavigateBack = onNavigateBack) }, modifier = modifier.fillMaxSize(), ) { paddingValues -> Surface( @@ -338,33 +329,11 @@ private fun FileSelectorSetting( } } -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun TopBar( - modifier: Modifier = Modifier, - onNavigateBack: () -> Unit, -) { - TopAppBar( - title = { Text("Settings") }, - colors = TopAppBarDefaults.mediumTopAppBarColors( - containerColor = MaterialTheme.colorScheme.primaryContainer, - ), - navigationIcon = { - IconButton(onClick = { onNavigateBack() }) { - Icon(Icons.Filled.ArrowBack, "Back") - } - }, - modifier = modifier, - ) -} - @Preview @Composable private fun SettingsViewPreview() { val context = LocalContext.current val repository = ConnectionInfoRepository(context) val settingsViewModel = SettingsViewModel(repository) - SettingsView(settingsViewModel) { - // unused in preview - } + SettingsView(settingsViewModel) } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureControlView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureControlView.kt index d5cddd4..2a13524 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureControlView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureControlView.kt @@ -19,15 +19,7 @@ package org.eclipse.kuksa.companion.feature.temperature.view -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.consumeWindowInsets -import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.BottomSheetScaffold -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Slider import androidx.compose.material3.Surface import androidx.compose.material3.Text @@ -37,7 +29,6 @@ import androidx.compose.runtime.mutableFloatStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.constraintlayout.compose.ConstraintLayout @@ -47,36 +38,17 @@ import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureView private val DefaultElementPadding = 10.dp private val DefaultEdgePadding = 25.dp -@OptIn(ExperimentalMaterial3Api::class, ExperimentalLayoutApi::class) @Composable fun TemperatureControlView( viewModel: TemperatureViewModel, modifier: Modifier = Modifier, ) { - BottomSheetScaffold( - sheetContent = { BottomSheetContent(viewModel) }, - containerColor = Color.White.copy(alpha = 0f), - modifier = modifier, - ) { - Column( - modifier = Modifier - .fillMaxSize() - .padding(it) - .consumeWindowInsets(paddingValues = it), - ) { - TemperatureOverlay(viewModel = viewModel) - } - } -} - -@Composable -private fun BottomSheetContent(viewModel: TemperatureViewModel) { var plannedTemperature by remember { val temperature = viewModel.hvac.station.row1.driver.temperature mutableFloatStateOf(temperature.value.toFloat()) } - ConstraintLayout(modifier = Modifier.fillMaxWidth()) { + ConstraintLayout(modifier = modifier.fillMaxWidth()) { val (minTemperatureRef, temperatureSliderRef, maxTemperatureRef) = createRefs() val (plannedTempRef, currentTemperatureRef) = createRefs() @@ -144,76 +116,11 @@ private fun BottomSheetContent(viewModel: TemperatureViewModel) { } } -@Composable -private fun TemperatureOverlay(viewModel: TemperatureViewModel) { - ConstraintLayout( - modifier = Modifier - .fillMaxSize() - .padding(start = 60.dp, end = 60.dp, top = 300.dp, bottom = 80.dp), - ) { - val (driverSideRef, passengerSideRef, driverSideBackRef, passengerSideBackRef) = createRefs() - val modifier = Modifier - val doorsPaddingBottom = 50.dp - - val temperatureDriverSideFront = viewModel.temperatureDriverSideFront - val temperaturePassengerSideFront = viewModel.temperaturePassengerSideFront - val temperatureDriverSideBack = viewModel.temperatureDriverSideBack - val temperaturePassengerSideBack = viewModel.temperaturePassengerSideBack - - val unit = "°C" - Text( - text = "$temperatureDriverSideFront $unit", - fontSize = MaterialTheme.typography.titleLarge.fontSize, - color = viewModel.getTemperatureColor(temperatureDriverSideFront), - modifier = modifier - .constrainAs(driverSideRef) { - start.linkTo(parent.start) - }, - ) - Text( - text = "$temperaturePassengerSideFront $unit", - fontSize = MaterialTheme.typography.titleLarge.fontSize, - color = viewModel.getTemperatureColor(temperaturePassengerSideFront), - modifier = modifier - .constrainAs(passengerSideRef) { - end.linkTo(parent.end) - }, - ) - Text( - text = "$temperatureDriverSideBack $unit", - fontSize = MaterialTheme.typography.titleLarge.fontSize, - color = viewModel.getTemperatureColor(temperatureDriverSideBack), - modifier = modifier - .constrainAs(driverSideBackRef) { - start.linkTo(parent.start) - bottom.linkTo(parent.bottom, doorsPaddingBottom) - }, - ) - Text( - text = "$temperaturePassengerSideBack $unit", - fontSize = MaterialTheme.typography.titleLarge.fontSize, - color = viewModel.getTemperatureColor(temperaturePassengerSideBack), - modifier = modifier - .constrainAs(passengerSideBackRef) { - end.linkTo(parent.end) - bottom.linkTo(parent.bottom, doorsPaddingBottom) - }, - ) - } -} - -@Preview -@Composable -private fun TemperatureControlPreview() { - Surface { - TemperatureControlView(TemperatureViewModel()) - } -} - @Preview @Composable -private fun BottomSheetContentPreview() { +private fun TemperatureControlViewPreview() { + val viewModel = TemperatureViewModel() Surface { - BottomSheetContent(TemperatureViewModel()) + TemperatureControlView(viewModel) } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt new file mode 100644 index 0000000..1d953f7 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt @@ -0,0 +1,128 @@ +/* + * 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.temperature.view + +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +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.graphics.Color +import androidx.compose.ui.platform.LocalConfiguration +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.constraintlayout.compose.ConstraintLayout +import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP +import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP +import org.eclipse.kuksa.companion.extension.alignDriverBackDoor +import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor +import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor +import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor +import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.feature.door.view.horizontalMarginAnchorToDoor +import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToBackDoor +import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToDoor +import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel + +@Composable +fun TemperatureOverlayView( + viewModel: TemperatureViewModel, + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, +) { + ConstraintLayout( + modifier = modifier + .fillMaxSize(), + ) { + val (driverSideRef, passengerSideRef, driverSideBackRef, passengerSideBackRef) = createRefs() + + val temperatureDriverSideFront = viewModel.temperatureDriverSideFront + val temperaturePassengerSideFront = viewModel.temperaturePassengerSideFront + val temperatureDriverSideBack = viewModel.temperatureDriverSideBack + val temperaturePassengerSideBack = viewModel.temperaturePassengerSideBack + + val anchorPoint = createRef() + Spacer( + Modifier + .size(2.dp) + .background(Color.White) + .constrainAs(anchorPoint) { + centerHorizontallyTo(parent) + centerVerticallyTo(parent) + }, + ) + + val unit = "°C" + Text( + text = "$temperatureDriverSideFront $unit", + fontSize = MaterialTheme.typography.titleLarge.fontSize, + color = viewModel.getTemperatureColor(temperatureDriverSideFront), + modifier = Modifier + .constrainAs(driverSideRef) { + alignDriverFrontDoor(windowSizeClass, anchorPoint) + }, + ) + Text( + text = "$temperaturePassengerSideFront $unit", + fontSize = MaterialTheme.typography.titleLarge.fontSize, + color = viewModel.getTemperatureColor(temperaturePassengerSideFront), + modifier = Modifier + .constrainAs(passengerSideRef) { + alignPassengerFrontDoor(windowSizeClass, anchorPoint) + }, + ) + Text( + text = "$temperatureDriverSideBack $unit", + fontSize = MaterialTheme.typography.titleLarge.fontSize, + color = viewModel.getTemperatureColor(temperatureDriverSideBack), + modifier = Modifier + .constrainAs(driverSideBackRef) { + alignDriverBackDoor(windowSizeClass, anchorPoint) + }, + ) + Text( + text = "$temperaturePassengerSideBack $unit", + fontSize = MaterialTheme.typography.titleLarge.fontSize, + color = viewModel.getTemperatureColor(temperaturePassengerSideBack), + modifier = Modifier + .constrainAs(passengerSideBackRef) { + alignPassengerBackDoor(windowSizeClass, anchorPoint) + }, + ) + } +} + +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) +@Composable +private fun TemperatureControlPreview() { + val viewModel = TemperatureViewModel() + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + Surface { + TemperatureOverlayView(viewModel, windowSizeClass) + } +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureControlView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt similarity index 57% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureControlView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt index 8eb8ccd..c51c569 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureControlView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt @@ -19,48 +19,80 @@ package org.eclipse.kuksa.companion.feature.wheel.pressure.view +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text +import androidx.compose.material3.windowsizeclass.WindowSizeClass +import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.runtime.Composable +import androidx.compose.runtime.Stable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color +import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import androidx.constraintlayout.compose.ConstrainScope +import androidx.constraintlayout.compose.ConstrainedLayoutReference import androidx.constraintlayout.compose.ConstraintLayout +import androidx.constraintlayout.compose.ConstraintLayoutScope +import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP +import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP +import org.eclipse.kuksa.companion.extension.alignDriverBackDoor +import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor +import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor +import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor +import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.feature.door.view.horizontalMarginAnchorToDoor +import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToBackDoor +import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToDoor import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel @Composable -fun WheelPressureControlView( +fun WheelPressureOverlayView( viewModel: WheelPressureViewModel, + windowSizeClass: WindowSizeClass, modifier: Modifier = Modifier, ) { - WheelPressureOverlay( + WheelPressureOverlayView( viewModel.pressureLeftFront, viewModel.pressureRightFront, viewModel.pressureLeftBack, viewModel.pressureRightBack, + windowSizeClass, modifier, ) } @Composable -private fun WheelPressureOverlay( +private fun WheelPressureOverlayView( pressureLeftFront: Int, pressureRightFront: Int, pressureLeftBack: Int, pressureRightBack: Int, + windowSizeClass: WindowSizeClass, modifier: Modifier = Modifier, ) { ConstraintLayout( modifier = modifier .fillMaxSize() - .padding(start = 35.dp, end = 35.dp, top = 225.dp, bottom = 90.dp), ) { val (driverSideRef, passengerSideRef, driverSideBackRef, passengerSideBackRef) = createRefs() - val doorsPaddingBottom = 50.dp + + val anchorPoint = createRef() + Spacer( + Modifier + .size(2.dp) + .background(Color.White) + .constrainAs(anchorPoint) { + centerHorizontallyTo(parent) + centerVerticallyTo(parent) + }, + ) val unit = "kPa" Text( @@ -69,7 +101,7 @@ private fun WheelPressureOverlay( color = Color.Black, modifier = Modifier .constrainAs(driverSideRef) { - start.linkTo(parent.start) + alignDriverFrontDoor(windowSizeClass, anchorPoint) }, ) Text( @@ -78,7 +110,7 @@ private fun WheelPressureOverlay( color = Color.Black, modifier = Modifier .constrainAs(passengerSideRef) { - end.linkTo(parent.end) + alignPassengerFrontDoor(windowSizeClass, anchorPoint) }, ) Text( @@ -87,8 +119,7 @@ private fun WheelPressureOverlay( color = Color.Black, modifier = Modifier .constrainAs(driverSideBackRef) { - start.linkTo(parent.start) - bottom.linkTo(parent.bottom, doorsPaddingBottom) + alignDriverBackDoor(windowSizeClass, anchorPoint) }, ) Text( @@ -97,17 +128,19 @@ private fun WheelPressureOverlay( color = Color.Black, modifier = Modifier .constrainAs(passengerSideBackRef) { - end.linkTo(parent.end) - bottom.linkTo(parent.bottom, doorsPaddingBottom) + alignPassengerBackDoor(windowSizeClass, anchorPoint) }, ) } } -@Preview +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) @Composable private fun WheelPressureControlViewPreview() { + val viewModel = WheelPressureViewModel() + val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() Surface { - WheelPressureControlView(WheelPressureViewModel()) + WheelPressureOverlayView(viewModel, windowSizeClass) } } diff --git a/app/src/main/res/drawable/baseline_settings_24.xml b/app/src/main/res/drawable/baseline_settings_24.xml new file mode 100644 index 0000000..298a5a1 --- /dev/null +++ b/app/src/main/res/drawable/baseline_settings_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/values-land/values.xml b/app/src/main/res/values-land/values.xml new file mode 100644 index 0000000..e5b873a --- /dev/null +++ b/app/src/main/res/values-land/values.xml @@ -0,0 +1,27 @@ + + + + 180 + 100 + 1000 + + 50 + 0 + diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml new file mode 100644 index 0000000..cbc6cd1 --- /dev/null +++ b/app/src/main/res/values/values.xml @@ -0,0 +1,27 @@ + + + + 90 + 100 + 700 + + 0 + 50 + From c78243510119c6f96c3cb56c1b23787c68edfffe Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 1 Feb 2024 13:51:30 +0100 Subject: [PATCH 02/28] chore: Fix Lint Issues --- .../kuksa/companion/CompanionApplication.kt | 3 +++ .../extension/ConstraintScopeExtension.kt | 26 ++++++++++++++----- .../view/AdaptiveConnectionStatusView.kt | 1 - .../feature/door/view/DoorControlView.kt | 6 ++--- .../feature/door/view/DoorOverlayView.kt | 11 ++++---- .../feature/home/view/AdaptiveAppScreen.kt | 18 +++++++++---- .../feature/home/view/sheet/AdaptiveLine.kt | 2 +- .../home/view/sheet/AdaptiveSheetLayout.kt | 10 +++---- .../feature/light/view/LightOverlayView.kt | 2 -- .../view/TemperatureOverlayView.kt | 8 ------ .../pressure/view/WheelPressureOverlayView.kt | 23 +++++----------- 11 files changed, 55 insertions(+), 55 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt index ffee8d1..df31733 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt @@ -25,5 +25,8 @@ import dagger.hilt.android.HiltAndroidApp const val PREVIEW_WIDTH_DP = 400 const val PREVIEW_HEIGHT_DP = 900 +const val SHEET_EXPANDED_HEIGHT = 300 +const val SHEET_COLLAPSED_HEIGHT = 50 + @HiltAndroidApp class CompanionApplication : Application() diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt index 69352cd..c0fdd06 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt @@ -27,7 +27,10 @@ import org.eclipse.kuksa.companion.feature.door.view.horizontalMarginAnchorToDoo import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToBackDoor import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToDoor -fun ConstrainScope.alignDriverFrontDoor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { +fun ConstrainScope.alignDriverFrontDoor( + windowSizeClass: WindowSizeClass, + anchorPoint: ConstrainedLayoutReference, +) { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { end.linkTo(anchorPoint.start, horizontalMarginAnchorToDoor) top.linkTo(anchorPoint.bottom, verticalMarginAnchorToDoor) @@ -37,7 +40,10 @@ fun ConstrainScope.alignDriverFrontDoor(windowSizeClass: WindowSizeClass, anchor } } -fun ConstrainScope.alignPassengerFrontDoor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { +fun ConstrainScope.alignPassengerFrontDoor( + windowSizeClass: WindowSizeClass, + anchorPoint: ConstrainedLayoutReference, +) { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { start.linkTo(anchorPoint.end, horizontalMarginAnchorToDoor) top.linkTo(anchorPoint.bottom, verticalMarginAnchorToDoor) @@ -47,8 +53,10 @@ fun ConstrainScope.alignPassengerFrontDoor(windowSizeClass: WindowSizeClass, anc } } - -fun ConstrainScope.alignDriverBackDoor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { +fun ConstrainScope.alignDriverBackDoor( + windowSizeClass: WindowSizeClass, + anchorPoint: ConstrainedLayoutReference, +) { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { end.linkTo(anchorPoint.start, horizontalMarginAnchorToDoor) top.linkTo(anchorPoint.bottom, verticalMarginAnchorToBackDoor) @@ -58,7 +66,10 @@ fun ConstrainScope.alignDriverBackDoor(windowSizeClass: WindowSizeClass, anchorP } } -fun ConstrainScope.alignPassengerBackDoor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { +fun ConstrainScope.alignPassengerBackDoor( + windowSizeClass: WindowSizeClass, + anchorPoint: ConstrainedLayoutReference, +) { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { start.linkTo(anchorPoint.end, horizontalMarginAnchorToDoor) top.linkTo(anchorPoint.bottom, verticalMarginAnchorToBackDoor) @@ -68,7 +79,10 @@ fun ConstrainScope.alignPassengerBackDoor(windowSizeClass: WindowSizeClass, anch } } -fun ConstrainScope.alignTrunk(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) { +fun ConstrainScope.alignTrunk( + windowSizeClass: WindowSizeClass, + anchorPoint: ConstrainedLayoutReference, +) { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { centerHorizontallyTo(anchorPoint) bottom.linkTo(parent.bottom) 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 index a02ce84..990046a 100644 --- 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 @@ -20,7 +20,6 @@ package org.eclipse.kuksa.companion.feature.connection.view import androidx.compose.foundation.layout.Box -import androidx.compose.material3.Surface import androidx.compose.material3.windowsizeclass.WindowSizeClass import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.runtime.Composable diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorControlView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorControlView.kt index 7d1a5d5..4c3999e 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorControlView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorControlView.kt @@ -34,8 +34,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.text.font.FontWeight 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.SHEET_EXPANDED_HEIGHT import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel @Composable @@ -101,8 +101,8 @@ fun DoorControlView( } } -@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = 300) -@Preview(widthDp = 300, heightDp = PREVIEW_WIDTH_DP) +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = SHEET_EXPANDED_HEIGHT) +@Preview(widthDp = SHEET_EXPANDED_HEIGHT, heightDp = PREVIEW_WIDTH_DP) @Composable private fun BottomSheetContentPreview() { val application = Application() diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt index dc01835..bcda5d5 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt @@ -21,7 +21,6 @@ package org.eclipse.kuksa.companion.feature.door.view import android.app.Application 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.Spacer @@ -29,16 +28,13 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.size import androidx.compose.material3.Surface 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.graphics.Color import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.constraintlayout.compose.ConstraintLayout -import org.eclipse.kuksa.companion.CompanionApplication import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP import org.eclipse.kuksa.companion.extension.alignDriverBackDoor @@ -54,7 +50,11 @@ val verticalMarginAnchorToDoor = 10.dp val verticalMarginAnchorToBackDoor = 100.dp @Composable -fun DoorOverlayView(viewModel: DoorControlViewModel, windowSizeClass: WindowSizeClass, modifier: Modifier = Modifier) { +fun DoorOverlayView( + viewModel: DoorControlViewModel, + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, +) { ConstraintLayout( modifier = modifier.fillMaxSize(), ) { @@ -70,7 +70,6 @@ fun DoorOverlayView(viewModel: DoorControlViewModel, windowSizeClass: WindowSize Spacer( Modifier .size(2.dp) - .background(Color.White) .constrainAs(anchorPoint) { centerHorizontallyTo(parent) centerVerticallyTo(parent) 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 764c73c..0fa0f0a 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 @@ -47,8 +47,8 @@ import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatus 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 -import org.eclipse.kuksa.companion.feature.home.view.navigation.NavigationPage import org.eclipse.kuksa.companion.feature.home.view.navigation.AdaptiveNavigationView +import org.eclipse.kuksa.companion.feature.home.view.navigation.NavigationPage import org.eclipse.kuksa.companion.feature.home.view.sheet.AdaptiveSheetView import org.eclipse.kuksa.companion.feature.light.view.LightControlView import org.eclipse.kuksa.companion.feature.light.view.LightOverlayView @@ -76,12 +76,13 @@ fun AdaptiveAppScreen( wheelPressureViewModel: WheelPressureViewModel, settingsViewModel: SettingsViewModel, windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, ) { var selectedPage: NavigationPage by remember { mutableStateOf(NavigationPage.DOORS) } - AdaptiveColumnRow(windowSizeClass = windowSizeClass, modifier = Modifier.fillMaxSize()) { + AdaptiveColumnRow(windowSizeClass = windowSizeClass, modifier = modifier.fillMaxSize()) { val context = LocalContext.current val resources = context.resources @@ -97,13 +98,15 @@ fun AdaptiveAppScreen( modifier = Modifier .zIndex(1F) .fillMaxSize() - .padding(bottom = paddingBottom.dp, end = paddingEnd.dp), // AdaptiveSheetPadding + // AdaptiveSheetPadding + .padding(bottom = paddingBottom.dp, end = paddingEnd.dp), ) val overlayModifier = Modifier .zIndex(2F) .fillMaxSize() - .padding(bottom = paddingBottom.dp, end = paddingEnd.dp) // AdaptiveSheetPadding + // AdaptiveSheetPadding + .padding(bottom = paddingBottom.dp, end = paddingEnd.dp) val controlModifier = Modifier .zIndex(2F) @@ -154,7 +157,12 @@ private fun AdaptiveAppScreenPreview() { // unused } - override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { + override fun surfaceChanged( + holder: SurfaceHolder, + format: Int, + width: Int, + height: Int, + ) { // unused } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt index c7f1a9b..565c0e2 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt @@ -44,11 +44,11 @@ import org.eclipse.kuksa.companion.extension.getWindowSizeClass */ @Composable fun AdaptiveLine( + windowSizeClass: WindowSizeClass, modifier: Modifier = Modifier, length: Dp = 50.dp, thickness: Dp = 4.dp, color: Color = Color.LightGray, - windowSizeClass: WindowSizeClass, ) { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { HorizontalLine(modifier, length, thickness, color) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt index 86ecadb..439f9b3 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt @@ -41,15 +41,13 @@ import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp import androidx.compose.ui.zIndex -import androidx.constraintlayout.compose.ConstrainScope import androidx.constraintlayout.compose.ConstraintLayout import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP +import org.eclipse.kuksa.companion.SHEET_COLLAPSED_HEIGHT +import org.eclipse.kuksa.companion.SHEET_EXPANDED_HEIGHT import org.eclipse.kuksa.companion.extension.getWindowSizeClass -private val WIDTH_EXPANDED = 300.dp -private val WIDTH_NOT_EXPANDED = 50.dp - /** * AdaptiveSheetView adds a lash, which can be expanded on click to contain additional content. While it will be placed * on the bottom for devices with a [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] it will be placed on the @@ -71,7 +69,7 @@ fun AdaptiveSheetView( val sheetModifier = when (windowSizeClass.widthSizeClass) { WindowWidthSizeClass.Compact -> { Modifier - .height(if (isExpanded) WIDTH_EXPANDED else WIDTH_NOT_EXPANDED) + .height(if (isExpanded) SHEET_EXPANDED_HEIGHT.dp else SHEET_COLLAPSED_HEIGHT.dp) .fillMaxWidth() .zIndex(2F) .clickable { isExpanded = !isExpanded } @@ -84,7 +82,7 @@ fun AdaptiveSheetView( else -> { Modifier .fillMaxHeight() - .width(if (isExpanded) WIDTH_EXPANDED else WIDTH_NOT_EXPANDED) + .width(if (isExpanded) SHEET_EXPANDED_HEIGHT.dp else SHEET_COLLAPSED_HEIGHT.dp) .zIndex(2F) .clickable { isExpanded = !isExpanded } .background(Color.White) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt index f7380db..172b30b 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt @@ -115,5 +115,3 @@ private fun LightControlViewPreview() { LightOverlayView(viewModel, windowSizeClass) } } - - diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt index 1d953f7..a631070 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt @@ -19,19 +19,15 @@ package org.eclipse.kuksa.companion.feature.temperature.view -import androidx.compose.foundation.background import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text 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.graphics.Color import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp @@ -43,9 +39,6 @@ import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor import org.eclipse.kuksa.companion.extension.getWindowSizeClass -import org.eclipse.kuksa.companion.feature.door.view.horizontalMarginAnchorToDoor -import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToBackDoor -import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToDoor import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel @Composable @@ -69,7 +62,6 @@ fun TemperatureOverlayView( Spacer( Modifier .size(2.dp) - .background(Color.White) .constrainAs(anchorPoint) { centerHorizontallyTo(parent) centerVerticallyTo(parent) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt index c51c569..6eb09c7 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt @@ -19,27 +19,20 @@ package org.eclipse.kuksa.companion.feature.wheel.pressure.view -import androidx.compose.foundation.background import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.size import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.material3.Text import androidx.compose.material3.windowsizeclass.WindowSizeClass -import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.runtime.Composable -import androidx.compose.runtime.Stable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp -import androidx.constraintlayout.compose.ConstrainScope -import androidx.constraintlayout.compose.ConstrainedLayoutReference import androidx.constraintlayout.compose.ConstraintLayout -import androidx.constraintlayout.compose.ConstraintLayoutScope import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP import org.eclipse.kuksa.companion.extension.alignDriverBackDoor @@ -47,9 +40,6 @@ import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor import org.eclipse.kuksa.companion.extension.getWindowSizeClass -import org.eclipse.kuksa.companion.feature.door.view.horizontalMarginAnchorToDoor -import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToBackDoor -import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToDoor import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel @Composable @@ -79,7 +69,7 @@ private fun WheelPressureOverlayView( ) { ConstraintLayout( modifier = modifier - .fillMaxSize() + .fillMaxSize(), ) { val (driverSideRef, passengerSideRef, driverSideBackRef, passengerSideBackRef) = createRefs() @@ -87,7 +77,6 @@ private fun WheelPressureOverlayView( Spacer( Modifier .size(2.dp) - .background(Color.White) .constrainAs(anchorPoint) { centerHorizontallyTo(parent) centerVerticallyTo(parent) @@ -98,7 +87,7 @@ private fun WheelPressureOverlayView( Text( text = "$pressureLeftFront $unit", fontSize = MaterialTheme.typography.titleLarge.fontSize, - color = Color.Black, + color = Color.White, modifier = Modifier .constrainAs(driverSideRef) { alignDriverFrontDoor(windowSizeClass, anchorPoint) @@ -107,7 +96,7 @@ private fun WheelPressureOverlayView( Text( text = "$pressureRightFront $unit", fontSize = MaterialTheme.typography.titleLarge.fontSize, - color = Color.Black, + color = Color.White, modifier = Modifier .constrainAs(passengerSideRef) { alignPassengerFrontDoor(windowSizeClass, anchorPoint) @@ -116,7 +105,7 @@ private fun WheelPressureOverlayView( Text( text = "$pressureLeftBack $unit", fontSize = MaterialTheme.typography.titleLarge.fontSize, - color = Color.Black, + color = Color.White, modifier = Modifier .constrainAs(driverSideBackRef) { alignDriverBackDoor(windowSizeClass, anchorPoint) @@ -125,7 +114,7 @@ private fun WheelPressureOverlayView( Text( text = "$pressureRightBack $unit", fontSize = MaterialTheme.typography.titleLarge.fontSize, - color = Color.Black, + color = Color.White, modifier = Modifier .constrainAs(passengerSideBackRef) { alignPassengerBackDoor(windowSizeClass, anchorPoint) @@ -134,7 +123,7 @@ private fun WheelPressureOverlayView( } } -@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP, showBackground = true) @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) @Composable private fun WheelPressureControlViewPreview() { From 2c96f1f73d194f69c39983a6171257a45370c30e Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 1 Feb 2024 13:57:48 +0100 Subject: [PATCH 03/28] chore: Move Library into .toml --- app/build.gradle.kts | 2 +- gradle/libs.versions.toml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 57ba2a9..01feabe 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -143,7 +143,7 @@ dependencies { implementation(libs.hilt.android) kapt(libs.hilt.android.compiler) - implementation("androidx.compose.material3:material3-window-size-class:1.1.2") + implementation(libs.androidx.material3.window.size.clazz) } // Allow references to generated code diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 519c9bb..ef9bb04 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,6 +19,7 @@ composeBom = "2023.10.01" jvmTarget = "17" kuksaSdk = "0.1.3" lifecycleRuntimeCompose = "2.7.0" +material3WindowSizeClass = "1.1.2" ramsesAar = "1.1.0" navigationCompose = "2.7.6" kotlinxSerializationJson = "1.6.1" @@ -32,6 +33,7 @@ androidx-datastore = { module = "androidx.datastore:datastore", version.ref = "d androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "espressoCore" } androidx-junit = { module = "androidx.test.ext:junit", version.ref = "junitVersion" } androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version.ref = "lifecycleRuntimeCompose" } +androidx-material3-window-size-clazz = { module = "androidx.compose.material3:material3-window-size-class", version.ref = "material3WindowSizeClass" } hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hiltAndroid" } hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hiltAndroid" } javapoet = { module = "com.squareup:javapoet", version.ref = "javapoet" } From e1755610e82ece82036f806937b9f497ae09879a Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 1 Feb 2024 13:58:06 +0100 Subject: [PATCH 04/28] chore: Fix z-indexes of Views --- .../companion/feature/home/view/AdaptiveAppScreen.kt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 0fa0f0a..0ee5170 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 @@ -61,6 +61,10 @@ 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_RAMSES_VIEW = 1F +private const val ZINDEX_OVERLAY = 2F +private const val ZINDEX_CONTROL = 3F + /** * Adds an adaptive AppScreen depending on the [WindowWidthSizeClass]. When the device has a [WindowWidthSizeClass] of * [WindowWidthSizeClass.Compact] all elements are placed on top of each other, while for devices with a higher class @@ -96,20 +100,20 @@ fun AdaptiveAppScreen( RamsesView( callback = callback, modifier = Modifier - .zIndex(1F) + .zIndex(ZINDEX_RAMSES_VIEW) .fillMaxSize() // AdaptiveSheetPadding .padding(bottom = paddingBottom.dp, end = paddingEnd.dp), ) val overlayModifier = Modifier - .zIndex(2F) + .zIndex(ZINDEX_OVERLAY) .fillMaxSize() // AdaptiveSheetPadding .padding(bottom = paddingBottom.dp, end = paddingEnd.dp) val controlModifier = Modifier - .zIndex(2F) + .zIndex(ZINDEX_CONTROL) .fillMaxSize() when (selectedPage) { From 8c0796b715489f003b1f98f050ee456ba6c63ab1 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Tue, 6 Feb 2024 07:08:50 +0100 Subject: [PATCH 05/28] chore: Change ConfigurationExtension from fun to val --- .../companion/extension/ConfigurationExtension.kt | 15 +++++++-------- .../view/AdaptiveConnectionStatusView.kt | 8 ++++---- .../feature/door/view/DoorOverlayView.kt | 4 ++-- .../feature/home/view/AdaptiveAppScreen.kt | 4 ++-- .../view/navigation/AdaptiveNavigationView.kt | 4 ++-- .../feature/home/view/sheet/AdaptiveLine.kt | 4 ++-- .../home/view/sheet/AdaptiveSheetLayout.kt | 4 ++-- .../feature/light/view/LightOverlayView.kt | 4 ++-- .../temperature/view/TemperatureOverlayView.kt | 4 ++-- .../pressure/view/WheelPressureOverlayView.kt | 4 ++-- 10 files changed, 27 insertions(+), 28 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConfigurationExtension.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConfigurationExtension.kt index 1808d5f..07b1293 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConfigurationExtension.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConfigurationExtension.kt @@ -22,15 +22,14 @@ package org.eclipse.kuksa.companion.extension import android.content.res.Configuration import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi import androidx.compose.material3.windowsizeclass.WindowSizeClass -import androidx.compose.runtime.Composable import androidx.compose.ui.unit.DpSize import androidx.compose.ui.unit.dp @OptIn(ExperimentalMaterial3WindowSizeClassApi::class) -@Composable -fun Configuration.getWindowSizeClass(): WindowSizeClass { - val screenWidth = screenWidthDp - val screenHeight = screenHeightDp - val size = DpSize(screenWidth.dp, screenHeight.dp) - return WindowSizeClass.calculateFromSize(size) -} +val Configuration.windowSizeClass: WindowSizeClass + get() { + val screenWidth = screenWidthDp + val screenHeight = screenHeightDp + val size = DpSize(screenWidth.dp, screenHeight.dp) + return WindowSizeClass.calculateFromSize(size) + } 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 index 990046a..a65918c 100644 --- 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 @@ -28,7 +28,7 @@ import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.tooling.preview.Preview import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP -import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.extension.windowSizeClass import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel @Composable @@ -51,7 +51,7 @@ private fun AdaptiveConnectionStatusViewPreview_Disconnected() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.DISCONNECTED - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass Box { AdaptiveConnectionStatusView(viewModel = viewModel, windowSizeClass) } @@ -64,7 +64,7 @@ private fun AdaptiveConnectionStatusViewPreview_Connecting() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTING - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass Box { AdaptiveConnectionStatusView(viewModel = viewModel, windowSizeClass) } @@ -77,7 +77,7 @@ private fun AdaptiveConnectionStatusViewPreview_Connected() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTED - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass Box { AdaptiveConnectionStatusView(viewModel = viewModel, windowSizeClass) } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt index bcda5d5..4f4b798 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt @@ -42,7 +42,7 @@ import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor import org.eclipse.kuksa.companion.extension.alignTrunk -import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.extension.windowSizeClass import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel val horizontalMarginAnchorToDoor = 75.dp @@ -159,7 +159,7 @@ fun DoorOverlayView( @Composable private fun DoorOverlayPreview() { val viewModel = DoorControlViewModel(Application()) - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass Surface { DoorOverlayView(viewModel, windowSizeClass) } 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 0ee5170..9436f8a 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 @@ -40,7 +40,7 @@ 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.R -import org.eclipse.kuksa.companion.extension.getWindowSizeClass +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.viewModel.ConnectionStatusViewModel @@ -155,7 +155,7 @@ fun AdaptiveAppScreen( @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) @Composable private fun AdaptiveAppScreenPreview() { - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass val callback = object : SurfaceHolder.Callback { override fun surfaceCreated(holder: SurfaceHolder) { // unused diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt index 7e3e9be..6d0a1df 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt @@ -27,7 +27,7 @@ import androidx.compose.ui.platform.LocalConfiguration import androidx.compose.ui.tooling.preview.Preview import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP -import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.extension.windowSizeClass /** * AdaptiveNavigationView will add depending on the [WindowWidthSizeClass] of the device a horizontal or vertical @@ -51,6 +51,6 @@ fun AdaptiveNavigationView( @Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) private fun AdaptiveNavigationViewPreview() { - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass AdaptiveNavigationView(windowSizeClass = windowSizeClass) } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt index 565c0e2..3f49e93 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt @@ -35,7 +35,7 @@ import androidx.compose.ui.unit.Dp 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.getWindowSizeClass +import org.eclipse.kuksa.companion.extension.windowSizeClass /** * AdaptiveLine draws a line depending on the [WindowWidthSizeClass] of the device. If the device has a @@ -91,7 +91,7 @@ fun VerticalLine( @Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) private fun AdaptiveLinePreview() { - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass Box { AdaptiveLine(windowSizeClass = windowSizeClass) } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt index 439f9b3..f7c1cd7 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt @@ -46,7 +46,7 @@ import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP import org.eclipse.kuksa.companion.SHEET_COLLAPSED_HEIGHT import org.eclipse.kuksa.companion.SHEET_EXPANDED_HEIGHT -import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.extension.windowSizeClass /** * AdaptiveSheetView adds a lash, which can be expanded on click to contain additional content. While it will be placed @@ -108,7 +108,7 @@ fun AdaptiveSheetView( @Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) private fun AdaptiveSheetViewPreview() { - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass AdaptiveSheetView(windowSizeClass) { } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt index 172b30b..e2963c4 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt @@ -36,7 +36,7 @@ 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.R -import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.extension.windowSizeClass import org.eclipse.kuksa.companion.feature.home.view.AdaptiveFlowRowColumn import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel @@ -109,7 +109,7 @@ private fun LightDashboardSymbol( @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) @Composable private fun LightControlViewPreview() { - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass val viewModel = LightControlViewModel() Surface { LightOverlayView(viewModel, windowSizeClass) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt index a631070..6cdb298 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt @@ -38,7 +38,7 @@ import org.eclipse.kuksa.companion.extension.alignDriverBackDoor import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor -import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.extension.windowSizeClass import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel @Composable @@ -113,7 +113,7 @@ fun TemperatureOverlayView( @Composable private fun TemperatureControlPreview() { val viewModel = TemperatureViewModel() - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass Surface { TemperatureOverlayView(viewModel, windowSizeClass) } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt index 6eb09c7..e286eb5 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt @@ -39,7 +39,7 @@ import org.eclipse.kuksa.companion.extension.alignDriverBackDoor import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor -import org.eclipse.kuksa.companion.extension.getWindowSizeClass +import org.eclipse.kuksa.companion.extension.windowSizeClass import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel @Composable @@ -128,7 +128,7 @@ private fun WheelPressureOverlayView( @Composable private fun WheelPressureControlViewPreview() { val viewModel = WheelPressureViewModel() - val windowSizeClass = LocalConfiguration.current.getWindowSizeClass() + val windowSizeClass = LocalConfiguration.current.windowSizeClass Surface { WheelPressureOverlayView(viewModel, windowSizeClass) } From c2cebd5b9ec9ad2ee070866c0235dc14c55e431b Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Tue, 6 Feb 2024 07:09:54 +0100 Subject: [PATCH 06/28] chore: Decouple animateLoadingText Logic from ConnectionState --- .../feature/connection/view/AnimatedLoadingText.kt | 9 ++++----- .../connection/view/HorizontalConnectionStatusView.kt | 3 ++- .../connection/view/VerticalConnectionStatusView.kt | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) 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 index 8f0c8cf..c26fd20 100644 --- 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 @@ -24,19 +24,18 @@ import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import kotlinx.coroutines.delay -import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel.ConnectionState import kotlin.time.Duration.Companion.milliseconds -private const val MAX_NUMBER_OF_DOTS = 3 +private const val maxNumberDots = 3 private val DelayDuration = 500.milliseconds @Composable fun animateLoadingText( - connectionState: ConnectionState, + isAnimating: Boolean, text: String, ): String { var animatedText = text - if (connectionState == ConnectionState.CONNECTING) { + if (isAnimating) { val numberOfDots = remember { mutableIntStateOf(0) } @@ -45,7 +44,7 @@ fun animateLoadingText( } LaunchedEffect(Unit) { while (true) { - if (numberOfDots.intValue < MAX_NUMBER_OF_DOTS) { + if (numberOfDots.intValue < maxNumberDots) { numberOfDots.intValue += 1 } else { numberOfDots.intValue = 0 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 8563762..f3f52d7 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 @@ -61,8 +61,9 @@ fun HorizontalConnectionStatusView( viewModel.onClickReconnect() }, ) { + val isAnimating = connectionState == ConnectionState.CONNECTING var text = connectionStateLabel - text = animateLoadingText(connectionState = connectionState, text = text) + text = animateLoadingText(isAnimating, text) ConstraintLayout(modifier = Modifier.height(StatusBarHeight)) { val (textRef, imageRef) = createRefs() 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 index b08dee4..fe79089 100644 --- 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 @@ -59,8 +59,9 @@ fun VerticalConnectionStatusView( viewModel.onClickReconnect() }, ) { + val isAnimating = connectionState == ConnectionStatusViewModel.ConnectionState.CONNECTING var text = connectionStateLabel - text = animateLoadingText(connectionState, text) + text = animateLoadingText(isAnimating, text) ConstraintLayout(modifier = Modifier.fillMaxSize()) { val (textRef, imageRef) = createRefs() From 3b12807d2e5b891d8b15e4bb08d2c8567a19d770 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Tue, 6 Feb 2024 07:22:38 +0100 Subject: [PATCH 07/28] chore: Rename Method Name of Previews --- .../feature/connection/view/AdaptiveConnectionStatusView.kt | 6 +++--- .../connection/view/HorizontalConnectionStatusView.kt | 6 +++--- .../feature/connection/view/VerticalConnectionStatusView.kt | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) 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 index a65918c..fbfcd7b 100644 --- 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 @@ -47,7 +47,7 @@ fun AdaptiveConnectionStatusView( @Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) @Composable -private fun AdaptiveConnectionStatusViewPreview_Disconnected() { +private fun AdaptiveDisconnectedPreview() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.DISCONNECTED @@ -60,7 +60,7 @@ private fun AdaptiveConnectionStatusViewPreview_Disconnected() { @Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) @Composable -private fun AdaptiveConnectionStatusViewPreview_Connecting() { +private fun AdaptiveConnectingPreview() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTING @@ -73,7 +73,7 @@ private fun AdaptiveConnectionStatusViewPreview_Connecting() { @Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) @Composable -private fun AdaptiveConnectionStatusViewPreview_Connected() { +private fun AdaptiveConnectedStatusPreview() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTED 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 f3f52d7..8d041c8 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 @@ -104,7 +104,7 @@ fun HorizontalConnectionStatusView( @Preview @Composable -private fun HorizontalConnectionStatusPreview_Disconnected() { +private fun HorizontalDisconnectedPreview() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionState.DISCONNECTED @@ -113,7 +113,7 @@ private fun HorizontalConnectionStatusPreview_Disconnected() { @Preview @Composable -private fun HorizontalConnectionStatusPreview_Connecting() { +private fun HorizontalConnectingPreview() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionState.CONNECTING HorizontalConnectionStatusView(viewModel = viewModel) @@ -121,7 +121,7 @@ private fun HorizontalConnectionStatusPreview_Connecting() { @Preview @Composable -private fun HorizontalConnectionStatusPreview_Connected() { +private fun HorizontalConnectedPreview() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionState.CONNECTED HorizontalConnectionStatusView(viewModel = viewModel) 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 index fe79089..03facea 100644 --- 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 @@ -102,7 +102,7 @@ fun VerticalConnectionStatusView( @Preview(heightDp = 300) @Composable -private fun VerticalConnectionStatusPreview_Disconnected() { +private fun VerticalDisconnectedPreview() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.DISCONNECTED @@ -111,7 +111,7 @@ private fun VerticalConnectionStatusPreview_Disconnected() { @Preview(heightDp = 300) @Composable -private fun VerticalConnectionStatusPreview_Connecting() { +private fun VerticalConnectingPreview() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTING VerticalConnectionStatusView(viewModel = viewModel) @@ -119,7 +119,7 @@ private fun VerticalConnectionStatusPreview_Connecting() { @Preview(heightDp = 300) @Composable -private fun VerticalConnectionStatusPreview_Connected() { +private fun VerticalConnectedPreview() { val viewModel = ConnectionStatusViewModel() viewModel.connectionState = ConnectionStatusViewModel.ConnectionState.CONNECTED VerticalConnectionStatusView(viewModel = viewModel) From d4c7613e8d4c4c9ad0ab6d269a55d8da0f47fec8 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Tue, 6 Feb 2024 07:48:36 +0100 Subject: [PATCH 08/28] chore: Replace VerticalText with Extension --- .../companion/extension/StringExtension.kt | 32 ++++++++ .../view/VerticalConnectionStatusView.kt | 9 ++- .../feature/connection/view/VerticalText.kt | 81 ------------------- 3 files changed, 39 insertions(+), 83 deletions(-) create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/extension/StringExtension.kt delete mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalText.kt 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 new file mode 100644 index 0000000..ce7141b --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/StringExtension.kt @@ -0,0 +1,32 @@ +/* + * 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.convertToVerticalString(): 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/VerticalConnectionStatusView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalConnectionStatusView.kt index 03facea..962e436 100644 --- 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 @@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth 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 @@ -38,6 +39,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.constraintlayout.compose.ConstraintLayout import org.eclipse.kuksa.companion.R +import org.eclipse.kuksa.companion.extension.convertToVerticalString import org.eclipse.kuksa.companion.extension.isVisible import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel @@ -66,8 +68,8 @@ fun VerticalConnectionStatusView( ConstraintLayout(modifier = Modifier.fillMaxSize()) { val (textRef, imageRef) = createRefs() - VerticalText( - text, + Text( + text = text.convertToVerticalString(), color = Color.White, textAlign = TextAlign.Center, fontWeight = FontWeight.Bold, @@ -100,6 +102,9 @@ fun VerticalConnectionStatusView( } } + + + @Preview(heightDp = 300) @Composable private fun VerticalDisconnectedPreview() { diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalText.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalText.kt deleted file mode 100644 index c1f7a3d..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/connection/view/VerticalText.kt +++ /dev/null @@ -1,81 +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.material3.LocalTextStyle -import androidx.compose.material3.Text -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.text.TextLayoutResult -import androidx.compose.ui.text.TextStyle -import androidx.compose.ui.text.font.FontFamily -import androidx.compose.ui.text.font.FontStyle -import androidx.compose.ui.text.font.FontWeight -import androidx.compose.ui.text.style.TextAlign -import androidx.compose.ui.text.style.TextDecoration -import androidx.compose.ui.text.style.TextOverflow -import androidx.compose.ui.unit.TextUnit - -@Composable -fun VerticalText( - text: String, - modifier: Modifier = Modifier, - color: Color = Color.Unspecified, - fontSize: TextUnit = TextUnit.Unspecified, - fontStyle: FontStyle? = null, - fontWeight: FontWeight? = null, - fontFamily: FontFamily? = null, - letterSpacing: TextUnit = TextUnit.Unspecified, - textDecoration: TextDecoration? = null, - textAlign: TextAlign? = null, - lineHeight: TextUnit = TextUnit.Unspecified, - overflow: TextOverflow = TextOverflow.Clip, - softWrap: Boolean = true, - maxLines: Int = Int.MAX_VALUE, - minLines: Int = 1, - onTextLayout: (TextLayoutResult) -> Unit = {}, - style: TextStyle = LocalTextStyle.current, -) { - val charArray = text.toCharArray() - val verticalTextBuilder = StringBuilder() - charArray.forEach { verticalTextBuilder.append(it).append(System.lineSeparator()) } - val verticalText = verticalTextBuilder.toString() - - Text( - verticalText, - modifier, - color, - fontSize, - fontStyle, - fontWeight, - fontFamily, - letterSpacing, - textDecoration, - textAlign, - lineHeight, - overflow, - softWrap, - maxLines, - minLines, - onTextLayout, - style, - ) -} From 549396f3186a4bcbf662c52f5104576a3a3d811f Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Tue, 6 Feb 2024 09:26:30 +0100 Subject: [PATCH 09/28] chore: Save NavigationBar Tab Information --- .../eclipse/kuksa/companion/MainActivity.kt | 3 ++ .../feature/home/view/AdaptiveAppScreen.kt | 7 ++- .../home/view/AdaptiveFlowRowColumn.kt | 51 ------------------- .../view/navigation/AdaptiveNavigationView.kt | 8 +-- .../navigation/HorizontalNavigationView.kt | 10 +++- .../view/navigation/NavigationViewModel.kt | 31 +++++++++++ .../view/navigation/VerticalNavigationView.kt | 19 ++++--- 7 files changed, 64 insertions(+), 65 deletions(-) delete mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowRowColumn.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationViewModel.kt diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt index 15a6f30..38e6719 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt @@ -46,6 +46,7 @@ import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.C import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.Companion.TRUNK_CLOSED import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.Companion.TRUNK_OPEN import org.eclipse.kuksa.companion.feature.home.view.AdaptiveAppScreen +import org.eclipse.kuksa.companion.feature.home.view.navigation.NavigationViewModel import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel import org.eclipse.kuksa.companion.feature.settings.viewModel.SettingsViewModel import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel @@ -77,6 +78,7 @@ class MainActivity : ComponentActivity() { } private val connectionStatusViewModel: ConnectionStatusViewModel by viewModels() + private val navigationViewModel: NavigationViewModel by viewModels() private val doorControlViewModel: DoorControlViewModel by viewModels() private val temperatureViewModel: TemperatureViewModel by viewModels() @@ -150,6 +152,7 @@ class MainActivity : ComponentActivity() { AdaptiveAppScreen( callback = doorVehicleSurface, connectionStatusViewModel = connectionStatusViewModel, + navigationViewModel = navigationViewModel, doorControlViewModel = doorControlViewModel, temperatureViewModel = temperatureViewModel, lightControlViewModel = lightControlViewModel, 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 9436f8a..736b2da 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 @@ -49,6 +49,7 @@ import org.eclipse.kuksa.companion.feature.door.view.DoorOverlayView import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel import org.eclipse.kuksa.companion.feature.home.view.navigation.AdaptiveNavigationView import org.eclipse.kuksa.companion.feature.home.view.navigation.NavigationPage +import org.eclipse.kuksa.companion.feature.home.view.navigation.NavigationViewModel import org.eclipse.kuksa.companion.feature.home.view.sheet.AdaptiveSheetView import org.eclipse.kuksa.companion.feature.light.view.LightControlView import org.eclipse.kuksa.companion.feature.light.view.LightOverlayView @@ -74,6 +75,7 @@ private const val ZINDEX_CONTROL = 3F fun AdaptiveAppScreen( callback: SurfaceHolder.Callback, connectionStatusViewModel: ConnectionStatusViewModel, + navigationViewModel: NavigationViewModel, doorControlViewModel: DoorControlViewModel, temperatureViewModel: TemperatureViewModel, lightControlViewModel: LightControlViewModel, @@ -83,7 +85,7 @@ fun AdaptiveAppScreen( modifier: Modifier = Modifier, ) { var selectedPage: NavigationPage by remember { - mutableStateOf(NavigationPage.DOORS) + mutableStateOf(navigationViewModel.selectedNavigationPage) } AdaptiveColumnRow(windowSizeClass = windowSizeClass, modifier = modifier.fillMaxSize()) { @@ -91,7 +93,7 @@ fun AdaptiveAppScreen( val resources = context.resources AdaptiveConnectionStatusView(connectionStatusViewModel, windowSizeClass) - AdaptiveNavigationView(windowSizeClass) { page -> + AdaptiveNavigationView(navigationViewModel, windowSizeClass) { page -> selectedPage = page } Box(modifier = Modifier.fillMaxSize()) { @@ -181,6 +183,7 @@ private fun AdaptiveAppScreenPreview() { AdaptiveAppScreen( callback, ConnectionStatusViewModel(), + NavigationViewModel(), DoorControlViewModel(application), TemperatureViewModel(), LightControlViewModel(), diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowRowColumn.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowRowColumn.kt deleted file mode 100644 index a887ef1..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowRowColumn.kt +++ /dev/null @@ -1,51 +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.home.view - -import androidx.compose.foundation.layout.ExperimentalLayoutApi -import androidx.compose.foundation.layout.FlowColumn -import androidx.compose.foundation.layout.FlowRow -import androidx.compose.material3.windowsizeclass.WindowSizeClass -import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass -import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier - -/** - * Adds an adaptive FlowRow or FlowColumn depending on the [WindowWidthSizeClass] of the device. - * If the device has a [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] a FlowColumn will - * be used, while otherwise a FlowRow will be used. - */ -@OptIn(ExperimentalLayoutApi::class) -@Composable -fun AdaptiveFlowRowColumn( - windowSizeClass: WindowSizeClass, - modifier: Modifier = Modifier, - content: @Composable () -> Unit, -) { - if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - FlowColumn(modifier) { - content() - } - } else { - FlowRow(modifier) { - content() - } - } -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt index 6d0a1df..1f577e5 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt @@ -36,14 +36,15 @@ import org.eclipse.kuksa.companion.extension.windowSizeClass */ @Composable fun AdaptiveNavigationView( + viewModel: NavigationViewModel, windowSizeClass: WindowSizeClass, modifier: Modifier = Modifier, onPageSelected: (NavigationPage) -> Unit = {}, ) { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - HorizontalNavigationView(modifier, onPageSelected) + HorizontalNavigationView(viewModel, modifier, onPageSelected) } else { - VerticalNavigationView(modifier, onPageSelected) + VerticalNavigationView(viewModel, modifier, onPageSelected) } } @@ -51,6 +52,7 @@ fun AdaptiveNavigationView( @Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) @Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) private fun AdaptiveNavigationViewPreview() { + val viewModel = NavigationViewModel() val windowSizeClass = LocalConfiguration.current.windowSizeClass - AdaptiveNavigationView(windowSizeClass = windowSizeClass) + AdaptiveNavigationView(viewModel, windowSizeClass) } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt index 3f754ec..4ba59de 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt @@ -34,10 +34,13 @@ import androidx.compose.ui.tooling.preview.Preview @Composable fun HorizontalNavigationView( + viewModel: NavigationViewModel, modifier: Modifier = Modifier, onPageSelected: (NavigationPage) -> Unit = {}, ) { - var selectedItemIndex by remember { mutableIntStateOf(0) } + var selectedItemIndex by remember { + mutableIntStateOf(viewModel.selectedNavigationIndex) + } Column(modifier) { NavigationBar { @@ -46,6 +49,8 @@ fun HorizontalNavigationView( selected = index == selectedItemIndex, onClick = { selectedItemIndex = index + viewModel.selectedNavigationIndex = index + viewModel.selectedNavigationPage = page onPageSelected(page) }, icon = { @@ -63,5 +68,6 @@ fun HorizontalNavigationView( @Preview(showBackground = true) @Composable private fun HorizontalNavigationViewPreview() { - HorizontalNavigationView() + val viewModel = NavigationViewModel() + HorizontalNavigationView(viewModel) } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationViewModel.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationViewModel.kt new file mode 100644 index 0000000..0bd23fd --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationViewModel.kt @@ -0,0 +1,31 @@ +/* + * 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.home.view.navigation + +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableIntStateOf +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.setValue +import androidx.lifecycle.ViewModel + +class NavigationViewModel : ViewModel() { + var selectedNavigationIndex by mutableIntStateOf(0) + var selectedNavigationPage by mutableStateOf(NavigationPage.DOORS) +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt index f3c3223..d0495af 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt @@ -35,22 +35,26 @@ import androidx.compose.ui.tooling.preview.Preview @Composable fun VerticalNavigationView( + viewModel: NavigationViewModel, modifier: Modifier = Modifier, onPageSelected: (NavigationPage) -> Unit = {}, ) { - var selectedItemIndex by remember { mutableIntStateOf(0) } + var selectedItemIndex by remember { + mutableIntStateOf(viewModel.selectedNavigationIndex) + } val pages = NavigationPage.entries.toTypedArray() Row(modifier) { NavigationRail { - pages.forEachIndexed { index, item -> - + pages.forEachIndexed { index, page -> NavigationRailItem( - label = { Text(item.title) }, - icon = { Icon(painterResource(id = item.iconRes), contentDescription = item.title) }, + label = { Text(page.title) }, + icon = { Icon(painterResource(id = page.iconRes), contentDescription = page.title) }, selected = selectedItemIndex == index, onClick = { selectedItemIndex = index - onPageSelected(item) + viewModel.selectedNavigationIndex = index + viewModel.selectedNavigationPage = page + onPageSelected(page) }, ) } @@ -61,5 +65,6 @@ fun VerticalNavigationView( @Preview @Composable private fun VerticalNavigationViewPreview() { - VerticalNavigationView() + val viewModel = NavigationViewModel() + VerticalNavigationView(viewModel) } From 3f4ad104235800130db93ac6a73b3d95756eb690 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Tue, 6 Feb 2024 09:26:48 +0100 Subject: [PATCH 10/28] chore: Align Naming --- .../home/view/AdaptiveFlowColumnRow.kt | 51 +++++++++++++++++++ .../feature/light/view/LightOverlayView.kt | 4 +- 2 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowColumnRow.kt diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowColumnRow.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowColumnRow.kt new file mode 100644 index 0000000..09c5a2a --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/AdaptiveFlowColumnRow.kt @@ -0,0 +1,51 @@ +/* + * 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.home.view + +import androidx.compose.foundation.layout.ExperimentalLayoutApi +import androidx.compose.foundation.layout.FlowColumn +import androidx.compose.foundation.layout.FlowRow +import androidx.compose.material3.windowsizeclass.WindowSizeClass +import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier + +/** + * Adds an adaptive FlowRow or FlowColumn depending on the [WindowWidthSizeClass] of the device. + * If the device has a [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] a FlowColumn will + * be used, while otherwise a FlowRow will be used. + */ +@OptIn(ExperimentalLayoutApi::class) +@Composable +fun AdaptiveFlowColumnRow( + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, + content: @Composable () -> Unit, +) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + FlowColumn(modifier) { + content() + } + } else { + FlowRow(modifier) { + content() + } + } +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt index e2963c4..5269995 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/light/view/LightOverlayView.kt @@ -37,7 +37,7 @@ 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.extension.windowSizeClass -import org.eclipse.kuksa.companion.feature.home.view.AdaptiveFlowRowColumn +import org.eclipse.kuksa.companion.feature.home.view.AdaptiveFlowColumnRow import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel @Composable @@ -46,7 +46,7 @@ fun LightOverlayView( windowSizeClass: WindowSizeClass, modifier: Modifier = Modifier, ) { - AdaptiveFlowRowColumn(windowSizeClass, modifier = modifier.padding(10.dp)) { + AdaptiveFlowColumnRow(windowSizeClass, modifier = modifier.padding(10.dp)) { LightDashboardSymbol( isLightEnabled = viewModel.isHighBeamLightOn.value, painterResource = R.drawable.lights_beam_high_24, From 2915a7d0b7952347ef716bf0c7024c5bd005c4d5 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Tue, 6 Feb 2024 14:21:36 +0100 Subject: [PATCH 11/28] chore: Re-Add BottomSheet --- .../feature/home/view/AdaptiveAppScreen.kt | 94 +++++++-------- .../home/view/navigation/NavigationPage.kt | 6 + ...eetLayout.kt => AdaptiveSheetLayoutBak.kt} | 4 +- .../home/view/sheet/AdaptiveSheetView.kt | 70 ++++++++++++ .../home/view/sheet/BottomSheetView.kt | 108 ++++++++++++++++++ .../feature/home/view/sheet/SideSheetView.kt | 39 +++++++ 6 files changed, 273 insertions(+), 48 deletions(-) rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/{AdaptiveSheetLayout.kt => AdaptiveSheetLayoutBak.kt} (97%) create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt 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 736b2da..5bb0ed2 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 @@ -21,9 +21,9 @@ 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.fillMaxSize import androidx.compose.foundation.layout.padding +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.windowsizeclass.WindowSizeClass import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.runtime.Composable @@ -35,11 +35,9 @@ 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.R 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 @@ -71,6 +69,7 @@ private const val ZINDEX_CONTROL = 3F * [WindowWidthSizeClass.Compact] all elements are placed on top of each other, while for devices with a higher class * the elements will be placed next to each other. */ +@OptIn(ExperimentalMaterial3Api::class) @Composable fun AdaptiveAppScreen( callback: SurfaceHolder.Callback, @@ -89,65 +88,66 @@ fun AdaptiveAppScreen( } AdaptiveColumnRow(windowSizeClass = windowSizeClass, modifier = modifier.fillMaxSize()) { - val context = LocalContext.current - val resources = context.resources - AdaptiveConnectionStatusView(connectionStatusViewModel, windowSizeClass) AdaptiveNavigationView(navigationViewModel, windowSizeClass) { page -> selectedPage = page } - Box(modifier = Modifier.fillMaxSize()) { - val paddingBottom = resources.getInteger(R.integer.RAMSES_VIEW_PADDING_BOTTOM) - val paddingEnd = resources.getInteger(R.integer.RAMSES_VIEW_PADDING_END) + AdaptiveSheetView( + windowSizeClass = windowSizeClass, + modifier = Modifier.fillMaxSize(), + isBottomSheetEnabled = selectedPage.isBottomSheetEnabled, + sheetContent = { + when (selectedPage) { + NavigationPage.DOORS -> DoorControlView(doorControlViewModel) + NavigationPage.TEMPERATURE -> TemperatureControlView(temperatureViewModel) + NavigationPage.LIGHT -> LightControlView(lightControlViewModel) + NavigationPage.WHEELS, + NavigationPage.SETTINGS, + -> { } + } + }, + ) { RamsesView( callback = callback, modifier = Modifier .zIndex(ZINDEX_RAMSES_VIEW) - .fillMaxSize() - // AdaptiveSheetPadding - .padding(bottom = paddingBottom.dp, end = paddingEnd.dp), + .fillMaxSize(), ) val overlayModifier = Modifier .zIndex(ZINDEX_OVERLAY) .fillMaxSize() - // AdaptiveSheetPadding - .padding(bottom = paddingBottom.dp, end = paddingEnd.dp) - - val controlModifier = Modifier - .zIndex(ZINDEX_CONTROL) - .fillMaxSize() + .padding(it) when (selectedPage) { - NavigationPage.DOORS -> { - DoorOverlayView(doorControlViewModel, windowSizeClass, overlayModifier) - AdaptiveSheetView(windowSizeClass, controlModifier) { - DoorControlView(doorControlViewModel) - } - } - - NavigationPage.TEMPERATURE -> { - TemperatureOverlayView(temperatureViewModel, windowSizeClass, overlayModifier) - AdaptiveSheetView(windowSizeClass, controlModifier) { - TemperatureControlView(temperatureViewModel) - } - } - - NavigationPage.LIGHT -> { - LightOverlayView(lightControlViewModel, windowSizeClass, overlayModifier) - AdaptiveSheetView(windowSizeClass, controlModifier) { - LightControlView(lightControlViewModel) - } - } - - NavigationPage.WHEELS -> { - WheelPressureOverlayView(wheelPressureViewModel, windowSizeClass, overlayModifier) - AdaptiveSheetView(windowSizeClass) { - WheelPressureOverlayView(wheelPressureViewModel, windowSizeClass) - } - } - - NavigationPage.SETTINGS -> SettingsView(settingsViewModel, overlayModifier) + NavigationPage.DOORS -> DoorOverlayView( + doorControlViewModel, + windowSizeClass, + overlayModifier, + ) + + NavigationPage.TEMPERATURE -> TemperatureOverlayView( + temperatureViewModel, + windowSizeClass, + overlayModifier, + ) + + NavigationPage.LIGHT -> LightOverlayView( + lightControlViewModel, + windowSizeClass, + overlayModifier, + ) + + NavigationPage.WHEELS -> WheelPressureOverlayView( + wheelPressureViewModel, + windowSizeClass, + overlayModifier, + ) + + NavigationPage.SETTINGS -> SettingsView( + settingsViewModel, + overlayModifier, + ) } } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt index 1b850a1..aa9b2ba 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt @@ -26,30 +26,36 @@ enum class NavigationPage( @DrawableRes val iconRes: Int, val title: String, val description: String, + val isBottomSheetEnabled: Boolean, ) { DOORS( R.drawable.baseline_sensor_door_24, "Door Control", "Show status of the doors and trunk, (un-)lock and open/close them", + true, ), TEMPERATURE( R.drawable.baseline_device_thermostat_24, "Temperature Control", "Check the temperature inside the car, increase or decrease the temperature. ", + true, ), LIGHT( R.drawable.baseline_light_mode_24, "Light Control", "Check the status of the light, turn them on and off to check their functionality", + true, ), WHEELS( R.drawable.baseline_sports_volleyball_24, "Wheel Pressure", "Check the pressure of the wheels", + false, ), SETTINGS( R.drawable.baseline_settings_24, "Settings", "Settings", + false, ), } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayoutBak.kt similarity index 97% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayoutBak.kt index f7c1cd7..95dc5cc 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayout.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayoutBak.kt @@ -27,6 +27,7 @@ import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.width +import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.windowsizeclass.WindowSizeClass import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass import androidx.compose.runtime.Composable @@ -54,7 +55,7 @@ import org.eclipse.kuksa.companion.extension.windowSizeClass * "end" for devices with a WindowWidthSizeClass which is higher. */ @Composable -fun AdaptiveSheetView( +fun AdaptiveSheetViewBak( windowSizeClass: WindowSizeClass, modifier: Modifier = Modifier, sheetContent: @Composable () -> Unit, @@ -104,6 +105,7 @@ fun AdaptiveSheetView( } } +@OptIn(ExperimentalMaterial3Api::class) @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/home/view/sheet/AdaptiveSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt new file mode 100644 index 0000000..fe20515 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt @@ -0,0 +1,70 @@ +/* + * 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.home.view.sheet + +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.SheetValue +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 org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP +import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP +import org.eclipse.kuksa.companion.extension.windowSizeClass + +/** + * AdaptiveSheetView adds a lash, which can be expanded on click to contain additional content. While it will be placed + * on the bottom for devices with a [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] it will be placed on the + * "end" for devices with a WindowWidthSizeClass which is higher. + */ +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun AdaptiveSheetView( + windowSizeClass: WindowSizeClass, + modifier: Modifier = Modifier, + isBottomSheetEnabled: Boolean = true, + sheetContent: @Composable () -> Unit = { }, + content: @Composable (PaddingValues) -> Unit = { }, +) { + if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { + val initialSheetValue = if (isBottomSheetEnabled) SheetValue.PartiallyExpanded else SheetValue.Hidden + + BottomSheetView( + modifier = modifier, + initialSheetValue = initialSheetValue, + sheetContent = sheetContent, + content = content, + ) + } else { + + } +} + +@Composable +@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) +@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) +private fun AdaptiveSheetViewPreview() { + val windowSizeClass = LocalConfiguration.current.windowSizeClass + AdaptiveSheetView(windowSizeClass) { + } +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt new file mode 100644 index 0000000..5acf0be --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt @@ -0,0 +1,108 @@ +/* + * 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.home.view.sheet + +import android.app.Application +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.BottomSheetDefaults +import androidx.compose.material3.BottomSheetScaffold +import androidx.compose.material3.BottomSheetScaffoldState +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.SheetState +import androidx.compose.material3.SheetValue +import androidx.compose.material3.SnackbarHostState +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.extension.windowSizeClass +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 + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun BottomSheetView( + modifier: Modifier = Modifier, + initialSheetValue: SheetValue = SheetValue.PartiallyExpanded, + sheetContent: @Composable () -> Unit, + content: @Composable (PaddingValues) -> Unit, +) { + val bottomSheetScaffoldState = BottomSheetScaffoldState( + bottomSheetState = SheetState( + initialValue = initialSheetValue, + skipPartiallyExpanded = false, + skipHiddenState = initialSheetValue != SheetValue.Hidden, + ), + snackbarHostState = SnackbarHostState(), + ) + + val sheetPeekHeight = if (initialSheetValue == SheetValue.Hidden) 0.dp else BottomSheetDefaults.SheetPeekHeight + BottomSheetScaffold( + + scaffoldState = bottomSheetScaffoldState, + sheetContent = { + sheetContent() + }, + sheetPeekHeight = sheetPeekHeight, + modifier = modifier.fillMaxSize(), + ) { + content(it) + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +@Preview +private fun ExpandedPreview() { + val application = Application() + val viewModel = DoorControlViewModel(application) + val windowSizeClass = LocalConfiguration.current.windowSizeClass + BottomSheetView(initialSheetValue = SheetValue.Expanded, sheetContent = { + DoorControlView(viewModel = viewModel) + }) { + DoorOverlayView( + viewModel = viewModel, + windowSizeClass = windowSizeClass, + modifier = Modifier.padding(it), + ) + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +@Preview +private fun CollapsedPreview() { + val application = Application() + val viewModel = DoorControlViewModel(application) + val windowSizeClass = LocalConfiguration.current.windowSizeClass + BottomSheetView(initialSheetValue = SheetValue.PartiallyExpanded, sheetContent = { + DoorControlView(viewModel = viewModel) + }) { + DoorOverlayView( + viewModel = viewModel, + windowSizeClass = windowSizeClass, + modifier = Modifier.padding(it), + ) + } +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt new file mode 100644 index 0000000..1d5b817 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt @@ -0,0 +1,39 @@ +/* + * 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.home.view.sheet + +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview + +@Composable +fun SideSheetView( + modifier: Modifier = Modifier, + sheetContent: @Composable () -> Unit, +) { +} + +@Preview +@Composable +private fun SideSheetViewPreview() { + SideSheetView { + + } +} From 09f79d53d18baebad073457c5f486317a8c31abb Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Wed, 7 Feb 2024 10:11:42 +0100 Subject: [PATCH 12/28] chore: Replace ConstraintScopeExtension with RamsesAnchor --- .../extension/ConstraintScopeExtension.kt | 93 ------------ .../feature/door/view/DoorOverlayView.kt | 29 ++-- .../view/TemperatureOverlayView.kt | 21 +-- .../pressure/view/WheelPressureOverlayView.kt | 22 +-- .../kuksa/companion/ramses/RamsesAnchor.kt | 135 ++++++++++++++++++ 5 files changed, 178 insertions(+), 122 deletions(-) delete mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt create mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/ramses/RamsesAnchor.kt diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt deleted file mode 100644 index c0fdd06..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/ConstraintScopeExtension.kt +++ /dev/null @@ -1,93 +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.material3.windowsizeclass.WindowSizeClass -import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass -import androidx.constraintlayout.compose.ConstrainScope -import androidx.constraintlayout.compose.ConstrainedLayoutReference -import org.eclipse.kuksa.companion.feature.door.view.horizontalMarginAnchorToDoor -import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToBackDoor -import org.eclipse.kuksa.companion.feature.door.view.verticalMarginAnchorToDoor - -fun ConstrainScope.alignDriverFrontDoor( - windowSizeClass: WindowSizeClass, - anchorPoint: ConstrainedLayoutReference, -) { - if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - end.linkTo(anchorPoint.start, horizontalMarginAnchorToDoor) - top.linkTo(anchorPoint.bottom, verticalMarginAnchorToDoor) - } else { - end.linkTo(anchorPoint.start, verticalMarginAnchorToDoor) - bottom.linkTo(anchorPoint.top, horizontalMarginAnchorToDoor) - } -} - -fun ConstrainScope.alignPassengerFrontDoor( - windowSizeClass: WindowSizeClass, - anchorPoint: ConstrainedLayoutReference, -) { - if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - start.linkTo(anchorPoint.end, horizontalMarginAnchorToDoor) - top.linkTo(anchorPoint.bottom, verticalMarginAnchorToDoor) - } else { - end.linkTo(anchorPoint.start, verticalMarginAnchorToDoor) - top.linkTo(anchorPoint.bottom, horizontalMarginAnchorToDoor) - } -} - -fun ConstrainScope.alignDriverBackDoor( - windowSizeClass: WindowSizeClass, - anchorPoint: ConstrainedLayoutReference, -) { - if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - end.linkTo(anchorPoint.start, horizontalMarginAnchorToDoor) - top.linkTo(anchorPoint.bottom, verticalMarginAnchorToBackDoor) - } else { - end.linkTo(anchorPoint.start, verticalMarginAnchorToBackDoor) - bottom.linkTo(anchorPoint.top, horizontalMarginAnchorToDoor) - } -} - -fun ConstrainScope.alignPassengerBackDoor( - windowSizeClass: WindowSizeClass, - anchorPoint: ConstrainedLayoutReference, -) { - if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - start.linkTo(anchorPoint.end, horizontalMarginAnchorToDoor) - top.linkTo(anchorPoint.bottom, verticalMarginAnchorToBackDoor) - } else { - end.linkTo(anchorPoint.start, verticalMarginAnchorToBackDoor) - top.linkTo(anchorPoint.bottom, horizontalMarginAnchorToDoor) - } -} - -fun ConstrainScope.alignTrunk( - windowSizeClass: WindowSizeClass, - anchorPoint: ConstrainedLayoutReference, -) { - if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - centerHorizontallyTo(anchorPoint) - bottom.linkTo(parent.bottom) - } else { - centerVerticallyTo(anchorPoint) - start.linkTo(parent.start) - } -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt index 4f4b798..9135a3f 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt @@ -37,17 +37,14 @@ import androidx.compose.ui.unit.dp import androidx.constraintlayout.compose.ConstraintLayout import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP -import org.eclipse.kuksa.companion.extension.alignDriverBackDoor -import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor -import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor -import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor -import org.eclipse.kuksa.companion.extension.alignTrunk import org.eclipse.kuksa.companion.extension.windowSizeClass import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel +import org.eclipse.kuksa.companion.ramses.DriverBackDoorAnchor +import org.eclipse.kuksa.companion.ramses.DriverFrontDoorAnchor +import org.eclipse.kuksa.companion.ramses.PassengerBackDoorAnchor +import org.eclipse.kuksa.companion.ramses.PassengerFrontDoorAnchor +import org.eclipse.kuksa.companion.ramses.TrunkAnchor -val horizontalMarginAnchorToDoor = 75.dp -val verticalMarginAnchorToDoor = 10.dp -val verticalMarginAnchorToBackDoor = 100.dp @Composable fun DoorOverlayView( @@ -76,12 +73,18 @@ fun DoorOverlayView( }, ) + val driverFrontDoorAnchor = DriverFrontDoorAnchor(windowSizeClass, anchorPoint) + val passengerFrontDoorAnchor = PassengerFrontDoorAnchor(windowSizeClass, anchorPoint) + val driverBackDoorAnchor = DriverBackDoorAnchor(windowSizeClass, anchorPoint) + val passengerBackDoorAnchor = PassengerBackDoorAnchor(windowSizeClass, anchorPoint) + val trunkAnchor = TrunkAnchor(windowSizeClass, anchorPoint) + val imageModifier = Modifier .size(60.dp) Box( modifier = imageModifier .constrainAs(driverSide) { - alignDriverFrontDoor(windowSizeClass, anchorPoint) + driverFrontDoorAnchor.align(this) } .clickable { viewModel.onClickToggleDoor(isLockedDriverSide) @@ -97,7 +100,7 @@ fun DoorOverlayView( Box( modifier = imageModifier .constrainAs(passengerSide) { - alignPassengerFrontDoor(windowSizeClass, anchorPoint) + passengerFrontDoorAnchor.align(this) } .clickable { viewModel.onClickToggleDoor(isLockedPassengerSide) @@ -114,7 +117,7 @@ fun DoorOverlayView( contentDescription = "Lock bottom left", modifier = imageModifier .constrainAs(driverSideBack) { - alignDriverBackDoor(windowSizeClass, anchorPoint) + driverBackDoorAnchor.align(this) } .clickable { viewModel.onClickToggleDoor(isLockedDriverSideBack) @@ -123,7 +126,7 @@ fun DoorOverlayView( Box( modifier = imageModifier .constrainAs(passengerSideBack) { - alignPassengerBackDoor(windowSizeClass, anchorPoint) + passengerBackDoorAnchor.align(this) } .clickable { viewModel.onClickToggleDoor(isLockedPassengerSideBack) @@ -139,7 +142,7 @@ fun DoorOverlayView( Box( modifier = imageModifier .constrainAs(trunkRear) { - alignTrunk(windowSizeClass, anchorPoint) + trunkAnchor.align(this) } .clickable { viewModel.onClickToggleTrunk(isLockedTrunkRear) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt index 6cdb298..f0867b8 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/temperature/view/TemperatureOverlayView.kt @@ -34,12 +34,12 @@ import androidx.compose.ui.unit.dp import androidx.constraintlayout.compose.ConstraintLayout import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP -import org.eclipse.kuksa.companion.extension.alignDriverBackDoor -import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor -import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor -import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor import org.eclipse.kuksa.companion.extension.windowSizeClass import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel +import org.eclipse.kuksa.companion.ramses.DriverBackDoorAnchor +import org.eclipse.kuksa.companion.ramses.DriverFrontDoorAnchor +import org.eclipse.kuksa.companion.ramses.PassengerBackDoorAnchor +import org.eclipse.kuksa.companion.ramses.PassengerFrontDoorAnchor @Composable fun TemperatureOverlayView( @@ -68,6 +68,11 @@ fun TemperatureOverlayView( }, ) + val driverFrontDoorAnchor = DriverFrontDoorAnchor(windowSizeClass, anchorPoint) + val passengerFrontDoorAnchor = PassengerFrontDoorAnchor(windowSizeClass, anchorPoint) + val driverBackDoorAnchor = DriverBackDoorAnchor(windowSizeClass, anchorPoint) + val passengerBackDoorAnchor = PassengerBackDoorAnchor(windowSizeClass, anchorPoint) + val unit = "°C" Text( text = "$temperatureDriverSideFront $unit", @@ -75,7 +80,7 @@ fun TemperatureOverlayView( color = viewModel.getTemperatureColor(temperatureDriverSideFront), modifier = Modifier .constrainAs(driverSideRef) { - alignDriverFrontDoor(windowSizeClass, anchorPoint) + driverFrontDoorAnchor.align(this) }, ) Text( @@ -84,7 +89,7 @@ fun TemperatureOverlayView( color = viewModel.getTemperatureColor(temperaturePassengerSideFront), modifier = Modifier .constrainAs(passengerSideRef) { - alignPassengerFrontDoor(windowSizeClass, anchorPoint) + passengerFrontDoorAnchor.align(this) }, ) Text( @@ -93,7 +98,7 @@ fun TemperatureOverlayView( color = viewModel.getTemperatureColor(temperatureDriverSideBack), modifier = Modifier .constrainAs(driverSideBackRef) { - alignDriverBackDoor(windowSizeClass, anchorPoint) + driverBackDoorAnchor.align(this) }, ) Text( @@ -102,7 +107,7 @@ fun TemperatureOverlayView( color = viewModel.getTemperatureColor(temperaturePassengerSideBack), modifier = Modifier .constrainAs(passengerSideBackRef) { - alignPassengerBackDoor(windowSizeClass, anchorPoint) + passengerBackDoorAnchor.align(this) }, ) } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt index e286eb5..dc4b56c 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt @@ -35,12 +35,13 @@ import androidx.compose.ui.unit.dp import androidx.constraintlayout.compose.ConstraintLayout import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP -import org.eclipse.kuksa.companion.extension.alignDriverBackDoor -import org.eclipse.kuksa.companion.extension.alignDriverFrontDoor -import org.eclipse.kuksa.companion.extension.alignPassengerBackDoor -import org.eclipse.kuksa.companion.extension.alignPassengerFrontDoor import org.eclipse.kuksa.companion.extension.windowSizeClass import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel +import org.eclipse.kuksa.companion.ramses.DriverBackDoorAnchor +import org.eclipse.kuksa.companion.ramses.DriverFrontDoorAnchor +import org.eclipse.kuksa.companion.ramses.PassengerBackDoorAnchor +import org.eclipse.kuksa.companion.ramses.PassengerFrontDoorAnchor +import org.eclipse.kuksa.companion.ramses.TrunkAnchor @Composable fun WheelPressureOverlayView( @@ -83,6 +84,11 @@ private fun WheelPressureOverlayView( }, ) + val driverFrontDoorAnchor = DriverFrontDoorAnchor(windowSizeClass, anchorPoint) + val passengerFrontDoorAnchor = PassengerFrontDoorAnchor(windowSizeClass, anchorPoint) + val driverBackDoorAnchor = DriverBackDoorAnchor(windowSizeClass, anchorPoint) + val passengerBackDoorAnchor = PassengerBackDoorAnchor(windowSizeClass, anchorPoint) + val unit = "kPa" Text( text = "$pressureLeftFront $unit", @@ -90,7 +96,7 @@ private fun WheelPressureOverlayView( color = Color.White, modifier = Modifier .constrainAs(driverSideRef) { - alignDriverFrontDoor(windowSizeClass, anchorPoint) + driverFrontDoorAnchor.align(this) }, ) Text( @@ -99,7 +105,7 @@ private fun WheelPressureOverlayView( color = Color.White, modifier = Modifier .constrainAs(passengerSideRef) { - alignPassengerFrontDoor(windowSizeClass, anchorPoint) + passengerFrontDoorAnchor.align(this) }, ) Text( @@ -108,7 +114,7 @@ private fun WheelPressureOverlayView( color = Color.White, modifier = Modifier .constrainAs(driverSideBackRef) { - alignDriverBackDoor(windowSizeClass, anchorPoint) + driverBackDoorAnchor.align(this) }, ) Text( @@ -117,7 +123,7 @@ private fun WheelPressureOverlayView( color = Color.White, modifier = Modifier .constrainAs(passengerSideBackRef) { - alignPassengerBackDoor(windowSizeClass, anchorPoint) + passengerBackDoorAnchor.align(this) }, ) } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/ramses/RamsesAnchor.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/ramses/RamsesAnchor.kt new file mode 100644 index 0000000..c357131 --- /dev/null +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/ramses/RamsesAnchor.kt @@ -0,0 +1,135 @@ +/* + * 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.ramses + +import androidx.compose.material3.windowsizeclass.WindowSizeClass +import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass +import androidx.compose.ui.unit.dp +import androidx.constraintlayout.compose.ConstrainScope +import androidx.constraintlayout.compose.ConstrainedLayoutReference + +private val horizontalMarginAnchorToDoor = 75.dp +private val verticalMarginAnchorToDoor = 10.dp +private val verticalMarginAnchorToBackDoor = 100.dp + +sealed class RamsesAnchor( + protected val windowSizeClass: WindowSizeClass, + protected val anchorPoint: ConstrainedLayoutReference, +) { + abstract fun alignCompact(constrainScope: ConstrainScope) + + abstract fun alignMedium(constrainScope: ConstrainScope) + + fun align(constrainScope: ConstrainScope) { + when (windowSizeClass.widthSizeClass) { + WindowWidthSizeClass.Compact -> alignCompact(constrainScope) + + WindowWidthSizeClass.Medium, + WindowWidthSizeClass.Expanded, + -> alignMedium(constrainScope) + } + } +} + +class DriverFrontDoorAnchor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) : + RamsesAnchor(windowSizeClass, anchorPoint) { + override fun alignCompact(constrainScope: ConstrainScope) { + constrainScope.apply { + end.linkTo(anchorPoint.start, horizontalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, verticalMarginAnchorToDoor) + } + } + + override fun alignMedium(constrainScope: ConstrainScope) { + constrainScope.apply { + end.linkTo(anchorPoint.start, verticalMarginAnchorToDoor) + bottom.linkTo(anchorPoint.top, horizontalMarginAnchorToDoor) + } + } +} + +class PassengerFrontDoorAnchor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) : + RamsesAnchor(windowSizeClass, anchorPoint) { + override fun alignCompact(constrainScope: ConstrainScope) { + constrainScope.apply { + start.linkTo(anchorPoint.end, horizontalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, verticalMarginAnchorToDoor) + } + } + + override fun alignMedium(constrainScope: ConstrainScope) { + constrainScope.apply { + end.linkTo(anchorPoint.start, verticalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, horizontalMarginAnchorToDoor) + } + } +} + +class DriverBackDoorAnchor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) : + RamsesAnchor(windowSizeClass, anchorPoint) { + override fun alignCompact(constrainScope: ConstrainScope) { + constrainScope.apply { + end.linkTo(anchorPoint.start, horizontalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, verticalMarginAnchorToBackDoor) + } + } + + override fun alignMedium(constrainScope: ConstrainScope) { + constrainScope.apply { + end.linkTo(anchorPoint.start, verticalMarginAnchorToBackDoor) + bottom.linkTo(anchorPoint.top, horizontalMarginAnchorToDoor) + } + } +} + +class PassengerBackDoorAnchor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) : + RamsesAnchor(windowSizeClass, anchorPoint) { + override fun alignCompact(constrainScope: ConstrainScope) { + constrainScope.apply { + start.linkTo(anchorPoint.end, horizontalMarginAnchorToDoor) + top.linkTo(anchorPoint.bottom, verticalMarginAnchorToBackDoor) + } + } + + override fun alignMedium(constrainScope: ConstrainScope) { + constrainScope.apply { + end.linkTo(anchorPoint.start, verticalMarginAnchorToBackDoor) + top.linkTo(anchorPoint.bottom, horizontalMarginAnchorToDoor) + } + } +} + +class TrunkAnchor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayoutReference) : + RamsesAnchor(windowSizeClass, anchorPoint) { + override fun alignCompact(constrainScope: ConstrainScope) { + constrainScope.apply { + centerHorizontallyTo(anchorPoint) + bottom.linkTo(parent.bottom) + } + } + + override fun alignMedium(constrainScope: ConstrainScope) { + constrainScope.apply { + centerVerticallyTo(anchorPoint) + start.linkTo(parent.start) + } + } +} + From 6df52508ad85729e15ce0d6c1e17ee2c04ade84d Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Wed, 7 Feb 2024 12:48:33 +0100 Subject: [PATCH 13/28] chore: Change Size of NavigationBarIcons --- .../home/view/navigation/HorizontalNavigationView.kt | 3 +++ .../home/view/navigation/VerticalNavigationView.kt | 10 +++++++++- app/src/main/res/values/values.xml | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt index 4ba59de..26dedc9 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt @@ -20,6 +20,7 @@ package org.eclipse.kuksa.companion.feature.home.view.navigation import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.size import androidx.compose.material3.Icon import androidx.compose.material3.NavigationBar import androidx.compose.material3.NavigationBarItem @@ -31,6 +32,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp @Composable fun HorizontalNavigationView( @@ -57,6 +59,7 @@ fun HorizontalNavigationView( 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/home/view/navigation/VerticalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt index d0495af..6570a57 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt @@ -20,6 +20,7 @@ package org.eclipse.kuksa.companion.feature.home.view.navigation import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.size import androidx.compose.material3.Icon import androidx.compose.material3.NavigationRail import androidx.compose.material3.NavigationRailItem @@ -32,6 +33,7 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp @Composable fun VerticalNavigationView( @@ -48,7 +50,13 @@ fun VerticalNavigationView( pages.forEachIndexed { index, page -> NavigationRailItem( label = { Text(page.title) }, - icon = { Icon(painterResource(id = page.iconRes), contentDescription = page.title) }, + icon = { + Icon( + painterResource(id = page.iconRes), + contentDescription = page.title, + modifier = Modifier.size(30.dp), + ) + }, selected = selectedItemIndex == index, onClick = { selectedItemIndex = index diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index cbc6cd1..b5a45d2 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -20,7 +20,7 @@ 90 100 - 700 + 800 0 50 From 3a82419b2f44821a5882b2b8222a9d674142c203 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 8 Feb 2024 07:16:06 +0100 Subject: [PATCH 14/28] chore: Add SideSheet to Landscape Mode --- app/build.gradle.kts | 2 + .../navigation/HorizontalNavigationView.kt | 3 +- .../view/navigation/VerticalNavigationView.kt | 9 +- .../home/view/sheet/AdaptiveSheetView.kt | 7 +- .../feature/home/view/sheet/SideSheetView.kt | 149 +++++++++++++++++- .../res/drawable/baseline_menu_open_24.xml | 5 + gradle/libs.versions.toml | 2 + 7 files changed, 169 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/drawable/baseline_menu_open_24.xml diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 01feabe..1177368 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -128,6 +128,8 @@ dependencies { implementation(libs.kotlinx.serialization.json) implementation(libs.androidx.lifecycle.runtime.compose) + implementation(libs.material) + implementation(libs.ramses.aar) testImplementation(libs.junit) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt index 26dedc9..63d4541 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt @@ -20,6 +20,7 @@ package org.eclipse.kuksa.companion.feature.home.view.navigation 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.NavigationBar @@ -45,7 +46,7 @@ fun HorizontalNavigationView( } Column(modifier) { - NavigationBar { + NavigationBar(Modifier.fillMaxWidth()) { NavigationPage.entries.forEachIndexed { index, page -> NavigationBarItem( selected = index == selectedItemIndex, diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt index 6570a57..40f2a01 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt @@ -19,7 +19,7 @@ package org.eclipse.kuksa.companion.feature.home.view.navigation -import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.size import androidx.compose.material3.Icon import androidx.compose.material3.NavigationRail @@ -30,6 +30,7 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview @@ -44,9 +45,11 @@ fun VerticalNavigationView( var selectedItemIndex by remember { mutableIntStateOf(viewModel.selectedNavigationIndex) } + val pages = NavigationPage.entries.toTypedArray() - Row(modifier) { - NavigationRail { + + Box(contentAlignment = Alignment.Center, modifier = modifier) { + NavigationRail(modifier) { pages.forEachIndexed { index, page -> NavigationRailItem( label = { Text(page.title) }, diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt index fe20515..69f0f84 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt @@ -56,7 +56,12 @@ fun AdaptiveSheetView( content = content, ) } else { - + SideSheetView( + modifier = modifier, + isBottomSheetEnabled = isBottomSheetEnabled, + sheetContent = sheetContent, + content = content, + ) } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt index 1d5b817..a10bcd7 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt @@ -19,21 +19,164 @@ package org.eclipse.kuksa.companion.feature.home.view.sheet +import android.graphics.Color +import android.widget.FrameLayout +import androidx.compose.foundation.ScrollState +import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.fillMaxHeight +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.verticalScroll +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Close +import androidx.compose.material3.FloatingActionButton +import androidx.compose.material3.Icon import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.ComposeView +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.R @Composable fun SideSheetView( modifier: Modifier = Modifier, + isBottomSheetEnabled: Boolean = true, + sheetContent: @Composable () -> Unit = {}, + content: @Composable (PaddingValues) -> Unit, +) { + var sideSheetBehavior: SideSheetBehavior? by remember { + mutableStateOf(null) + } + ConstraintLayout(modifier = modifier) { + Box(Modifier.fillMaxSize()) { + val paddingValues = PaddingValues(0.dp) + content(paddingValues) + } + if (isBottomSheetEnabled) { + SideSheetInteractionFAB( + sideSheetBehavior = sideSheetBehavior, + modifier = Modifier + .zIndex(2F) + .constrainAs(createRef()) { + end.linkTo(parent.end, 10.dp) + bottom.linkTo(parent.bottom, 10.dp) + }, + ) + + SideSheet( + sheetContent = sheetContent, + onSideSheetInitialised = { behavior -> + sideSheetBehavior = behavior + }, + modifier = Modifier + .zIndex(3F) + .fillMaxHeight() + .width(350.dp) + .constrainAs(createRef()) { + top.linkTo(parent.top) + end.linkTo(parent.end) + }, + ) + } + } +} + +@Composable +private fun SideSheet( sheetContent: @Composable () -> Unit, + onSideSheetInitialised: (SideSheetBehavior) -> Unit, + modifier: Modifier = Modifier, ) { + val sideSheetBehavior: SideSheetBehavior = SideSheetBehavior() + + AndroidView( + { context -> + val composeView = ComposeView(context).apply { + setContent { + Column { + Icon( + imageVector = Icons.Default.Close, + contentDescription = "Close SideSheet", + modifier = Modifier + .padding(top = 24.dp, end = 24.dp, bottom = 5.dp) + .clickable { + sideSheetBehavior.hide() + }.align(Alignment.End), + ) + Box( + modifier = Modifier + .fillMaxSize() + .verticalScroll(ScrollState(0)), + ) { + sheetContent() + } + } + } + } + + val frameLayout = FrameLayout(context) + .also { + it.setBackgroundColor(Color.WHITE) + } + frameLayout.addView(composeView) + + val coordinatorLayout = CoordinatorLayout(context) + coordinatorLayout.addView(frameLayout) + + val layoutParams = frameLayout.layoutParams as CoordinatorLayout.LayoutParams + layoutParams.behavior = sideSheetBehavior + + onSideSheetInitialised(sideSheetBehavior) + + coordinatorLayout + }, + modifier = modifier, + ) } -@Preview @Composable -private fun SideSheetViewPreview() { - SideSheetView { +private fun SideSheetInteractionFAB(sideSheetBehavior: SideSheetBehavior?, modifier: Modifier = Modifier) { + FloatingActionButton( + onClick = { + sideSheetBehavior?.state = SideSheetBehavior.STATE_EXPANDED + when (sideSheetBehavior?.state) { + SideSheetBehavior.STATE_EXPANDED -> sideSheetBehavior.hide() + SideSheetBehavior.STATE_HIDDEN -> sideSheetBehavior.expand() + else -> { + // ignored + } + } + }, + modifier = modifier, + ) { + Icon( + painter = painterResource(id = R.drawable.baseline_menu_open_24), + contentDescription = "Open SideSheet", + modifier = Modifier.size(30.dp), + ) } } + +@Preview +@Composable +private fun SideSheetViewPreview() { + SideSheetView(isBottomSheetEnabled = true, sheetContent = {}) {} +} diff --git a/app/src/main/res/drawable/baseline_menu_open_24.xml b/app/src/main/res/drawable/baseline_menu_open_24.xml new file mode 100644 index 0000000..8230fc9 --- /dev/null +++ b/app/src/main/res/drawable/baseline_menu_open_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index ef9bb04..3dac8fe 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -19,6 +19,7 @@ composeBom = "2023.10.01" jvmTarget = "17" kuksaSdk = "0.1.3" lifecycleRuntimeCompose = "2.7.0" +material = "1.11.0" material3WindowSizeClass = "1.1.2" ramsesAar = "1.1.0" navigationCompose = "2.7.6" @@ -47,6 +48,7 @@ kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serializa ktlint-compose-rules = { module = "com.twitter.compose.rules:ktlint", version.ref = "composeRules" } detekt-compose-rules = { module = "com.twitter.compose.rules:detekt", version.ref = "composeRules" } kuksa-sdk = { module = "org.eclipse.kuksa:kuksa-sdk", version.ref = "kuksaSdk" } +material = { module = "com.google.android.material:material", version.ref = "material" } vss-processor = { module = "org.eclipse.kuksa:vss-processor", version.ref = "kuksaSdk" } ramses-aar = { module = "io.github.bmwcarit:ramses-aar", version.ref = "ramsesAar" } From c30add3a6962a5b2e12a7ba000dfa919b329fb92 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 8 Feb 2024 12:26:11 +0100 Subject: [PATCH 15/28] chore: Fix Lint Findings --- .../eclipse/kuksa/companion/CompanionApplication.kt | 2 +- .../feature/connection/view/AnimatedLoadingText.kt | 4 ++-- .../connection/view/VerticalConnectionStatusView.kt | 3 --- .../companion/feature/door/view/DoorOverlayView.kt | 1 - .../companion/feature/home/view/AdaptiveAppScreen.kt | 1 - .../home/view/navigation/VerticalNavigationView.kt | 8 +++++--- .../feature/home/view/sheet/BottomSheetView.kt | 3 +-- .../companion/feature/home/view/sheet/SideSheetView.kt | 10 +++++++--- .../wheel/pressure/view/WheelPressureOverlayView.kt | 1 - .../org/eclipse/kuksa/companion/ramses/RamsesAnchor.kt | 1 - 10 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt index df31733..a603b2f 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt @@ -25,7 +25,7 @@ import dagger.hilt.android.HiltAndroidApp const val PREVIEW_WIDTH_DP = 400 const val PREVIEW_HEIGHT_DP = 900 -const val SHEET_EXPANDED_HEIGHT = 300 +const val SHEET_EXPANDED_HEIGHT = 350 const val SHEET_COLLAPSED_HEIGHT = 50 @HiltAndroidApp 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 index c26fd20..22271ab 100644 --- 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 @@ -26,7 +26,7 @@ import androidx.compose.runtime.remember import kotlinx.coroutines.delay import kotlin.time.Duration.Companion.milliseconds -private const val maxNumberDots = 3 +private const val MaxNumberDots = 3 private val DelayDuration = 500.milliseconds @Composable @@ -44,7 +44,7 @@ fun animateLoadingText( } LaunchedEffect(Unit) { while (true) { - if (numberOfDots.intValue < maxNumberDots) { + if (numberOfDots.intValue < MaxNumberDots) { numberOfDots.intValue += 1 } else { numberOfDots.intValue = 0 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 index 962e436..ae0c6d5 100644 --- 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 @@ -102,9 +102,6 @@ fun VerticalConnectionStatusView( } } - - - @Preview(heightDp = 300) @Composable private fun VerticalDisconnectedPreview() { diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt index 9135a3f..023a4b8 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/door/view/DoorOverlayView.kt @@ -45,7 +45,6 @@ import org.eclipse.kuksa.companion.ramses.PassengerBackDoorAnchor import org.eclipse.kuksa.companion.ramses.PassengerFrontDoorAnchor import org.eclipse.kuksa.companion.ramses.TrunkAnchor - @Composable fun DoorOverlayView( viewModel: DoorControlViewModel, 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 5bb0ed2..4a9bf3a 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 @@ -62,7 +62,6 @@ import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressur private const val ZINDEX_RAMSES_VIEW = 1F private const val ZINDEX_OVERLAY = 2F -private const val ZINDEX_CONTROL = 3F /** * Adds an adaptive AppScreen depending on the [WindowWidthSizeClass]. When the device has a [WindowWidthSizeClass] of diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt index 40f2a01..74dfb36 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt @@ -40,7 +40,7 @@ import androidx.compose.ui.unit.dp fun VerticalNavigationView( viewModel: NavigationViewModel, modifier: Modifier = Modifier, - onPageSelected: (NavigationPage) -> Unit = {}, + onPageSelected: (NavigationPage) -> Unit, ) { var selectedItemIndex by remember { mutableIntStateOf(viewModel.selectedNavigationIndex) @@ -49,7 +49,7 @@ fun VerticalNavigationView( val pages = NavigationPage.entries.toTypedArray() Box(contentAlignment = Alignment.Center, modifier = modifier) { - NavigationRail(modifier) { + NavigationRail { pages.forEachIndexed { index, page -> NavigationRailItem( label = { Text(page.title) }, @@ -77,5 +77,7 @@ fun VerticalNavigationView( @Composable private fun VerticalNavigationViewPreview() { val viewModel = NavigationViewModel() - VerticalNavigationView(viewModel) + VerticalNavigationView(viewModel) { + // not used in preview + } } diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt index 5acf0be..1b7799d 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt @@ -45,7 +45,7 @@ import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel fun BottomSheetView( modifier: Modifier = Modifier, initialSheetValue: SheetValue = SheetValue.PartiallyExpanded, - sheetContent: @Composable () -> Unit, + sheetContent: @Composable () -> Unit = {}, content: @Composable (PaddingValues) -> Unit, ) { val bottomSheetScaffoldState = BottomSheetScaffoldState( @@ -59,7 +59,6 @@ fun BottomSheetView( val sheetPeekHeight = if (initialSheetValue == SheetValue.Hidden) 0.dp else BottomSheetDefaults.SheetPeekHeight BottomSheetScaffold( - scaffoldState = bottomSheetScaffoldState, sheetContent = { sheetContent() diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt index a10bcd7..13ca253 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt @@ -53,6 +53,7 @@ import androidx.constraintlayout.compose.ConstraintLayout import androidx.coordinatorlayout.widget.CoordinatorLayout import com.google.android.material.sidesheet.SideSheetBehavior import org.eclipse.kuksa.companion.R +import org.eclipse.kuksa.companion.SHEET_EXPANDED_HEIGHT @Composable fun SideSheetView( @@ -86,9 +87,9 @@ fun SideSheetView( sideSheetBehavior = behavior }, modifier = Modifier - .zIndex(3F) + .zIndex(Float.MAX_VALUE) .fillMaxHeight() - .width(350.dp) + .width(SHEET_EXPANDED_HEIGHT.dp) .constrainAs(createRef()) { top.linkTo(parent.top) end.linkTo(parent.end) @@ -152,7 +153,10 @@ private fun SideSheet( } @Composable -private fun SideSheetInteractionFAB(sideSheetBehavior: SideSheetBehavior?, modifier: Modifier = Modifier) { +private fun SideSheetInteractionFAB( + sideSheetBehavior: SideSheetBehavior?, + modifier: Modifier = Modifier, +) { FloatingActionButton( onClick = { sideSheetBehavior?.state = SideSheetBehavior.STATE_EXPANDED diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt index dc4b56c..e61cf11 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/wheel/pressure/view/WheelPressureOverlayView.kt @@ -41,7 +41,6 @@ import org.eclipse.kuksa.companion.ramses.DriverBackDoorAnchor import org.eclipse.kuksa.companion.ramses.DriverFrontDoorAnchor import org.eclipse.kuksa.companion.ramses.PassengerBackDoorAnchor import org.eclipse.kuksa.companion.ramses.PassengerFrontDoorAnchor -import org.eclipse.kuksa.companion.ramses.TrunkAnchor @Composable fun WheelPressureOverlayView( diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/ramses/RamsesAnchor.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/ramses/RamsesAnchor.kt index c357131..02e06e3 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/ramses/RamsesAnchor.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/ramses/RamsesAnchor.kt @@ -132,4 +132,3 @@ class TrunkAnchor(windowSizeClass: WindowSizeClass, anchorPoint: ConstrainedLayo } } } - From 3db8d9d052df1912b26da0dd99a9d26440eac0cc Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 8 Feb 2024 13:17:58 +0100 Subject: [PATCH 16/28] chore: Disable KTLint Naming Rule KTLints property-naming rule is not compatible with compose. The official recommendation is to disable the rule, see: https://github.com/pinterest/ktlint/issues/2139 This should be okay, since we still have the detekt linter, which also checks for names in a more compose compatible way. --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index 5a4c813..c40d823 100644 --- a/.editorconfig +++ b/.editorconfig @@ -29,3 +29,4 @@ ktlint_standard_annotation = disabled # false positive with @JvmOverloads and de ktlint_function_naming_ignore_when_annotated_with = Composable ktlint_standard_multiline-expression-wrapping = disabled ktlint_standard_string-template-indent = disabled +ktlint_standard_property-naming = disabled \ No newline at end of file From 98d3520629d93654393d1e7f4b5d9d91abadf435 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 8 Feb 2024 14:03:15 +0100 Subject: [PATCH 17/28] chore: Keep Connection Alive on Orientation Change --- .../kuksa/companion/CompanionApplication.kt | 5 ++++- .../org/eclipse/kuksa/companion/MainActivity.kt | 17 ++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt index a603b2f..8551eba 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/CompanionApplication.kt @@ -21,6 +21,7 @@ package org.eclipse.kuksa.companion import android.app.Application import dagger.hilt.android.HiltAndroidApp +import org.eclipse.kuksa.DataBrokerConnection const val PREVIEW_WIDTH_DP = 400 const val PREVIEW_HEIGHT_DP = 900 @@ -29,4 +30,6 @@ const val SHEET_EXPANDED_HEIGHT = 350 const val SHEET_COLLAPSED_HEIGHT = 50 @HiltAndroidApp -class CompanionApplication : Application() +class CompanionApplication : Application() { + var dataBrokerConnection: DataBrokerConnection? = null +} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt index 38e6719..74652ed 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt @@ -68,6 +68,9 @@ import javax.inject.Inject @AndroidEntryPoint @VssDefinition("vss_rel_4.0.yaml") class MainActivity : ComponentActivity() { + private val companionApplication + get() = applicationContext as CompanionApplication + @Inject lateinit var connectionInfoRepository: ConnectionInfoRepository @@ -87,7 +90,13 @@ class MainActivity : ComponentActivity() { private val settingsViewModel: SettingsViewModel by viewModels() - private var dataBrokerConnection: DataBrokerConnection? = null + // storing the connection in the Application keeps the Connection alive on orientation changes + private var dataBrokerConnection: DataBrokerConnection? + get() = companionApplication.dataBrokerConnection + set(value) { + companionApplication.dataBrokerConnection = value + } + private val dataBrokerConnectorFactory = DataBrokerConnectorFactory() private val doorVehicleSurface = DoorVehicleSurface() @@ -289,6 +298,12 @@ class MainActivity : ComponentActivity() { } private fun connectToDataBroker(onConnected: () -> Unit = {}) { + // dataBrokerConnection is already established e.g. after an orientation change + if (dataBrokerConnection != null) { + onConnected() + return + } + lifecycleScope.launch { val connectionInfo = connectionInfoRepository.connectionInfoFlow.first() From c6a4bb858ffb517d251b87e168c351dd82dc5a62 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 8 Feb 2024 14:12:40 +0100 Subject: [PATCH 18/28] chore: Remove Legacy Code --- .../feature/home/view/sheet/AdaptiveLine.kt | 110 ----------------- .../home/view/sheet/AdaptiveSheetLayoutBak.kt | 116 ------------------ 2 files changed, 226 deletions(-) delete mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt delete mode 100644 app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayoutBak.kt diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt deleted file mode 100644 index 3f49e93..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveLine.kt +++ /dev/null @@ -1,110 +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.home.view.sheet - -import androidx.compose.foundation.background -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.Spacer -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.width -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.graphics.Color -import androidx.compose.ui.platform.LocalConfiguration -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.Dp -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 - -/** - * AdaptiveLine draws a line depending on the [WindowWidthSizeClass] of the device. If the device has a - * [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] it will draw a horizontal line, otherwise it will draw a - * horizontal line. - */ -@Composable -fun AdaptiveLine( - windowSizeClass: WindowSizeClass, - modifier: Modifier = Modifier, - length: Dp = 50.dp, - thickness: Dp = 4.dp, - color: Color = Color.LightGray, -) { - if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - HorizontalLine(modifier, length, thickness, color) - } else { - VerticalLine(modifier, length, thickness, color) - } -} - -@Composable -fun HorizontalLine( - modifier: Modifier = Modifier, - length: Dp = 50.dp, - thickness: Dp = 4.dp, - color: Color = Color.LightGray, -) { - Spacer( - modifier = modifier - .background(color) - .width(length) - .height(thickness), - ) -} - -@Composable -fun VerticalLine( - modifier: Modifier = Modifier, - length: Dp = 50.dp, - thickness: Dp = 4.dp, - color: Color = Color.LightGray, -) { - Spacer( - modifier = modifier - .background(color) - .width(thickness) - .height(length), - ) -} - -@Composable -@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) -@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) -private fun AdaptiveLinePreview() { - val windowSizeClass = LocalConfiguration.current.windowSizeClass - Box { - AdaptiveLine(windowSizeClass = windowSizeClass) - } -} - -@Composable -@Preview -private fun HorizontalLinePreview() { - HorizontalLine() -} - -@Composable -@Preview -private fun VerticalLinePreview() { - VerticalLine() -} diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayoutBak.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayoutBak.kt deleted file mode 100644 index 95dc5cc..0000000 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetLayoutBak.kt +++ /dev/null @@ -1,116 +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.home.view.sheet - -import androidx.compose.foundation.background -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Box -import androidx.compose.foundation.layout.fillMaxHeight -import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.width -import androidx.compose.material3.ExperimentalMaterial3Api -import androidx.compose.material3.windowsizeclass.WindowSizeClass -import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment -import androidx.compose.ui.Modifier -import androidx.compose.ui.graphics.Color -import androidx.compose.ui.platform.LocalConfiguration -import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.dp -import androidx.compose.ui.zIndex -import androidx.constraintlayout.compose.ConstraintLayout -import org.eclipse.kuksa.companion.PREVIEW_HEIGHT_DP -import org.eclipse.kuksa.companion.PREVIEW_WIDTH_DP -import org.eclipse.kuksa.companion.SHEET_COLLAPSED_HEIGHT -import org.eclipse.kuksa.companion.SHEET_EXPANDED_HEIGHT -import org.eclipse.kuksa.companion.extension.windowSizeClass - -/** - * AdaptiveSheetView adds a lash, which can be expanded on click to contain additional content. While it will be placed - * on the bottom for devices with a [WindowWidthSizeClass] of [WindowWidthSizeClass.Compact] it will be placed on the - * "end" for devices with a WindowWidthSizeClass which is higher. - */ -@Composable -fun AdaptiveSheetViewBak( - windowSizeClass: WindowSizeClass, - modifier: Modifier = Modifier, - sheetContent: @Composable () -> Unit, -) { - var isExpanded by remember { - mutableStateOf(false) - } - - ConstraintLayout(modifier = modifier.fillMaxSize()) { - val sheetRef = createRef() - - val sheetModifier = when (windowSizeClass.widthSizeClass) { - WindowWidthSizeClass.Compact -> { - Modifier - .height(if (isExpanded) SHEET_EXPANDED_HEIGHT.dp else SHEET_COLLAPSED_HEIGHT.dp) - .fillMaxWidth() - .zIndex(2F) - .clickable { isExpanded = !isExpanded } - .background(Color.White) - .constrainAs(sheetRef) { - bottom.linkTo(parent.bottom) - } - } - - else -> { - Modifier - .fillMaxHeight() - .width(if (isExpanded) SHEET_EXPANDED_HEIGHT.dp else SHEET_COLLAPSED_HEIGHT.dp) - .zIndex(2F) - .clickable { isExpanded = !isExpanded } - .background(Color.White) - .constrainAs(sheetRef) { - end.linkTo(parent.end) - } - } - } - - Box( - modifier = sheetModifier, - ) { - if (isExpanded) { - sheetContent() - } else { - AdaptiveLine(modifier = Modifier.align(Alignment.Center), windowSizeClass = windowSizeClass) - } - } - } -} - -@OptIn(ExperimentalMaterial3Api::class) -@Composable -@Preview(widthDp = PREVIEW_WIDTH_DP, heightDp = PREVIEW_HEIGHT_DP) -@Preview(widthDp = PREVIEW_HEIGHT_DP, heightDp = PREVIEW_WIDTH_DP) -private fun AdaptiveSheetViewPreview() { - val windowSizeClass = LocalConfiguration.current.windowSizeClass - AdaptiveSheetView(windowSizeClass) { - } -} From 46c86f2a2ad51cabec9bcb4af3e0ec42df6dec91 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 8 Feb 2024 14:50:33 +0100 Subject: [PATCH 19/28] chore: Remove onSideSheetInitialised Callback --- .../feature/home/view/sheet/SideSheetView.kt | 39 ++++++++----------- 1 file changed, 16 insertions(+), 23 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt index 13ca253..5b0c49f 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt @@ -37,10 +37,6 @@ import androidx.compose.material.icons.filled.Close import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.remember -import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.ComposeView @@ -62,9 +58,7 @@ fun SideSheetView( sheetContent: @Composable () -> Unit = {}, content: @Composable (PaddingValues) -> Unit, ) { - var sideSheetBehavior: SideSheetBehavior? by remember { - mutableStateOf(null) - } + val sideSheetBehavior: SideSheetBehavior = SideSheetBehavior() ConstraintLayout(modifier = modifier) { Box(Modifier.fillMaxSize()) { val paddingValues = PaddingValues(0.dp) @@ -83,9 +77,7 @@ fun SideSheetView( SideSheet( sheetContent = sheetContent, - onSideSheetInitialised = { behavior -> - sideSheetBehavior = behavior - }, + sideSheetBehavior = sideSheetBehavior, modifier = Modifier .zIndex(Float.MAX_VALUE) .fillMaxHeight() @@ -101,12 +93,10 @@ fun SideSheetView( @Composable private fun SideSheet( - sheetContent: @Composable () -> Unit, - onSideSheetInitialised: (SideSheetBehavior) -> Unit, + sideSheetBehavior: SideSheetBehavior, modifier: Modifier = Modifier, + sheetContent: @Composable () -> Unit, ) { - val sideSheetBehavior: SideSheetBehavior = SideSheetBehavior() - AndroidView( { context -> val composeView = ComposeView(context).apply { @@ -119,7 +109,8 @@ private fun SideSheet( .padding(top = 24.dp, end = 24.dp, bottom = 5.dp) .clickable { sideSheetBehavior.hide() - }.align(Alignment.End), + } + .align(Alignment.End), ) Box( modifier = Modifier @@ -133,18 +124,20 @@ private fun SideSheet( } val frameLayout = FrameLayout(context) - .also { - it.setBackgroundColor(Color.WHITE) + .apply { + setBackgroundColor(Color.WHITE) + addView(composeView) } - frameLayout.addView(composeView) val coordinatorLayout = CoordinatorLayout(context) - coordinatorLayout.addView(frameLayout) - - val layoutParams = frameLayout.layoutParams as CoordinatorLayout.LayoutParams - layoutParams.behavior = sideSheetBehavior + .apply { + addView(frameLayout) + } - onSideSheetInitialised(sideSheetBehavior) + (frameLayout.layoutParams as CoordinatorLayout.LayoutParams) + .apply { + behavior = sideSheetBehavior + } coordinatorLayout }, From 2b780a865ed72f12887a2eb9cc578192d1e43547 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 8 Feb 2024 14:51:11 +0100 Subject: [PATCH 20/28] chore: Remove Unused Resources --- app/src/main/res/values-land/values.xml | 3 --- app/src/main/res/values/values.xml | 3 --- 2 files changed, 6 deletions(-) diff --git a/app/src/main/res/values-land/values.xml b/app/src/main/res/values-land/values.xml index e5b873a..fbb4dea 100644 --- a/app/src/main/res/values-land/values.xml +++ b/app/src/main/res/values-land/values.xml @@ -21,7 +21,4 @@ 180 100 1000 - - 50 - 0 diff --git a/app/src/main/res/values/values.xml b/app/src/main/res/values/values.xml index b5a45d2..cb0b4da 100644 --- a/app/src/main/res/values/values.xml +++ b/app/src/main/res/values/values.xml @@ -21,7 +21,4 @@ 90 100 800 - - 0 - 50 From a3be81b0730c938ef43b125fa410995f805626e3 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Thu, 8 Feb 2024 14:57:57 +0100 Subject: [PATCH 21/28] chore: Change isBottomSheetEnabled to more generic isSheetEnabled --- .../kuksa/companion/feature/home/view/AdaptiveAppScreen.kt | 2 +- .../feature/home/view/navigation/NavigationPage.kt | 2 +- .../companion/feature/home/view/sheet/AdaptiveSheetView.kt | 6 +++--- .../companion/feature/home/view/sheet/SideSheetView.kt | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) 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 4a9bf3a..b434a5a 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 @@ -94,7 +94,7 @@ fun AdaptiveAppScreen( AdaptiveSheetView( windowSizeClass = windowSizeClass, modifier = Modifier.fillMaxSize(), - isBottomSheetEnabled = selectedPage.isBottomSheetEnabled, + isSheetEnabled = selectedPage.isSheetEnabled, sheetContent = { when (selectedPage) { NavigationPage.DOORS -> DoorControlView(doorControlViewModel) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt index aa9b2ba..da68fa3 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt @@ -26,7 +26,7 @@ enum class NavigationPage( @DrawableRes val iconRes: Int, val title: String, val description: String, - val isBottomSheetEnabled: Boolean, + val isSheetEnabled: Boolean, ) { DOORS( R.drawable.baseline_sensor_door_24, diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt index 69f0f84..62d7d6d 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt @@ -42,12 +42,12 @@ import org.eclipse.kuksa.companion.extension.windowSizeClass fun AdaptiveSheetView( windowSizeClass: WindowSizeClass, modifier: Modifier = Modifier, - isBottomSheetEnabled: Boolean = true, + isSheetEnabled: Boolean = true, sheetContent: @Composable () -> Unit = { }, content: @Composable (PaddingValues) -> Unit = { }, ) { if (windowSizeClass.widthSizeClass == WindowWidthSizeClass.Compact) { - val initialSheetValue = if (isBottomSheetEnabled) SheetValue.PartiallyExpanded else SheetValue.Hidden + val initialSheetValue = if (isSheetEnabled) SheetValue.PartiallyExpanded else SheetValue.Hidden BottomSheetView( modifier = modifier, @@ -58,7 +58,7 @@ fun AdaptiveSheetView( } else { SideSheetView( modifier = modifier, - isBottomSheetEnabled = isBottomSheetEnabled, + isSideSheetEnabled = isSheetEnabled, sheetContent = sheetContent, content = content, ) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt index 5b0c49f..4b46f66 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt @@ -54,7 +54,7 @@ import org.eclipse.kuksa.companion.SHEET_EXPANDED_HEIGHT @Composable fun SideSheetView( modifier: Modifier = Modifier, - isBottomSheetEnabled: Boolean = true, + isSideSheetEnabled: Boolean = true, sheetContent: @Composable () -> Unit = {}, content: @Composable (PaddingValues) -> Unit, ) { @@ -64,7 +64,7 @@ fun SideSheetView( val paddingValues = PaddingValues(0.dp) content(paddingValues) } - if (isBottomSheetEnabled) { + if (isSideSheetEnabled) { SideSheetInteractionFAB( sideSheetBehavior = sideSheetBehavior, modifier = Modifier @@ -175,5 +175,5 @@ private fun SideSheetInteractionFAB( @Preview @Composable private fun SideSheetViewPreview() { - SideSheetView(isBottomSheetEnabled = true, sheetContent = {}) {} + SideSheetView(isSideSheetEnabled = true, sheetContent = {}) {} } From 6caf440f869eec54d4c6eb9b88ac5a90a26cfc56 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Fri, 9 Feb 2024 09:36:35 +0100 Subject: [PATCH 22/28] chore: Center NavigationRail --- .../view/navigation/VerticalNavigationView.kt | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt index 74dfb36..e1d74b3 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt @@ -19,7 +19,7 @@ package org.eclipse.kuksa.companion.feature.home.view.navigation -import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.size import androidx.compose.material3.Icon import androidx.compose.material3.NavigationRail @@ -30,7 +30,6 @@ import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.setValue -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview @@ -48,28 +47,28 @@ fun VerticalNavigationView( val pages = NavigationPage.entries.toTypedArray() - Box(contentAlignment = Alignment.Center, modifier = modifier) { - NavigationRail { - pages.forEachIndexed { index, page -> - NavigationRailItem( - label = { Text(page.title) }, - icon = { - Icon( - painterResource(id = page.iconRes), - contentDescription = page.title, - modifier = Modifier.size(30.dp), - ) - }, - selected = selectedItemIndex == index, - onClick = { - selectedItemIndex = index - viewModel.selectedNavigationIndex = index - viewModel.selectedNavigationPage = page - onPageSelected(page) - }, - ) - } + NavigationRail(modifier) { + Spacer(Modifier.weight(1f)) + pages.forEachIndexed { index, page -> + NavigationRailItem( + label = { Text(page.title) }, + icon = { + Icon( + painterResource(id = page.iconRes), + contentDescription = page.title, + modifier = Modifier.size(30.dp), + ) + }, + selected = selectedItemIndex == index, + onClick = { + selectedItemIndex = index + viewModel.selectedNavigationIndex = index + viewModel.selectedNavigationPage = page + onPageSelected(page) + }, + ) } + Spacer(Modifier.weight(1f)) } } From 696eec96e559698077dea788dbf662e0acb2bab0 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Fri, 9 Feb 2024 10:29:13 +0100 Subject: [PATCH 23/28] chore: Add Rounded Corner to SideSheet --- .../feature/home/view/sheet/SideSheetView.kt | 4 +-- app/src/main/res/drawable/rounded_shape.xml | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/drawable/rounded_shape.xml diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt index 4b46f66..e212d22 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt @@ -19,8 +19,8 @@ package org.eclipse.kuksa.companion.feature.home.view.sheet -import android.graphics.Color import android.widget.FrameLayout +import androidx.appcompat.content.res.AppCompatResources import androidx.compose.foundation.ScrollState import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.Box @@ -125,7 +125,7 @@ private fun SideSheet( val frameLayout = FrameLayout(context) .apply { - setBackgroundColor(Color.WHITE) + background = AppCompatResources.getDrawable(context, R.drawable.rounded_shape) addView(composeView) } diff --git a/app/src/main/res/drawable/rounded_shape.xml b/app/src/main/res/drawable/rounded_shape.xml new file mode 100644 index 0000000..43b777a --- /dev/null +++ b/app/src/main/res/drawable/rounded_shape.xml @@ -0,0 +1,25 @@ + + + + + + From 21426777ec0eda039b9b5f97750ad7578e6c9356 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Fri, 9 Feb 2024 10:40:56 +0100 Subject: [PATCH 24/28] chore: Change Navigation Labels and add Padding --- .../feature/home/view/navigation/NavigationPage.kt | 8 ++++---- .../home/view/navigation/VerticalNavigationView.kt | 7 ++++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt index da68fa3..15281c6 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt @@ -30,25 +30,25 @@ enum class NavigationPage( ) { DOORS( R.drawable.baseline_sensor_door_24, - "Door Control", + "Doors", "Show status of the doors and trunk, (un-)lock and open/close them", true, ), TEMPERATURE( R.drawable.baseline_device_thermostat_24, - "Temperature Control", + "Temperatures", "Check the temperature inside the car, increase or decrease the temperature. ", true, ), LIGHT( R.drawable.baseline_light_mode_24, - "Light Control", + "Lights", "Check the status of the light, turn them on and off to check their functionality", true, ), WHEELS( R.drawable.baseline_sports_volleyball_24, - "Wheel Pressure", + "Wheels", "Check the pressure of the wheels", false, ), diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt index e1d74b3..5e08057 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt @@ -20,6 +20,7 @@ package org.eclipse.kuksa.companion.feature.home.view.navigation 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.NavigationRail @@ -35,6 +36,9 @@ import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +private val IconSize = 30.dp +private val Padding = 5.dp + @Composable fun VerticalNavigationView( viewModel: NavigationViewModel, @@ -56,7 +60,7 @@ fun VerticalNavigationView( Icon( painterResource(id = page.iconRes), contentDescription = page.title, - modifier = Modifier.size(30.dp), + modifier = Modifier.size(IconSize), ) }, selected = selectedItemIndex == index, @@ -66,6 +70,7 @@ fun VerticalNavigationView( viewModel.selectedNavigationPage = page onPageSelected(page) }, + modifier = Modifier.padding(start = Padding, end = Padding), ) } Spacer(Modifier.weight(1f)) From f0088e3c8e80d0975ef44260be65a9a3d01c8d95 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Fri, 9 Feb 2024 11:35:23 +0100 Subject: [PATCH 25/28] chore: Correctly Register DisconnectListener on Orientation Change --- .../kotlin/org/eclipse/kuksa/companion/MainActivity.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt index 74652ed..401acdc 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt @@ -77,6 +77,7 @@ class MainActivity : ComponentActivity() { private lateinit var doorVehicleScene: DoorVehicleScene private val disconnectListener = DisconnectListener { + dataBrokerConnection = null connectionStatusViewModel.connectionState = ConnectionState.DISCONNECTED } @@ -264,6 +265,8 @@ class MainActivity : ComponentActivity() { private fun subscribe() { dataBrokerConnection?.apply { + disconnectListeners.register(disconnectListener) + subscribe(VssDoor(), listener = vssDoorListener) subscribe(VssTrunk(), listener = vssTrunkListener) subscribe(VssHvac(), listener = vssTemperatureListener) @@ -313,9 +316,7 @@ class MainActivity : ComponentActivity() { connectionStatusViewModel.connectionState = ConnectionState.CONNECTING val context = this@MainActivity val dataBrokerConnector = dataBrokerConnectorFactory.create(context, connectionInfo) - dataBrokerConnection = dataBrokerConnector.connect().apply { - disconnectListeners.register(disconnectListener) - } + dataBrokerConnection = dataBrokerConnector.connect() connectionStatusViewModel.connectionState = ConnectionState.CONNECTED onConnected() } catch (e: DataBrokerException) { From 7ecb21c584c755fc0b18146c4a96d9baf0384b24 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Fri, 9 Feb 2024 15:24:07 +0100 Subject: [PATCH 26/28] chore: Align Feature Folder Structure - add feature folder for Navigation and (Side-)/(Bottom-)Sheet --- .../kotlin/org/eclipse/kuksa/companion/MainActivity.kt | 2 +- .../eclipse/kuksa/companion/extension/StringExtension.kt | 2 +- .../connection/view/VerticalConnectionStatusView.kt | 4 ++-- .../companion/feature/home/view/AdaptiveAppScreen.kt | 8 ++++---- .../feature/{home/view => }/navigation/NavigationPage.kt | 2 +- .../view}/AdaptiveNavigationView.kt | 4 +++- .../view}/HorizontalNavigationView.kt | 4 +++- .../view}/VerticalNavigationView.kt | 4 +++- .../viewmodel}/NavigationViewModel.kt | 3 ++- .../{home/view/sheet => sheet/view}/AdaptiveSheetView.kt | 2 +- .../{home/view/sheet => sheet/view}/BottomSheetView.kt | 2 +- .../{home/view/sheet => sheet/view}/SideSheetView.kt | 4 +++- 12 files changed, 25 insertions(+), 16 deletions(-) rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/{home/view => }/navigation/NavigationPage.kt (96%) rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/{home/view/navigation => navigation/view}/AdaptiveNavigationView.kt (91%) rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/{home/view/navigation => navigation/view}/HorizontalNavigationView.kt (92%) rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/{home/view/navigation => navigation/view}/VerticalNavigationView.kt (93%) rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/{home/view/navigation => navigation/viewmodel}/NavigationViewModel.kt (88%) rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/{home/view/sheet => sheet/view}/AdaptiveSheetView.kt (97%) rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/{home/view/sheet => sheet/view}/BottomSheetView.kt (98%) rename app/src/main/kotlin/org/eclipse/kuksa/companion/feature/{home/view/sheet => sheet/view}/SideSheetView.kt (96%) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt index 401acdc..5da88b2 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt @@ -46,7 +46,7 @@ import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.C import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.Companion.TRUNK_CLOSED import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.Companion.TRUNK_OPEN import org.eclipse.kuksa.companion.feature.home.view.AdaptiveAppScreen -import org.eclipse.kuksa.companion.feature.home.view.navigation.NavigationViewModel +import org.eclipse.kuksa.companion.feature.navigation.viewmodel.NavigationViewModel import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel import org.eclipse.kuksa.companion.feature.settings.viewModel.SettingsViewModel import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel 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 index ce7141b..1d4298f 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/StringExtension.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/extension/StringExtension.kt @@ -19,7 +19,7 @@ package org.eclipse.kuksa.companion.extension -fun String.convertToVerticalString(): String { +fun String.toVertical(): String { if (isEmpty()) return this val charArray = toCharArray() 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 index ae0c6d5..2695fd2 100644 --- 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 @@ -39,7 +39,7 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.constraintlayout.compose.ConstraintLayout import org.eclipse.kuksa.companion.R -import org.eclipse.kuksa.companion.extension.convertToVerticalString +import org.eclipse.kuksa.companion.extension.toVertical import org.eclipse.kuksa.companion.extension.isVisible import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel @@ -69,7 +69,7 @@ fun VerticalConnectionStatusView( val (textRef, imageRef) = createRefs() Text( - text = text.convertToVerticalString(), + text = text.toVertical(), color = Color.White, textAlign = TextAlign.Center, fontWeight = FontWeight.Bold, 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 b434a5a..bd9c73f 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 @@ -45,10 +45,10 @@ import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatus 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 -import org.eclipse.kuksa.companion.feature.home.view.navigation.AdaptiveNavigationView -import org.eclipse.kuksa.companion.feature.home.view.navigation.NavigationPage -import org.eclipse.kuksa.companion.feature.home.view.navigation.NavigationViewModel -import org.eclipse.kuksa.companion.feature.home.view.sheet.AdaptiveSheetView +import org.eclipse.kuksa.companion.feature.navigation.view.AdaptiveNavigationView +import org.eclipse.kuksa.companion.feature.navigation.NavigationPage +import org.eclipse.kuksa.companion.feature.navigation.viewmodel.NavigationViewModel +import org.eclipse.kuksa.companion.feature.sheet.view.AdaptiveSheetView import org.eclipse.kuksa.companion.feature.light.view.LightControlView import org.eclipse.kuksa.companion.feature.light.view.LightOverlayView import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/NavigationPage.kt similarity index 96% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/NavigationPage.kt index 15281c6..39159c3 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationPage.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/NavigationPage.kt @@ -17,7 +17,7 @@ * */ -package org.eclipse.kuksa.companion.feature.home.view.navigation +package org.eclipse.kuksa.companion.feature.navigation import androidx.annotation.DrawableRes import org.eclipse.kuksa.companion.R diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/AdaptiveNavigationView.kt similarity index 91% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/AdaptiveNavigationView.kt index 1f577e5..aae5eee 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/AdaptiveNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/AdaptiveNavigationView.kt @@ -17,7 +17,7 @@ * */ -package org.eclipse.kuksa.companion.feature.home.view.navigation +package org.eclipse.kuksa.companion.feature.navigation.view import androidx.compose.material3.windowsizeclass.WindowSizeClass import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass @@ -28,6 +28,8 @@ import androidx.compose.ui.tooling.preview.Preview 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.navigation.NavigationPage +import org.eclipse.kuksa.companion.feature.navigation.viewmodel.NavigationViewModel /** * AdaptiveNavigationView will add depending on the [WindowWidthSizeClass] of the device a horizontal or vertical diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/HorizontalNavigationView.kt similarity index 92% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/HorizontalNavigationView.kt index 63d4541..e50d757 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/HorizontalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/HorizontalNavigationView.kt @@ -17,7 +17,7 @@ * */ -package org.eclipse.kuksa.companion.feature.home.view.navigation +package org.eclipse.kuksa.companion.feature.navigation.view import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxWidth @@ -34,6 +34,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import org.eclipse.kuksa.companion.feature.navigation.NavigationPage +import org.eclipse.kuksa.companion.feature.navigation.viewmodel.NavigationViewModel @Composable fun HorizontalNavigationView( diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/VerticalNavigationView.kt similarity index 93% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/VerticalNavigationView.kt index 5e08057..61674a9 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/VerticalNavigationView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/view/VerticalNavigationView.kt @@ -17,7 +17,7 @@ * */ -package org.eclipse.kuksa.companion.feature.home.view.navigation +package org.eclipse.kuksa.companion.feature.navigation.view import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding @@ -35,6 +35,8 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.dp +import org.eclipse.kuksa.companion.feature.navigation.NavigationPage +import org.eclipse.kuksa.companion.feature.navigation.viewmodel.NavigationViewModel private val IconSize = 30.dp private val Padding = 5.dp diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationViewModel.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/viewmodel/NavigationViewModel.kt similarity index 88% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationViewModel.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/viewmodel/NavigationViewModel.kt index 0bd23fd..f95693b 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/navigation/NavigationViewModel.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/navigation/viewmodel/NavigationViewModel.kt @@ -17,13 +17,14 @@ * */ -package org.eclipse.kuksa.companion.feature.home.view.navigation +package org.eclipse.kuksa.companion.feature.navigation.viewmodel import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.setValue import androidx.lifecycle.ViewModel +import org.eclipse.kuksa.companion.feature.navigation.NavigationPage class NavigationViewModel : ViewModel() { var selectedNavigationIndex by mutableIntStateOf(0) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/AdaptiveSheetView.kt similarity index 97% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/AdaptiveSheetView.kt index 62d7d6d..7b33b42 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/AdaptiveSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/AdaptiveSheetView.kt @@ -17,7 +17,7 @@ * */ -package org.eclipse.kuksa.companion.feature.home.view.sheet +package org.eclipse.kuksa.companion.feature.sheet.view import androidx.compose.foundation.layout.PaddingValues import androidx.compose.material3.ExperimentalMaterial3Api diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/BottomSheetView.kt similarity index 98% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/BottomSheetView.kt index 1b7799d..b2ed678 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/BottomSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/BottomSheetView.kt @@ -17,7 +17,7 @@ * */ -package org.eclipse.kuksa.companion.feature.home.view.sheet +package org.eclipse.kuksa.companion.feature.sheet.view import android.app.Application import androidx.compose.foundation.layout.PaddingValues diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/SideSheetView.kt similarity index 96% rename from app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt rename to app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/SideSheetView.kt index e212d22..9c1fa94 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/home/view/sheet/SideSheetView.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/feature/sheet/view/SideSheetView.kt @@ -17,7 +17,7 @@ * */ -package org.eclipse.kuksa.companion.feature.home.view.sheet +package org.eclipse.kuksa.companion.feature.sheet.view import android.widget.FrameLayout import androidx.appcompat.content.res.AppCompatResources @@ -97,6 +97,8 @@ private fun SideSheet( modifier: Modifier = Modifier, sheetContent: @Composable () -> Unit, ) { + // replace with Compose Side-Sheet once it is released: + // https://m3.material.io/components/side-sheets/overview#32f078ba-e45e-40be-a66b-f04814fabf7a AndroidView( { context -> val composeView = ComposeView(context).apply { From 7b6fbb3164084253e3f5ee0d2d77d5e97d043f7f Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Fri, 9 Feb 2024 15:52:42 +0100 Subject: [PATCH 27/28] chore: Use Early Return if SideSheet is disabled --- .../feature/sheet/view/SideSheetView.kt | 47 ++++++++++--------- 1 file changed, 25 insertions(+), 22 deletions(-) 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 9c1fa94..1936afa 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 @@ -64,30 +64,33 @@ fun SideSheetView( val paddingValues = PaddingValues(0.dp) content(paddingValues) } - if (isSideSheetEnabled) { - SideSheetInteractionFAB( - sideSheetBehavior = sideSheetBehavior, - modifier = Modifier - .zIndex(2F) - .constrainAs(createRef()) { - end.linkTo(parent.end, 10.dp) - bottom.linkTo(parent.bottom, 10.dp) - }, - ) - SideSheet( - sheetContent = sheetContent, - sideSheetBehavior = sideSheetBehavior, - modifier = Modifier - .zIndex(Float.MAX_VALUE) - .fillMaxHeight() - .width(SHEET_EXPANDED_HEIGHT.dp) - .constrainAs(createRef()) { - top.linkTo(parent.top) - end.linkTo(parent.end) - }, - ) + if (!isSideSheetEnabled) { + return@ConstraintLayout } + + SideSheetInteractionFAB( + sideSheetBehavior = sideSheetBehavior, + modifier = Modifier + .zIndex(2F) + .constrainAs(createRef()) { + end.linkTo(parent.end, 10.dp) + bottom.linkTo(parent.bottom, 10.dp) + }, + ) + + SideSheet( + sheetContent = sheetContent, + sideSheetBehavior = sideSheetBehavior, + modifier = Modifier + .zIndex(Float.MAX_VALUE) + .fillMaxHeight() + .width(SHEET_EXPANDED_HEIGHT.dp) + .constrainAs(createRef()) { + top.linkTo(parent.top) + end.linkTo(parent.end) + }, + ) } } From a2927eda3d3edeff3ecc8452cfb81e13fbbdffe4 Mon Sep 17 00:00:00 2001 From: Andre Weber Date: Mon, 12 Feb 2024 08:16:28 +0100 Subject: [PATCH 28/28] chore: Align Subscribe and Unsubscribe --- .../kotlin/org/eclipse/kuksa/companion/MainActivity.kt | 4 +++- .../connection/view/VerticalConnectionStatusView.kt | 2 +- .../companion/feature/home/view/AdaptiveAppScreen.kt | 8 ++++---- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt index 5da88b2..4b4ffb8 100644 --- a/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt +++ b/app/src/main/kotlin/org/eclipse/kuksa/companion/MainActivity.kt @@ -46,8 +46,8 @@ import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.C import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.Companion.TRUNK_CLOSED import org.eclipse.kuksa.companion.feature.door.viewModel.DoorControlViewModel.Companion.TRUNK_OPEN import org.eclipse.kuksa.companion.feature.home.view.AdaptiveAppScreen -import org.eclipse.kuksa.companion.feature.navigation.viewmodel.NavigationViewModel import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel +import org.eclipse.kuksa.companion.feature.navigation.viewmodel.NavigationViewModel import org.eclipse.kuksa.companion.feature.settings.viewModel.SettingsViewModel import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel import org.eclipse.kuksa.companion.feature.wheel.pressure.viewmodel.WheelPressureViewModel @@ -277,6 +277,8 @@ class MainActivity : ComponentActivity() { private fun unsubscribe() { dataBrokerConnection?.apply { + disconnectListeners.unregister(disconnectListener) + unsubscribe(VssDoor(), listener = vssDoorListener) unsubscribe(VssTrunk(), listener = vssTrunkListener) unsubscribe(VssHvac(), listener = vssTemperatureListener) 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 index 2695fd2..69f1c6b 100644 --- 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 @@ -39,8 +39,8 @@ import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.tooling.preview.Preview import androidx.constraintlayout.compose.ConstraintLayout import org.eclipse.kuksa.companion.R -import org.eclipse.kuksa.companion.extension.toVertical import org.eclipse.kuksa.companion.extension.isVisible +import org.eclipse.kuksa.companion.extension.toVertical import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatusViewModel @Composable 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 bd9c73f..09f4f44 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 @@ -45,15 +45,15 @@ import org.eclipse.kuksa.companion.feature.connection.viewModel.ConnectionStatus 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 -import org.eclipse.kuksa.companion.feature.navigation.view.AdaptiveNavigationView -import org.eclipse.kuksa.companion.feature.navigation.NavigationPage -import org.eclipse.kuksa.companion.feature.navigation.viewmodel.NavigationViewModel -import org.eclipse.kuksa.companion.feature.sheet.view.AdaptiveSheetView import org.eclipse.kuksa.companion.feature.light.view.LightControlView import org.eclipse.kuksa.companion.feature.light.view.LightOverlayView import org.eclipse.kuksa.companion.feature.light.viewmodel.LightControlViewModel +import org.eclipse.kuksa.companion.feature.navigation.NavigationPage +import org.eclipse.kuksa.companion.feature.navigation.view.AdaptiveNavigationView +import org.eclipse.kuksa.companion.feature.navigation.viewmodel.NavigationViewModel import org.eclipse.kuksa.companion.feature.settings.view.SettingsView import org.eclipse.kuksa.companion.feature.settings.viewModel.SettingsViewModel +import org.eclipse.kuksa.companion.feature.sheet.view.AdaptiveSheetView import org.eclipse.kuksa.companion.feature.temperature.view.TemperatureControlView import org.eclipse.kuksa.companion.feature.temperature.view.TemperatureOverlayView import org.eclipse.kuksa.companion.feature.temperature.viewmodel.TemperatureViewModel