need to do ChangeHotel

This commit is contained in:
VictoriaPresnyakova 2023-11-01 19:13:12 +04:00
parent 6a8a539858
commit edeae3587f
8 changed files with 144 additions and 86 deletions

View File

@ -12,18 +12,18 @@ data class Hotel (
@ColumnInfo(name = "Name") @ColumnInfo(name = "Name")
val name: String, val name: String,
@ColumnInfo(name = "Price") @ColumnInfo(name = "Price")//
val price: Double, val price: Double,
@ColumnInfo(name = "Img") @ColumnInfo(name = "Img")//
val img: Int, val img: Int,
@ColumnInfo(name = "Stars") @ColumnInfo(name = "Stars")//
val stars: Int, val stars: Int,
@ColumnInfo(name = "Location") @ColumnInfo(name = "Location")//
val location: String, val location: String,
@ColumnInfo(name = "Info") @ColumnInfo(name = "Info")//
val info: String, val info: String,
) )

View File

@ -1,18 +1,14 @@
package com.example.androidlabs.Navigation package com.example.androidlabs.Navigation
import android.util.Log
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable import androidx.navigation.compose.composable
import com.example.androidlabs.DB.models.Hotel import com.example.androidlabs.DB.models.Hotel
import com.example.androidlabs.DB.viewModels.HotelViewModel
import com.example.androidlabs.DB.viewModels.OrderViewModel import com.example.androidlabs.DB.viewModels.OrderViewModel
import com.example.androidlabs.MyOrderScreen.MyOrderScreen import com.example.androidlabs.MyOrderScreen.MyOrderScreen
import com.example.androidlabs.R
import com.example.androidlabs.booking.BookingScreen import com.example.androidlabs.booking.BookingScreen
import com.example.androidlabs.homeScreen.CardItem.HotelCard
import com.example.androidlabs.homeScreen.HomeScreen import com.example.androidlabs.homeScreen.HomeScreen
import com.example.androidlabs.hotelScreen.HotelInfo import com.example.androidlabs.hotelScreen.HotelInfo
import com.example.androidlabs.profileScreen.profile.Person import com.example.androidlabs.profileScreen.profile.Person
@ -21,6 +17,7 @@ import com.example.androidlabs.profileScreen.signIn.LoginScreen
import com.example.androidlabs.profileScreen.signUp.SignUpScreen import com.example.androidlabs.profileScreen.signUp.SignUpScreen
import com.example.androidlabs.adminPanel.AddPanel import com.example.androidlabs.adminPanel.AddPanel
import com.example.androidlabs.adminPanel.AdminPanel import com.example.androidlabs.adminPanel.AdminPanel
import com.example.androidlabs.adminPanel.ChangeHotel
import com.example.androidlabs.adminPanel.ChangePanel import com.example.androidlabs.adminPanel.ChangePanel
import com.google.gson.Gson import com.google.gson.Gson
@ -61,6 +58,13 @@ fun NavController(navController: NavHostController) {
hotelItem?.let { BookingScreen(orderViewModel, it, navController) hotelItem?.let { BookingScreen(orderViewModel, it, navController)
} }
} }
composable(NavItem.ChangeHotel.route) { backStackEntry ->
val hotelItemString = backStackEntry.arguments?.getString("hotelItem")
val hotelItem = Gson().fromJson(hotelItemString, Hotel::class.java)
hotelItem?.let { ChangeHotel(it, onBackClick = {
navController.navigateUp() })
}
}
composable(NavItem.Person.route) { composable(NavItem.Person.route) {
Person(navController) Person(navController)
} }
@ -68,10 +72,11 @@ fun NavController(navController: NavHostController) {
AdminPanel(navController) AdminPanel(navController)
} }
composable(NavItem.AddPanel.route){ composable(NavItem.AddPanel.route){
AddPanel() AddPanel(navController)
} }
composable(NavItem.ChangePanel.route){ composable(NavItem.ChangePanel.route){
ChangePanel(navController) ChangePanel(navController)
} }
} }
} }

View File

@ -19,6 +19,6 @@ sealed class NavItem(val route: String, val icon: ImageVector?){
object AdminPanel : NavItem("admin", Icons.Default.Build) object AdminPanel : NavItem("admin", Icons.Default.Build)
object AddPanel : NavItem("add", null) object AddPanel : NavItem("add", null)
object ChangePanel : NavItem("change", null) object ChangePanel : NavItem("change", null)
// object ChangeHotel : NavItem("changeHotel/{hotelItem}", null) object ChangeHotel : NavItem("changeHotel/{hotelItem}", null)
} }

View File

