From 1998931a98d5cdfe481b8faed49d861e4547e5f6 Mon Sep 17 00:00:00 2001 From: mezhendosina Date: Wed, 21 Jun 2023 14:33:49 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B1=D1=80=D0=B0=D0=BB=20AppHavHost=20?= =?UTF-8?q?=D0=B2=20=D0=BE=D1=82=D0=B4=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/ru/nm17/narodmon/MainActivity.kt | 43 +---------------- .../ru/nm17/narodmon/ui/navHost/AppNavHost.kt | 46 +++++++++++++++++++ 2 files changed, 48 insertions(+), 41 deletions(-) create mode 100644 app/src/main/java/ru/nm17/narodmon/ui/navHost/AppNavHost.kt diff --git a/app/src/main/java/ru/nm17/narodmon/MainActivity.kt b/app/src/main/java/ru/nm17/narodmon/MainActivity.kt index 72011a6..6216071 100644 --- a/app/src/main/java/ru/nm17/narodmon/MainActivity.kt +++ b/app/src/main/java/ru/nm17/narodmon/MainActivity.kt @@ -47,50 +47,12 @@ import kotlinx.coroutines.launch import ru.nm17.narodmon.db.AppDatabase import ru.nm17.narodmon.db.entities.KVSetting import ru.nm17.narodmon.ui.dialogs.AgreementDialog +import ru.nm17.narodmon.ui.navHost.AppNavHost +import ru.nm17.narodmon.ui.navHost.MainScreen import ru.nm17.narodmon.ui.sensorsScreen.SensorsScreen import ru.nm17.narodmon.ui.theme.NarodMonTheme -@OptIn(ExperimentalMaterial3Api::class) -@Composable -fun AppNavHost() { - val navController = rememberNavController() - val coScope = rememberCoroutineScope() - NavHost(navController = navController, startDestination = "sensors") { - composable("agreement") { - - } - - composable("sensors") { - Scaffold(bottomBar = { - BottomAppBar(actions = { - Image( - Icons.Rounded.Menu, - contentDescription = null - ) - }, floatingActionButton = { - FloatingActionButton(onClick = { /*TODO*/ }) { - Image( - Icons.Rounded.Add, - contentDescription = "" - ) - } - }, - contentPadding = PaddingValues(start = 16.dp) - ) - }) { - Column(modifier = Modifier.padding(it)) { - SensorsScreen(navController) - } - } - - } - } - - /*...*/ - -} - class MainActivity : ComponentActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -153,7 +115,6 @@ class MainActivity : ComponentActivity() { } } else { AppNavHost() - } // A surface container using the 'background' color from the theme diff --git a/app/src/main/java/ru/nm17/narodmon/ui/navHost/AppNavHost.kt b/app/src/main/java/ru/nm17/narodmon/ui/navHost/AppNavHost.kt new file mode 100644 index 0000000..25bb97d --- /dev/null +++ b/app/src/main/java/ru/nm17/narodmon/ui/navHost/AppNavHost.kt @@ -0,0 +1,46 @@ +package ru.nm17.narodmon.ui.navHost + +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.PaddingValues +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Add +import androidx.compose.material.icons.rounded.Menu +import androidx.compose.material3.BottomAppBar +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.FloatingActionButton +import androidx.compose.material3.Scaffold +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.ui.Modifier +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +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.sensorsScreen.SensorsScreen +import ru.nm17.narodmon.ui.settings.SettingsScreen + + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun AppNavHost() { + val navController = rememberNavController() + NavHost(navController = navController, startDestination = "main") { + composable("main") { + MainScreen(navController) + } + composable("settings") { + SettingsScreen() + } + } +} + +@Preview +@Composable +fun PreviewAppNavHost() { + AppNavHost() +}