осталось список заказов и панельку админа
This commit is contained in:
parent
25e1d97db5
commit
4c013ac345
@ -0,0 +1,60 @@
|
||||
package com.example.androidlabs.DB.viewModels
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.ViewModelProvider.AndroidViewModelFactory.Companion.APPLICATION_KEY
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.CreationExtras
|
||||
import com.example.androidlabs.App
|
||||
import com.example.androidlabs.DB.AppDatabase
|
||||
import com.example.androidlabs.DB.models.Hotel
|
||||
import com.example.androidlabs.R
|
||||
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
class HotelViewModel(val database: AppDatabase): ViewModel() {
|
||||
var name = mutableStateOf("")
|
||||
val price = mutableStateOf("")
|
||||
val location = mutableStateOf("")
|
||||
val stars = mutableStateOf("")
|
||||
val info = mutableStateOf("")
|
||||
val img = mutableStateOf(R.drawable.img)
|
||||
val HotelList = database.hotelDao().getAllHotelss()
|
||||
var hotel: Hotel? = null
|
||||
|
||||
fun insertHotel() = viewModelScope.launch {
|
||||
val hotel = Hotel(
|
||||
name = name.value,
|
||||
location = location.value,
|
||||
price = price.value.toDouble(),
|
||||
img = img.value,
|
||||
stars = stars.value.toInt(),
|
||||
info = info.value
|
||||
)
|
||||
database.hotelDao().insert(hotel)
|
||||
}
|
||||
|
||||
fun deleteHotel(hotel : Hotel) = viewModelScope.launch {
|
||||
database.hotelDao().delete(hotel)
|
||||
}
|
||||
|
||||
fun getHotelById(id: Int) = viewModelScope.launch {
|
||||
database.hotelDao().getHotelById(id)
|
||||
}
|
||||
|
||||
fun UpdateHotel(hotel: Hotel) = viewModelScope.launch {
|
||||
database.hotelDao().update(hotel)
|
||||
}
|
||||
|
||||
companion object{
|
||||
val factory: ViewModelProvider.Factory = object : ViewModelProvider.Factory{
|
||||
override fun <T : ViewModel> create(
|
||||
modelClass: Class<T>,
|
||||
extras: CreationExtras): T {
|
||||
val database = (checkNotNull(extras[APPLICATION_KEY]) as App).database
|
||||
return HotelViewModel(database) as T
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.example.androidlabs.DB.viewModels
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.CreationExtras
|
||||
import com.example.androidlabs.App
|
||||
import com.example.androidlabs.DB.AppDatabase
|
||||
import com.example.androidlabs.DB.models.Hotel
|
||||
import com.example.androidlabs.DB.models.Order
|
||||
import com.example.androidlabs.GlobalUser
|
||||
import kotlinx.coroutines.launch
|
||||
import java.util.Date
|
||||
|
||||
class OrderViewModel(val database: AppDatabase) : ViewModel() {
|
||||
var selectedItem: Hotel? = null
|
||||
val rooms = mutableStateOf("")
|
||||
|
||||
fun deleteOrder(order: Order) = viewModelScope.launch {
|
||||
database.orderDao().delete(order)
|
||||
}
|
||||
|
||||
fun getOrderList(id: Int) = viewModelScope.launch {
|
||||
database.userDao().getUserOrders(id)
|
||||
}
|
||||
|
||||
|
||||
fun createOrder() = viewModelScope.launch {
|
||||
val order = Order(
|
||||
dateFrom = Date().time,
|
||||
dateTo = Date().time,
|
||||
rooms = rooms.value.toInt(),
|
||||
total = getSubTotal(),
|
||||
bookedHotelId = selectedItem?.hotelId!!,
|
||||
//creatorUserId = 1
|
||||
creatorUserId = GlobalUser.getInstance().getUser()?.userId!!
|
||||
)
|
||||
|
||||
val orderId = database.orderDao().createOrder(order)
|
||||
|
||||
|
||||
rooms.value = ""
|
||||
selectedItem = null
|
||||
}
|
||||
|
||||
fun getSubTotal(): Double {
|
||||
return selectedItem!!.price * rooms.value.toInt()
|
||||
}
|
||||
|
||||
companion object{
|
||||
val factory: ViewModelProvider.Factory = object : ViewModelProvider.Factory{
|
||||
override fun <T : ViewModel> create(
|
||||
modelClass: Class<T>,
|
||||
extras: CreationExtras
|
||||
): T {
|
||||
val database = (checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY]) as App).database
|
||||
return OrderViewModel(database) as T
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package com.example.androidlabs.DB.viewModels
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.lifecycle.ViewModel
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.viewModelScope
|
||||
import androidx.lifecycle.viewmodel.CreationExtras
|
||||
import com.example.androidlabs.App
|
||||
import com.example.androidlabs.DB.AppDatabase
|
||||
import com.example.androidlabs.DB.models.RoleEnum
|
||||
import com.example.androidlabs.DB.models.User
|
||||
import com.example.androidlabs.GlobalUser
|
||||
|
||||
import kotlinx.coroutines.launch
|
||||
class UserViewModel(val database: AppDatabase): ViewModel() {
|
||||
|
||||
var name = mutableStateOf("")
|
||||
val surname = mutableStateOf("")
|
||||
val email = mutableStateOf("")
|
||||
val password = mutableStateOf("")
|
||||
fun createUser() = viewModelScope.launch {
|
||||
val user = User(
|
||||
name = name.value,
|
||||
surname = surname.value,
|
||||
email = email.value,
|
||||
password = password.value,
|
||||
role = RoleEnum.User
|
||||
)
|
||||
database.userDao().createUser(user)
|
||||
}
|
||||
fun authUser() = viewModelScope.launch {
|
||||
val user = database.userDao().getUserByEmail(email.value)
|
||||
if (password.value != "" && user.password == password.value) {
|
||||
val globalUser = GlobalUser.getInstance()
|
||||
globalUser.setUser(user)
|
||||
println()
|
||||
}
|
||||
}
|
||||
fun isValidEmail(email: String): Boolean {
|
||||
return android.util.Patterns.EMAIL_ADDRESS.matcher(email).matches()
|
||||
}
|
||||
|
||||
companion object{
|
||||
val factory: ViewModelProvider.Factory = object : ViewModelProvider.Factory{
|
||||
override fun <T : ViewModel> create(
|
||||
modelClass: Class<T>,
|
||||
extras: CreationExtras
|
||||
): T {
|
||||
val database = (checkNotNull(extras[ViewModelProvider.AndroidViewModelFactory.APPLICATION_KEY]) as App).database
|
||||
return UserViewModel(database) as T
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,10 +1,14 @@
|
||||
package com.example.androidlabs.Navigation
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.NavHost
|
||||
import androidx.navigation.compose.composable
|
||||
import com.example.androidlabs.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.R
|
||||
import com.example.androidlabs.booking.BookingScreen
|
||||
import com.example.androidlabs.homeScreen.CardItem.HotelCard
|
||||
@ -17,15 +21,22 @@ import com.example.androidlabs.profileScreen.signUp.SignUpScreen
|
||||
import com.example.androidlabs.adminPanel.AddPanel
|
||||
import com.example.androidlabs.adminPanel.AdminPanel
|
||||
import com.example.androidlabs.adminPanel.ChangePanel
|
||||
import com.google.gson.Gson
|
||||
|
||||
@Composable
|
||||
fun NavController(navController: NavHostController) {
|
||||
var orderViewModel: OrderViewModel = viewModel(factory = OrderViewModel.factory)
|
||||
NavHost(
|
||||
navController = navController,
|
||||
startDestination = NavItem.Home.route
|
||||
) {
|
||||
composable(NavItem.HotelInfo.route) {
|
||||
HotelInfo(Hotel("hotel", R.drawable.img_1, 4, "location", "info", 4000), navController)
|
||||
//
|
||||
backStackEntry ->
|
||||
val hotelItemString = backStackEntry.arguments?.getString("hotelItem")
|
||||
val hotelItem = Gson().fromJson(hotelItemString, Hotel::class.java)
|
||||
hotelItem?.let { HotelInfo(it, navController)
|
||||
}
|
||||
}
|
||||
composable(NavItem.Home.route) {
|
||||
HomeScreen(navController)
|
||||
@ -37,13 +48,17 @@ fun NavController(navController: NavHostController) {
|
||||
LoginScreen(navController)
|
||||
}
|
||||
composable(NavItem.SignUp.route){
|
||||
SignUpScreen()
|
||||
SignUpScreen(navController)
|
||||
}
|
||||
composable(NavItem.Booking.route) {
|
||||
BookingScreen()
|
||||
backStackEntry ->
|
||||
val hotelItemString = backStackEntry.arguments?.getString("hotelItem")
|
||||
val hotelItem = Gson().fromJson(hotelItemString, Hotel::class.java)
|
||||
hotelItem?.let { BookingScreen(orderViewModel, it, navController)
|
||||
}
|
||||
}
|
||||
composable(NavItem.Person.route) {
|
||||
Person()
|
||||
Person(navController)
|
||||
}
|
||||
composable(NavItem.AdminPanel.route){
|
||||
AdminPanel(navController)
|
||||
|
@ -12,8 +12,8 @@ sealed class NavItem(val route: String, val icon: ImageVector?){
|
||||
object Profile : NavItem("profile", Icons.Default.Person)
|
||||
object SignIn : NavItem("login", null)
|
||||
object SignUp : NavItem("signup", null)
|
||||
object HotelInfo : NavItem("HotelInfo", null)
|
||||
object Booking : NavItem("booking", null)
|
||||
object HotelInfo : NavItem("HotelInfo/{hotelItem}", null)
|
||||
object Booking : NavItem("booking/{hotelItem}", null)
|
||||
object Person : NavItem("person", null)
|
||||
object AdminPanel : NavItem("admin", Icons.Default.Build)
|
||||
object AddPanel : NavItem("add", null)
|
||||
|
@ -10,7 +10,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.BasicTextField
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material.Button
|
||||
@ -34,12 +33,15 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.androidlabs.DB.models.Hotel
|
||||
import com.example.androidlabs.DB.viewModels.OrderViewModel
|
||||
import com.example.androidlabs.GlobalUser
|
||||
import com.example.androidlabs.R
|
||||
import com.example.androidlabs.profileScreen.signIn.LoginScreen
|
||||
|
||||
@Composable
|
||||
fun BookingScreen() {
|
||||
fun BookingScreen(orderViewModel: OrderViewModel, hotel: Hotel, navHostController: NavHostController) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
@ -49,7 +51,7 @@ fun BookingScreen() {
|
||||
verticalArrangement = Arrangement.Center,
|
||||
horizontalAlignment = Alignment.CenterHorizontally
|
||||
) {
|
||||
var room by remember { mutableStateOf("") }
|
||||
var rooms by remember { mutableStateOf("") }
|
||||
var date by remember { mutableStateOf("") }
|
||||
|
||||
Text(
|
||||
@ -61,8 +63,8 @@ fun BookingScreen() {
|
||||
)
|
||||
|
||||
TextField(
|
||||
value = room,
|
||||
onValueChange = { room = it },
|
||||
value = orderViewModel.rooms.value,
|
||||
onValueChange = { orderViewModel.rooms.value = it},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(50.dp)
|
||||
@ -80,7 +82,7 @@ fun BookingScreen() {
|
||||
),
|
||||
placeholder = {
|
||||
Text(
|
||||
text = "Room",
|
||||
text = "Rooms",
|
||||
style = TextStyle(fontSize = 12.sp)
|
||||
)
|
||||
}
|
||||
@ -122,21 +124,27 @@ fun BookingScreen() {
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
|
||||
//if(GlobalUser.getInstance().getUser() != null){
|
||||
orderViewModel.selectedItem = hotel
|
||||
orderViewModel.createOrder()
|
||||
navHostController.navigate("home")
|
||||
//}else{
|
||||
// navHostController.navigate("login")
|
||||
// }
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp, 16.dp, 16.dp, 0.dp)
|
||||
.height(50.dp)
|
||||
) {
|
||||
Text("Payment")
|
||||
Text("Book")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true)
|
||||
fun BookingScreenPreview(){
|
||||
val navController = rememberNavController()
|
||||
BookingScreen()
|
||||
}
|
||||
//@Composable
|
||||
//@Preview(showBackground = true)
|
||||
//fun BookingScreenPreview(){
|
||||
// val navController = rememberNavController()
|
||||
// BookingScreen()
|
||||
//}
|
@ -26,8 +26,9 @@ import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.androidlabs.Hotel
|
||||
import com.example.androidlabs.DB.models.Hotel
|
||||
import com.example.androidlabs.R
|
||||
import com.google.gson.Gson
|
||||
|
||||
@Composable
|
||||
fun HotelCard (hotel: Hotel, navController: NavHostController){
|
||||
@ -36,7 +37,8 @@ fun HotelCard (hotel: Hotel, navController: NavHostController){
|
||||
.fillMaxWidth()
|
||||
.padding(10.dp)
|
||||
.clickable {
|
||||
navController.navigate("HotelInfo")
|
||||
val hotelItemString = Gson().toJson(hotel)
|
||||
navController.navigate("HotelInfo/${hotelItemString}")
|
||||
},
|
||||
shape = RoundedCornerShape(15.dp),
|
||||
elevation = 5.dp
|
||||
|
@ -9,6 +9,8 @@ import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
@ -21,9 +23,11 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.androidlabs.DB.AppDatabase
|
||||
import com.example.androidlabs.DB.viewModels.HotelViewModel
|
||||
import com.example.androidlabs.R
|
||||
import com.example.androidlabs.homeScreen.CardItem.HotelCard
|
||||
import com.example.androidlabs.Hotel
|
||||
@ -31,14 +35,14 @@ import com.example.androidlabs.homeScreen.SearchField.SearchField
|
||||
import kotlinx.coroutines.flow.count
|
||||
|
||||
@Composable
|
||||
fun HomeScreen(navController: NavHostController) {
|
||||
val context = LocalContext.current
|
||||
val List = AppDatabase.getInstance(context).hotelDao().getAllHotelss().collectAsState(initial = emptyList()).value
|
||||
Log.d("MyLog", List.toString())
|
||||
fun HomeScreen(navController: NavHostController, hotelViewModel: HotelViewModel = viewModel(factory = HotelViewModel.factory)) {
|
||||
val list = hotelViewModel.HotelList.collectAsState(initial = emptyList()).value
|
||||
//Log.d("MyLog", list.toString())
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.White)
|
||||
//.padding(bottom = 60.dp)
|
||||
) {
|
||||
Box(modifier = Modifier
|
||||
.background(colorResource(id = R.color.figma_blue))
|
||||
@ -62,12 +66,14 @@ fun HomeScreen(navController: NavHostController) {
|
||||
}
|
||||
}
|
||||
}
|
||||
LazyColumn (
|
||||
Column (
|
||||
modifier = Modifier
|
||||
//.verticalScroll(rememberScrollState())
|
||||
.verticalScroll(rememberScrollState())
|
||||
.padding(bottom = 60.dp)
|
||||
|
||||
){
|
||||
items(count = 100 ){
|
||||
HotelCard(Hotel("hotel", R.drawable.img, it % 6, "location", "info", 4000), navController)
|
||||
for (item in list){
|
||||
HotelCard(item, navController)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.example.androidlabs.hotelScreen
|
||||
|
||||
import android.util.Log
|
||||
import androidx.compose.animation.shrinkVertically
|
||||
import androidx.compose.foundation.Image
|
||||
import androidx.compose.foundation.ScrollState
|
||||
@ -34,12 +35,15 @@ import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.androidlabs.Hotel
|
||||
import com.example.androidlabs.DB.models.Hotel
|
||||
import com.example.androidlabs.R
|
||||
import com.example.androidlabs.homeScreen.CardItem.HotelCard
|
||||
import com.google.gson.Gson
|
||||
|
||||
@Composable
|
||||
fun HotelInfo(hotel: Hotel, navController: NavHostController) {
|
||||
Log.d("MyLog", hotel.toString())
|
||||
|
||||
Column (
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -143,7 +147,8 @@ fun HotelInfo(hotel: Hotel, navController: NavHostController) {
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
navController.navigate("booking")
|
||||
val hotelItemString = Gson().toJson(hotel)
|
||||
navController.navigate("booking/${hotelItemString}")
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -161,6 +166,6 @@ fun HotelInfo(hotel: Hotel, navController: NavHostController) {
|
||||
@Composable
|
||||
fun HotelInfoPreview() {
|
||||
val navController = rememberNavController()
|
||||
HotelInfo(Hotel("hotel", R.drawable.img_1, 4, "location", "info", 4000), navController)
|
||||
// HotelInfo(Hotel("hotel", R.drawable.img_1, 4, "location", "info", 4000), navController)
|
||||
|
||||
}
|
@ -11,6 +11,8 @@ import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
@ -18,26 +20,46 @@ import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import androidx.compose.ui.res.painterResource
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.androidlabs.GlobalUser
|
||||
import com.example.androidlabs.R
|
||||
|
||||
@Composable
|
||||
fun Person() {
|
||||
fun Person(navHostController: NavHostController) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.background(Color.White)
|
||||
.fillMaxSize(),
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
ProfileCard()
|
||||
Button(
|
||||
onClick = {
|
||||
GlobalUser.getInstance().setUser(null)
|
||||
navHostController.navigate("profile")
|
||||
},
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = colorResource(id = R.color.white),
|
||||
contentColor = Color.Black
|
||||
),
|
||||
modifier = Modifier
|
||||
.padding(16.dp, 0.dp)
|
||||
) {
|
||||
Text("Exit")
|
||||
}
|
||||
ProfileCard(navHostController)
|
||||
}
|
||||
}
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PersonPreview(){
|
||||
Person()
|
||||
val navController = rememberNavController()
|
||||
Person(navController)
|
||||
}
|
@ -13,6 +13,8 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.CircleShape
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.ButtonDefaults
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Alignment
|
||||
@ -27,17 +29,19 @@ import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavHostController
|
||||
import com.example.androidlabs.GlobalUser
|
||||
import com.example.androidlabs.R
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun ProfileCard() {
|
||||
fun ProfileCard(navHostController: NavHostController) {
|
||||
val globalUser = GlobalUser.getInstance().getUser()
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp)
|
||||
.clip(RoundedCornerShape(16.dp))
|
||||
.background(Color.LightGray)
|
||||
.background(colorResource(id = R.color.figma))
|
||||
){
|
||||
Column(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
@ -55,17 +59,32 @@ fun ProfileCard() {
|
||||
.clip(CircleShape)
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "User",
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
|
||||
Text(
|
||||
text = "user@example.com",
|
||||
fontSize = 16.sp,
|
||||
color = Color.Gray
|
||||
)
|
||||
if (globalUser != null) {
|
||||
Text(
|
||||
text = "${globalUser.name} ${globalUser.surname}",
|
||||
fontSize = 18.sp,
|
||||
fontWeight = FontWeight.Bold
|
||||
)
|
||||
Text(
|
||||
text = globalUser.email,
|
||||
fontSize = 16.sp,
|
||||
color = Color.Gray
|
||||
)
|
||||
}
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = colorResource(id = R.color.figma_blue),
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
navHostController.navigate("myorder")
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp, 16.dp, 16.dp, 0.dp)
|
||||
) {
|
||||
Text("My order")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,78 +25,22 @@ import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.res.colorResource
|
||||
import com.example.androidlabs.GlobalUser
|
||||
import com.example.androidlabs.R
|
||||
import com.example.androidlabs.profileScreen.signIn.LoginScreen
|
||||
|
||||
@Composable
|
||||
fun ProfileScreen(navController: NavHostController) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.fillMaxHeight()
|
||||
.padding(16.dp),
|
||||
verticalArrangement = Arrangement.Center,
|
||||
){
|
||||
Row(
|
||||
){
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = (colorResource(id = R.color.figma_blue)),
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
navController.navigate("person")
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp, 0.dp, 16.dp, 0.dp)
|
||||
.height(50.dp)
|
||||
) {
|
||||
Text(text = "Profile")
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Row(
|
||||
){
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = (colorResource(id = R.color.figma_blue)),
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
navController.navigate("login")
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp, 0.dp, 16.dp, 0.dp)
|
||||
.height(50.dp)
|
||||
) {
|
||||
Text(text = "Sign In")
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
Row(
|
||||
){
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = (colorResource(id = R.color.figma_blue)),
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
navController.navigate("signup")
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp, 0.dp, 16.dp, 0.dp)
|
||||
.height(50.dp)
|
||||
) {
|
||||
Text(text = "Sign Up")
|
||||
}
|
||||
}
|
||||
val globalUser: GlobalUser = GlobalUser.getInstance()
|
||||
if(globalUser.getUser() != null){
|
||||
Person(navController)
|
||||
}else{
|
||||
LoginScreen(navController = navController)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true)
|
||||
@Preview
|
||||
fun ProfileScreenPreview(){
|
||||
val navController = rememberNavController()
|
||||
ProfileScreen(navController = navController)
|
||||
|
@ -37,12 +37,14 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.androidlabs.DB.viewModels.UserViewModel
|
||||
import com.example.androidlabs.R
|
||||
|
||||
@Composable
|
||||
fun SignInCard(navController: NavHostController) {
|
||||
fun SignInCard(navController: NavHostController, userViewModel: UserViewModel = viewModel(factory = UserViewModel.factory)) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -55,8 +57,8 @@ fun SignInCard(navController: NavHostController) {
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.Center
|
||||
){
|
||||
var username by remember { mutableStateOf("") }
|
||||
var password by remember { mutableStateOf("") }
|
||||
var isEmailValid by remember { mutableStateOf(true) }
|
||||
var isPasswordValid by remember { mutableStateOf(true) }
|
||||
|
||||
Text(
|
||||
text = "Sign In",
|
||||
@ -67,8 +69,10 @@ fun SignInCard(navController: NavHostController) {
|
||||
)
|
||||
|
||||
TextField(
|
||||
value = username,
|
||||
onValueChange = { username = it },
|
||||
value = userViewModel.email.value,
|
||||
onValueChange = {
|
||||
userViewModel.email.value = it
|
||||
isEmailValid = userViewModel.isValidEmail(it)},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(50.dp)
|
||||
@ -91,12 +95,21 @@ fun SignInCard(navController: NavHostController) {
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
if (!isEmailValid) {
|
||||
Text(
|
||||
text = "Invalid email format",
|
||||
color = Color.Red,
|
||||
style = TextStyle(fontSize = 12.sp)
|
||||
)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
TextField(
|
||||
value = password,
|
||||
onValueChange = { password = it },
|
||||
value = userViewModel.password.value,
|
||||
onValueChange = {
|
||||
userViewModel.password.value = it
|
||||
isPasswordValid = it.isNotEmpty()
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(50.dp)
|
||||
@ -121,14 +134,21 @@ fun SignInCard(navController: NavHostController) {
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
if (!isPasswordValid) {
|
||||
Text(
|
||||
text = "Password is required",
|
||||
color = Color.Red,
|
||||
style = TextStyle(fontSize = 12.sp)
|
||||
)
|
||||
}
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = (colorResource(id = R.color.figma_blue)),
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
|
||||
userViewModel.authUser()
|
||||
navController.navigate("person")
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
|
@ -34,18 +34,15 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import androidx.navigation.NavHostController
|
||||
import androidx.navigation.compose.rememberNavController
|
||||
import com.example.androidlabs.DB.viewModels.UserViewModel
|
||||
import com.example.androidlabs.R
|
||||
import com.example.androidlabs.profileScreen.signIn.LoginScreen
|
||||
|
||||
@Composable
|
||||
@Preview
|
||||
fun SignUpCard() {
|
||||
var username by remember { mutableStateOf("") }
|
||||
var password by remember { mutableStateOf("") }
|
||||
var sex by remember { mutableStateOf("") }
|
||||
var name by remember { mutableStateOf("") }
|
||||
var surname by remember { mutableStateOf("") }
|
||||
fun SignUpCard(navHostController: NavHostController, userViewModel: UserViewModel = viewModel(factory = UserViewModel.factory)) {
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -68,36 +65,8 @@ fun SignUpCard() {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
TextField(
|
||||
value = username,
|
||||
onValueChange = { username = 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 = "Username",
|
||||
style = TextStyle(fontSize = 12.sp)
|
||||
)
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
TextField(
|
||||
value = name,
|
||||
onValueChange = { name = it },
|
||||
value = userViewModel.name.value,
|
||||
onValueChange = { userViewModel.name.value = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(50.dp)
|
||||
@ -124,8 +93,8 @@ fun SignUpCard() {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
TextField(
|
||||
value = surname,
|
||||
onValueChange = { surname = it },
|
||||
value = userViewModel.surname.value,
|
||||
onValueChange = { userViewModel.surname.value = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(50.dp)
|
||||
@ -152,8 +121,8 @@ fun SignUpCard() {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
TextField(
|
||||
value = sex,
|
||||
onValueChange = { sex = it },
|
||||
value = userViewModel.email.value,
|
||||
onValueChange = { userViewModel.email.value = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(50.dp)
|
||||
@ -171,7 +140,7 @@ fun SignUpCard() {
|
||||
),
|
||||
placeholder = {
|
||||
Text(
|
||||
text = "Sex",
|
||||
text = "Email",
|
||||
style = TextStyle(fontSize = 12.sp)
|
||||
)
|
||||
}
|
||||
@ -180,20 +149,18 @@ fun SignUpCard() {
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
TextField(
|
||||
value = password,
|
||||
onValueChange = { password = it },
|
||||
value = userViewModel.password.value,
|
||||
onValueChange = { userViewModel.password.value = it },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.height(50.dp)
|
||||
.padding(16.dp, 0.dp)
|
||||
.border(1.dp, Color.Gray, RoundedCornerShape(4.dp)),
|
||||
singleLine = true,
|
||||
visualTransformation = PasswordVisualTransformation(),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Text,
|
||||
imeAction = ImeAction.Next
|
||||
),
|
||||
|
||||
keyboardActions = KeyboardActions(
|
||||
onNext = {
|
||||
|
||||
@ -207,13 +174,16 @@ fun SignUpCard() {
|
||||
}
|
||||
)
|
||||
|
||||
Spacer(modifier = Modifier.height(16.dp))
|
||||
|
||||
Button(
|
||||
colors = ButtonDefaults.buttonColors(
|
||||
backgroundColor = (colorResource(id = R.color.figma_blue)),
|
||||
contentColor = Color.White
|
||||
),
|
||||
onClick = {
|
||||
|
||||
userViewModel.createUser()
|
||||
navHostController.navigate("login")
|
||||
},
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@ -226,8 +196,3 @@ fun SignUpCard() {
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
@Preview(showBackground = true)
|
||||
fun SignUpScreenPreview(){
|
||||
SignUpScreen()
|
||||
}
|
@ -34,14 +34,15 @@ import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.sp
|
||||
import androidx.navigation.NavHostController
|
||||
|
||||
@Composable
|
||||
fun SignUpScreen() {
|
||||
fun SignUpScreen(navHostController: NavHostController) {
|
||||
Column(modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(Color.White),
|
||||
verticalArrangement = Arrangement.Center
|
||||
) {
|
||||
SignUpCard()
|
||||
SignUpCard(navHostController)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user