@ -41,11 +41,15 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import com.example.androidlabs.DB.models.PhotoManager
import com.example.androidlabs.DB.viewModels.HotelViewModel
import com.example.androidlabs.R import com.example.androidlabs.R
@Composable @Composable
fun AddPanel(){ fun AddPanel(navHostController: NavHostController, hotelViewModel: HotelViewModel = viewModel(factory = HotelViewModel.factory)){
val photoManager = PhotoManager()
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -59,7 +63,7 @@ fun AddPanel(){
verticalArrangement = Arrangement.Center verticalArrangement = Arrangement.Center
) { ) {
Image( Image(
painter = painterResource(id = R.drawable.img), painter = painterResource(id = hotelViewModel.img.value),
contentDescription = "image", contentDescription = "image",
contentScale = ContentScale.FillHeight, contentScale = ContentScale.FillHeight,
modifier = Modifier modifier = Modifier
@ -73,7 +77,8 @@ fun AddPanel(){
contentColor = Color.White contentColor = Color.White
), ),
onClick = { onClick = {
//TODO hotelViewModel.img.value = photoManager.changePhoto(hotelViewModel.img.value)
}, },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -82,10 +87,35 @@ fun AddPanel(){
) { ) {
Text("Add image") Text("Add image")
} }
TextField( TextField(
value = "", value = hotelViewModel.name.value,
onValueChange = { }, onValueChange = { hotelViewModel.name.value = it },
modifier = Modifier
.fillMaxWidth()
.height(50.dp)
.padding(16.dp, 0.dp)
.border(1.dp, Color.Gray, RoundedCornerShape(4.dp)),
singleLine = true,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Next
),
keyboardActions = KeyboardActions(
onNext = {
}
),
placeholder = {
Text(
text = "Name",
style = TextStyle(fontSize = 12.sp)
)
}
)
Spacer(modifier = Modifier.height(16.dp))
TextField(
value = hotelViewModel.stars.value,
onValueChange = { hotelViewModel.stars.value = it },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(50.dp) .height(50.dp)
@ -111,8 +141,8 @@ fun AddPanel(){
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
TextField( TextField(
value = "", value = hotelViewModel.location.value,
onValueChange = { }, onValueChange = { hotelViewModel.location.value = it },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(50.dp) .height(50.dp)
@ -138,36 +168,11 @@ fun AddPanel(){
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
TextField(
value = "",
onValueChange = { },
modifier = Modifier
.fillMaxWidth()
.height(50.dp)
.padding(16.dp, 0.dp)
.border(1.dp, Color.Gray, RoundedCornerShape(4.dp)),
singleLine = true,
keyboardOptions = KeyboardOptions(
keyboardType = KeyboardType.Text,
imeAction = ImeAction.Next
),
keyboardActions = KeyboardActions(
onNext = {
}
),
placeholder = {
Text(
text = "Info",
style = TextStyle(fontSize = 12.sp)
)
}
)
Spacer(modifier = Modifier.height(16.dp))
TextField( TextField(
value = "", value = hotelViewModel.price.value,
onValueChange = { }, onValueChange = { hotelViewModel.price.value = it },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(50.dp) .height(50.dp)
@ -193,8 +198,8 @@ fun AddPanel(){
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
TextField( TextField(
value = "", value = hotelViewModel.info.value,
onValueChange = { }, onValueChange = { hotelViewModel.info.value = it },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
.height(50.dp) .height(50.dp)
@ -224,7 +229,8 @@ fun AddPanel(){
contentColor = Color.White contentColor = Color.White
), ),
onClick = { onClick = {
// hotelViewModel.insertHotel()
navHostController.navigate("home")
}, },
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -241,6 +247,6 @@ fun AddPanel(){
@Composable @Composable
fun AddPreview() { fun AddPreview() {
AddPanel() //AddPanel()
} }

View File

@ -4,6 +4,8 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.material.AlertDialog
import androidx.compose.material.Button
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue import androidx.compose.runtime.getValue
@ -16,13 +18,34 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.example.androidlabs.DB.models.RoleEnum
import com.example.androidlabs.GlobalUser
import com.example.androidlabs.profileScreen.signIn.LoginScreen import com.example.androidlabs.profileScreen.signIn.LoginScreen
@Composable @Composable
fun AdminPanel(navHostController: NavHostController) { fun AdminPanel(navHostController: NavHostController) {
var isAddPanelVisible by remember { mutableStateOf(false) } var isAddPanelVisible by remember { mutableStateOf(false) }
var isChangePanelVisible by remember { mutableStateOf(true) } var isChangePanelVisible by remember { mutableStateOf(true) }
var showDialog by remember { mutableStateOf(GlobalUser.getInstance().getUser()?.role == RoleEnum.User || GlobalUser.getInstance().getUser()?.role == null) }
if (showDialog) {
AlertDialog(
onDismissRequest = { showDialog = false },
title = {
Text("Access denied")
},
text = {
Text("You are not admin")
},
confirmButton = {
Button(
onClick = { navHostController.navigate("home") }
) {
Text("OK")
}
}
)
}
else{
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@ -41,13 +64,14 @@ fun AdminPanel(navHostController: NavHostController) {
) )
if (isAddPanelVisible) { if (isAddPanelVisible) {
AddPanel() AddPanel(navHostController)
} }
if (isChangePanelVisible) { if (isChangePanelVisible) {
ChangePanel(navHostController) ChangePanel(navHostController)
} }
} }
}
} }
@Composable @Composable

View File

@ -2,7 +2,6 @@ package com.example.androidlabs.adminPanel
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -10,7 +9,13 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material.Icon
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Create
import androidx.compose.material.icons.filled.Delete
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -22,15 +27,17 @@ import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController import androidx.navigation.compose.rememberNavController
import com.example.androidlabs.Hotel import com.example.androidlabs.DB.models.Hotel
import com.example.androidlabs.DB.viewModels.HotelViewModel
import com.example.androidlabs.R import com.example.androidlabs.R
import com.google.gson.Gson import com.google.gson.Gson
@Composable @Composable
fun CardHotelForChange(item: Hotel, navController: NavHostController) { fun CardHotelForChange(item: Hotel, navController: NavHostController, hotelViewModel: HotelViewModel = viewModel(factory = HotelViewModel.factory)) {
Row( Row(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@ -59,28 +66,39 @@ fun CardHotelForChange(item: Hotel, navController: NavHostController) {
Text(text = "${item.location}", color = Color.Red, fontSize = 16.sp) Text(text = "${item.location}", color = Color.Red, fontSize = 16.sp)
} }
Image( Button(
painter = painterResource(id = R.drawable.baseline_edit_24), colors = ButtonDefaults.buttonColors(
contentDescription = "image", backgroundColor = colorResource(id = R.color.figma_blue),
modifier = Modifier contentColor = Color.White
.size(40.dp) ),
.padding(10.dp) onClick = {
.clickable { hotelViewModel.name.value = item.name ?: ""
val hotelItemString = Gson().toJson(item) hotelViewModel.price.value = item.price.toString()
navController.navigate("changeHotel/${hotelItemString}") hotelViewModel.stars.value = item.stars.toString()
} hotelViewModel.location.value = item.location ?: ""
) hotelViewModel.info.value = item.info ?: ""
Image( val hotelItemString = Gson().toJson(item)
painter = painterResource(id = R.drawable.baseline_delete_24), navController.navigate("changeHotel/${hotelItemString}") },
contentDescription = "image",
modifier = Modifier modifier = Modifier
.size(40.dp) .padding(end = 16.dp)
.padding(10.dp) ) {
.clickable { Icon(imageVector = Icons.Default.Create, contentDescription = "change")
}
} Button(
) colors = ButtonDefaults.buttonColors(
backgroundColor = colorResource(id = R.color.figma_blue),
contentColor = Color.White
),
onClick = {
hotelViewModel.deleteHotel(item)
},
modifier = Modifier
.padding(end = 16.dp)
) {
Icon(imageVector = Icons.Default.Delete, contentDescription = "delete")
}
} }
} }
@ -91,5 +109,5 @@ fun CardHotelForChange(item: Hotel, navController: NavHostController) {
@Preview @Preview
fun CardHotelLikePreview(){ fun CardHotelLikePreview(){
val navController = rememberNavController() val navController = rememberNavController()
CardHotelForChange(Hotel("Hotel", R.drawable.img, 5, "location", "info", 4000), navController) //CardHotelForChange(Hotel("Hotel", R.drawable.img, 5, "location", "info", 4000), navController)
} }

View File

@ -0,0 +1,10 @@
package com.example.androidlabs.adminPanel
import androidx.compose.runtime.Composable
import com.example.androidlabs.DB.models.Hotel
import com.example.androidlabs.DB.viewModels.HotelViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
@Composable
fun ChangeHotel(sneaker: Hotel, onBackClick: () -> Unit, sneakerViewModel: HotelViewModel = viewModel(factory = HotelViewModel.factory)) {
//TODO
}

View File

@ -14,13 +14,14 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.lifecycle.viewmodel.compose.viewModel import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController import androidx.navigation.NavHostController
import com.example.androidlabs.DB.viewModels.HotelViewModel
import com.example.androidlabs.Hotel import com.example.androidlabs.Hotel
import com.example.androidlabs.R import com.example.androidlabs.R
@Composable @Composable
fun ChangePanel(navHostController: NavHostController){ fun ChangePanel(navHostController: NavHostController, hotelViewModel: HotelViewModel = viewModel(factory = HotelViewModel.factory)){
//val list = sneakerViewModel.SneakerList.collectAsState(initial = emptyList()).value val list = hotelViewModel.HotelList.collectAsState(initial = emptyList()).value
Column( Column(
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
@ -32,16 +33,10 @@ fun ChangePanel(navHostController: NavHostController){
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
) { ) {
itemsIndexed( itemsIndexed(list
listOf(
Hotel("Hotel", R.drawable.img, 5, "location", "info", 4000),
Hotel("Hotel", R.drawable.img, 5, "location", "info", 4000),
Hotel("Hotel", R.drawable.img, 5, "location", "info", 4000)
)
){_, item-> ){_, item->
CardHotelForChange(item = item, navHostController) CardHotelForChange(item = item, navHostController)
}
}
} }
} }
} }