From 4bbba45d49cc88d494b84668f36cf7a91ab0ee51 Mon Sep 17 00:00:00 2001 From: mezhendosina Date: Wed, 21 Jun 2023 14:34:43 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BD=D0=B0=D0=B2=D0=B8=D0=B3=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ru/nm17/narodmon/ui/navHost/MainScreen.kt | 92 +++++++++++++++++++ .../narodmon/ui/navHost/MainScreenSealed.kt | 23 +++++ .../ui/webCamsScreen/WebCamsScreen.kt | 6 +- 3 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/ru/nm17/narodmon/ui/navHost/MainScreen.kt create mode 100644 app/src/main/java/ru/nm17/narodmon/ui/navHost/MainScreenSealed.kt diff --git a/app/src/main/java/ru/nm17/narodmon/ui/navHost/MainScreen.kt b/app/src/main/java/ru/nm17/narodmon/ui/navHost/MainScreen.kt new file mode 100644 index 0000000..a8af55f --- /dev/null +++ b/app/src/main/java/ru/nm17/narodmon/ui/navHost/MainScreen.kt @@ -0,0 +1,92 @@ +package ru.nm17.narodmon.ui.navHost + +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Menu +import androidx.compose.material3.Icon +import androidx.compose.material3.NavigationBar +import androidx.compose.material3.NavigationBarItem +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.tooling.preview.Preview +import androidx.navigation.NavController +import androidx.navigation.NavDestination.Companion.hierarchy +import androidx.navigation.NavGraph.Companion.findStartDestination +import androidx.navigation.compose.NavHost +import androidx.navigation.compose.composable +import androidx.navigation.compose.currentBackStackEntryAsState +import androidx.navigation.compose.rememberNavController +import ru.nm17.narodmon.ui.messages.MessagesScreen +import ru.nm17.narodmon.ui.sensorsScreen.SensorsScreen +import ru.nm17.narodmon.ui.settings.SettingsScreen +import ru.nm17.narodmon.ui.theme.NarodMonTheme +import ru.nm17.narodmon.ui.webCamsScreen.WebCamsScreen + + +val items = listOf( + MainScreenSealed.Sensors, + MainScreenSealed.Webcams, + MainScreenSealed.Messages +) + +@Composable +fun MainScreen(outerNavController: NavController) { + val navController = rememberNavController() + + Scaffold( + bottomBar = { + NavigationBar { + + items.forEach { screen -> + NavigationBarItem( + selected = navController.currentDestination?.route == screen.route, + onClick = { + navController.navigate(screen.route) { + popUpTo(navController.graph.findStartDestination().id) { + saveState = true + } + launchSingleTop = true + restoreState = true + } + }, + label = { Text(text = stringResource(id = screen.resourceId)) }, + icon = { + Icon( + painter = painterResource(id = screen.iconId), + contentDescription = "" + ) + }) + } + } + }, + modifier = Modifier.fillMaxSize() + ) { + NavHost( + navController, + startDestination = MainScreenSealed.Sensors.route, + Modifier.padding(it) + ) { + composable(MainScreenSealed.Sensors.route) { + SensorsScreen(navController) { + outerNavController.navigate("settings") + } + } + composable(MainScreenSealed.Webcams.route) { WebCamsScreen(navController) } + composable(MainScreenSealed.Messages.route) { } + } + } +} + +@Preview +@Composable +fun PreviewMainScreen() { + NarodMonTheme { + MainScreen(rememberNavController()) + } +} \ No newline at end of file diff --git a/app/src/main/java/ru/nm17/narodmon/ui/navHost/MainScreenSealed.kt b/app/src/main/java/ru/nm17/narodmon/ui/navHost/MainScreenSealed.kt new file mode 100644 index 0000000..0dd0636 --- /dev/null +++ b/app/src/main/java/ru/nm17/narodmon/ui/navHost/MainScreenSealed.kt @@ -0,0 +1,23 @@ +package ru.nm17.narodmon.ui.navHost + +import android.widget.ImageView +import androidx.annotation.DrawableRes +import androidx.annotation.StringRes +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Home +import androidx.compose.material.icons.filled.Menu +import androidx.compose.ui.graphics.vector.ImageVector +import ru.nm17.narodmon.R + +sealed class MainScreenSealed( + val route: String, + @StringRes val resourceId: Int, + @DrawableRes val iconId: Int +) { + object Sensors : MainScreenSealed("sensors", R.string.sensors_page_title, R.drawable.ic_home) + object Webcams : MainScreenSealed("webcams", R.string.webcams, R.drawable.ic_webcam) + + object Messages : MainScreenSealed("messages", R.string.messages, R.drawable.ic_message) + + object Settings : MainScreenSealed("settings", R.string.settings, R.drawable.ic_settings) +} \ No newline at end of file diff --git a/app/src/main/java/ru/nm17/narodmon/ui/webCamsScreen/WebCamsScreen.kt b/app/src/main/java/ru/nm17/narodmon/ui/webCamsScreen/WebCamsScreen.kt index 98298b9..0bdbcc9 100644 --- a/app/src/main/java/ru/nm17/narodmon/ui/webCamsScreen/WebCamsScreen.kt +++ b/app/src/main/java/ru/nm17/narodmon/ui/webCamsScreen/WebCamsScreen.kt @@ -11,10 +11,12 @@ import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.viewinterop.AndroidView +import androidx.navigation.NavController +import androidx.navigation.compose.rememberNavController import ru.nm17.narodmon.ui.theme.NarodMonTheme @Composable -fun WebCamsScreen() { +fun WebCamsScreen(navController: NavController) { var webCams by remember { mutableStateOf( @@ -58,6 +60,6 @@ fun WebCamsScreen() { @Composable fun PreviewWebCams() { NarodMonTheme { - WebCamsScreen() + WebCamsScreen(rememberNavController()) } } \ No newline at end of file