diff --git a/app/src/main/java/com/example/mobileapp/MainActivity.kt b/app/src/main/java/com/example/mobileapp/MainActivity.kt index 25833de..8105863 100644 --- a/app/src/main/java/com/example/mobileapp/MainActivity.kt +++ b/app/src/main/java/com/example/mobileapp/MainActivity.kt @@ -1,30 +1,24 @@ package com.example.mobileapp import android.os.Bundle +import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent -import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Modifier import androidx.navigation.NavHostController -import androidx.navigation.compose.NavHost -import androidx.navigation.compose.composable +import androidx.navigation.compose.currentBackStackEntryAsState import androidx.navigation.compose.rememberNavController +import com.example.mobileapp.components.NavBar import com.example.mobileapp.entities.Mail import com.example.mobileapp.entities.MailSingleton import com.example.mobileapp.entities.Story import com.example.mobileapp.entities.StorySingleton -import com.example.mobileapp.screens.Authorization -import com.example.mobileapp.screens.EditMailScreen -import com.example.mobileapp.screens.EditStoryScreen -import com.example.mobileapp.screens.ListDataScreen -import com.example.mobileapp.screens.ListMailScreen -import com.example.mobileapp.screens.MainScreen -import com.example.mobileapp.screens.Registration -import com.example.mobileapp.screens.SettingsScreen import com.example.mobileapp.ui.theme.MobileAppTheme class MainActivity : ComponentActivity() { @@ -54,41 +48,9 @@ class MainActivity : ComponentActivity() { storySingleton.addStory(Story(2, "Чужак", "Знаменитая книга стивена кинга", R.drawable.king)) storySingleton.addStory(Story(3, "Переулок", "История ужасов от Дзюнзи Ито", R.drawable.dzun)) - AppNavigation(navController = navController) + NavBar(navController = navController) } } } } } - -@Composable -fun AppNavigation(navController: NavHostController){ - NavHost( - navController = navController, startDestination = "authorization" - ) { - composable("authorization"){ - Authorization(navController = navController) - } - composable("registration"){ - Registration(navController = navController) - } - composable("main"){ - MainScreen(navController = navController) - } - composable("listdata"){ - ListDataScreen(navController = navController) - } - composable("mail"){ - ListMailScreen(navController = navController) - } - composable("settings"){ - SettingsScreen(navController = navController) - } - composable("editstory"){ - EditStoryScreen(navController = navController) - } - composable("editmail"){ - EditMailScreen(navController = navController) - } - } -} diff --git a/app/src/main/java/com/example/mobileapp/components/NavigationBar.kt b/app/src/main/java/com/example/mobileapp/components/NavigationBar.kt index 3d75c1f..715f335 100644 --- a/app/src/main/java/com/example/mobileapp/components/NavigationBar.kt +++ b/app/src/main/java/com/example/mobileapp/components/NavigationBar.kt @@ -1,9 +1,11 @@ package com.example.mobileapp.components +import androidx.compose.animation.AnimatedVisibility +import androidx.compose.animation.slideInVertically +import androidx.compose.animation.slideOutVertically import androidx.compose.foundation.Image -import androidx.compose.foundation.clickable -import androidx.compose.foundation.layout.Arrangement -import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.requiredHeight @@ -12,58 +14,122 @@ import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material3.Button import androidx.compose.material3.ButtonDefaults import androidx.compose.material3.ExperimentalMaterial3Api +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.ui.Alignment +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.graphics.ColorFilter -import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.sp import androidx.navigation.NavHostController -import androidx.navigation.NavType import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable -import androidx.navigation.navArgument import com.example.mobileapp.R +import com.example.mobileapp.screens.Authorization +import com.example.mobileapp.screens.EditMailScreen +import com.example.mobileapp.screens.EditStoryScreen +import com.example.mobileapp.screens.ListDataScreen +import com.example.mobileapp.screens.ListMailScreen +import com.example.mobileapp.screens.MainScreen +import com.example.mobileapp.screens.Registration +import com.example.mobileapp.screens.SettingsScreen +val navBarItems = listOf( + NavBarItem(route = "main", label = "Главная", icon = R.drawable.home), + NavBarItem(route = "listdata", label = "Создание", icon = R.drawable.edit), + NavBarItem(route = "mail", label = "Уведомления", icon = R.drawable.mail), + NavBarItem(route = "settings", label = "Настройки", icon = R.drawable.settings), +) + +@OptIn(ExperimentalMaterial3Api::class) @Composable -fun NavBar(navController: NavHostController, itemColorFilter: Color) { - Row( - modifier = Modifier - .fillMaxWidth(), - horizontalArrangement = Arrangement.SpaceEvenly, - verticalAlignment = Alignment.CenterVertically - ) { - NavItem(navController = navController, imageId = R.drawable.home, - description = "homeButton", destination = "main", itemColorFilter = itemColorFilter) - NavItem(navController = navController, imageId = R.drawable.edit, - description = "editButton", destination = "listdata", itemColorFilter = itemColorFilter) - NavItem(navController = navController, imageId = R.drawable.mail, - description = "mailButton", destination = "mail", itemColorFilter = itemColorFilter) - NavItem(navController = navController, imageId = R.drawable.settings, - description = "settingsButton", destination = "settings", itemColorFilter = itemColorFilter) +fun NavBar(navController: NavHostController) { + val bottomBarState = rememberSaveable { (mutableStateOf(false)) } + + Scaffold( + bottomBar = { + AnimatedVisibility( + visible = bottomBarState.value, + enter = slideInVertically(initialOffsetY = { it }), + exit = slideOutVertically(targetOffsetY = { it }), + content = { + NavigationBar { + navBarItems.forEach{item -> + NavigationBarItem( + icon = { + Image( + painter = painterResource(item.icon), + contentDescription = null, + modifier = Modifier + .size(40.dp) + .padding(bottom = 6.dp) + ) + }, + label = { + Text( + text = item.label + ) + }, + onClick = { + navController.navigate(item.route) + }, + selected = false, + modifier = Modifier.fillMaxSize() + ) + } + } + } + ) + }, + modifier = Modifier.background(Color.White) + ) {innerPaddings -> + NavHost( + navController = navController, + startDestination = "authorization", + modifier = Modifier.padding(innerPaddings) + ) { + composable("authorization"){ + Authorization(navController = navController) + bottomBarState.value = false + } + composable("registration"){ + Registration(navController = navController) + bottomBarState.value = false + } + composable("main"){ + MainScreen(navController = navController) + bottomBarState.value = true + } + composable("listdata"){ + ListDataScreen(navController = navController) + bottomBarState.value = true + } + composable("mail"){ + ListMailScreen(navController = navController) + bottomBarState.value = true + } + composable("settings"){ + SettingsScreen(navController = navController) + bottomBarState.value = true + } + composable("editstory"){ + EditStoryScreen(navController = navController) + bottomBarState.value = false + } + composable("editmail"){ + EditMailScreen(navController = navController) + bottomBarState.value = false + } + } } } -@Composable -fun NavItem(navController: NavHostController, imageId: Int, - description: String, destination: String, itemColorFilter: Color){ - Image(painter = painterResource(id = imageId), - contentDescription = description, - contentScale = ContentScale.Crop, - modifier = Modifier - .size(64.dp) - .clickable { - navController.navigate(destination) - }, - colorFilter = ColorFilter.tint(itemColorFilter)) -} - @Composable fun NavigationButton(navController: NavHostController, destination: String, label: String, diff --git a/app/src/main/java/com/example/mobileapp/screens/ListDataScreen.kt b/app/src/main/java/com/example/mobileapp/screens/ListDataScreen.kt index e5a039a..8a25837 100644 --- a/app/src/main/java/com/example/mobileapp/screens/ListDataScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/ListDataScreen.kt @@ -22,19 +22,6 @@ fun ListDataScreen(navController: NavHostController){ .fillMaxSize() .background(BackgroundItem1) ) { - Box( - modifier = Modifier - .fillMaxWidth() - .fillMaxHeight(0.9f) - ){ - DataListScroll(navController) - } - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center - ) { - NavBar(navController = navController, itemColorFilter = BackgroundItem2) - } + DataListScroll(navController) } } \ No newline at end of file diff --git a/app/src/main/java/com/example/mobileapp/screens/ListMailScreen.kt b/app/src/main/java/com/example/mobileapp/screens/ListMailScreen.kt index d74f1a0..3ff5272 100644 --- a/app/src/main/java/com/example/mobileapp/screens/ListMailScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/ListMailScreen.kt @@ -22,19 +22,6 @@ fun ListMailScreen(navController: NavHostController){ .fillMaxSize() .background(BackgroundItem1) ) { - Box( - modifier = Modifier - .fillMaxWidth() - .fillMaxHeight(0.9f) - ){ - MailListScroll(navController) - } - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center - ) { - NavBar(navController = navController, itemColorFilter = BackgroundItem2) - } + MailListScroll(navController) } } \ No newline at end of file diff --git a/app/src/main/java/com/example/mobileapp/screens/MainScreen.kt b/app/src/main/java/com/example/mobileapp/screens/MainScreen.kt index 3caa0e7..7846a9e 100644 --- a/app/src/main/java/com/example/mobileapp/screens/MainScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/MainScreen.kt @@ -51,12 +51,5 @@ fun MainScreen(navController: NavHostController) { fontWeight = FontWeight.Bold ) } - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center - ) { - NavBar(navController = navController, itemColorFilter = Color.Black) - } } } \ No newline at end of file diff --git a/app/src/main/java/com/example/mobileapp/screens/SettingsScreen.kt b/app/src/main/java/com/example/mobileapp/screens/SettingsScreen.kt index 453bc9e..5702361 100644 --- a/app/src/main/java/com/example/mobileapp/screens/SettingsScreen.kt +++ b/app/src/main/java/com/example/mobileapp/screens/SettingsScreen.kt @@ -37,39 +37,26 @@ import com.example.mobileapp.ui.theme.ButtonColor2 fun SettingsScreen(navController: NavHostController){ Column( modifier = Modifier - .fillMaxSize() + .fillMaxSize(), + verticalArrangement = Arrangement.Top, + horizontalAlignment = Alignment.CenterHorizontally ) { - Column( + Image( + painter = painterResource(id = R.drawable.settingsplaceholder), + contentDescription = "settings", + contentScale = ContentScale.Crop, modifier = Modifier - .fillMaxWidth() - .fillMaxHeight(0.9f), - verticalArrangement = Arrangement.Top, - horizontalAlignment = Alignment.CenterHorizontally - ){ - Image( - painter = painterResource(id = R.drawable.settingsplaceholder), - contentDescription = "settings", - contentScale = ContentScale.Crop, - modifier = Modifier - .size(384.dp) - .padding(8.dp)) - IconButton(iconLeft = Icons.Default.AccountCircle, label = "Учётная запись", - backgroundColor = ButtonColor2, textColor = Color.White, onClickAction = { }) - IconButton(iconLeft = Icons.Default.Face, label = "Внешний вид", - backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = { }) - IconButton(iconLeft = Icons.Default.Share, label = "Контакты", - backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = { }) - IconButton(iconLeft = Icons.Default.Info, label = "О приложении", - backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = { }) - IconButton(iconLeft = Icons.Default.ExitToApp, label = "Выйти", - backgroundColor = Color.Red, textColor = Color.White, onClickAction = { }) - } - Column( - modifier = Modifier - .fillMaxSize(), - verticalArrangement = Arrangement.Center - ) { - NavBar(navController = navController, itemColorFilter = Color.Black) - } + .size(384.dp) + .padding(8.dp)) + IconButton(iconLeft = Icons.Default.AccountCircle, label = "Учётная запись", + backgroundColor = ButtonColor2, textColor = Color.White, onClickAction = { }) + IconButton(iconLeft = Icons.Default.Face, label = "Внешний вид", + backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = { }) + IconButton(iconLeft = Icons.Default.Share, label = "Контакты", + backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = { }) + IconButton(iconLeft = Icons.Default.Info, label = "О приложении", + backgroundColor = ButtonColor1, textColor = Color.Black, onClickAction = { }) + IconButton(iconLeft = Icons.Default.ExitToApp, label = "Выйти", + backgroundColor = Color.Red, textColor = Color.White, onClickAction = { }) } } \ No newline at end of file