Я хорош

This commit is contained in:
maxnes3 2023-11-16 02:01:29 +04:00
parent 2567fc24a1
commit 6fc39a2396
6 changed files with 130 additions and 148 deletions

View File

@ -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)
}
}
}

View File

@ -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,56 +14,120 @@ 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
@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)
}
}
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 NavItem(navController: NavHostController, imageId: Int,
description: String, destination: String, itemColorFilter: Color){
Image(painter = painterResource(id = imageId),
contentDescription = description,
contentScale = ContentScale.Crop,
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(64.dp)
.clickable {
navController.navigate(destination)
.size(40.dp)
.padding(bottom = 6.dp)
)
},
colorFilter = ColorFilter.tint(itemColorFilter))
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

View File

@ -21,20 +21,7 @@ fun ListDataScreen(navController: NavHostController){
modifier = Modifier
.fillMaxSize()
.background(BackgroundItem1)
) {
Box(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(0.9f)
) {
DataListScroll(navController)
}
Column(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.Center
) {
NavBar(navController = navController, itemColorFilter = BackgroundItem2)
}
}
}

View File

@ -21,20 +21,7 @@ fun ListMailScreen(navController: NavHostController){
modifier = Modifier
.fillMaxSize()
.background(BackgroundItem1)
) {
Box(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(0.9f)
) {
MailListScroll(navController)
}
Column(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.Center
) {
NavBar(navController = navController, itemColorFilter = BackgroundItem2)
}
}
}

View File

@ -51,12 +51,5 @@ fun MainScreen(navController: NavHostController) {
fontWeight = FontWeight.Bold
)
}
Column(
modifier = Modifier
.fillMaxSize(),
verticalArrangement = Arrangement.Center
) {
NavBar(navController = navController, itemColorFilter = Color.Black)
}
}
}

View File

@ -37,12 +37,7 @@ import com.example.mobileapp.ui.theme.ButtonColor2
fun SettingsScreen(navController: NavHostController){
Column(
modifier = Modifier
.fillMaxSize()
) {
Column(
modifier = Modifier
.fillMaxWidth()
.fillMaxHeight(0.9f),
.fillMaxSize(),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
@ -64,12 +59,4 @@ fun SettingsScreen(navController: NavHostController){
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)
}
}
}