|
@@ -1,2 +1,304 @@
|
|
|
package com.example.triphelper.view.RouteScreens
|
|
|
|
|
|
+import androidx.compose.foundation.background
|
|
|
+import androidx.compose.foundation.border
|
|
|
+import androidx.compose.foundation.layout.Arrangement
|
|
|
+import androidx.compose.foundation.layout.Box
|
|
|
+import androidx.compose.foundation.layout.Column
|
|
|
+import androidx.compose.foundation.layout.Row
|
|
|
+import androidx.compose.foundation.layout.fillMaxHeight
|
|
|
+import androidx.compose.foundation.layout.fillMaxSize
|
|
|
+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.material3.Button
|
|
|
+import androidx.compose.material3.ButtonDefaults.buttonColors
|
|
|
+import androidx.compose.material3.DropdownMenu
|
|
|
+import androidx.compose.material3.DropdownMenuItem
|
|
|
+import androidx.compose.material3.Icon
|
|
|
+import androidx.compose.material3.Text
|
|
|
+import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.LaunchedEffect
|
|
|
+import androidx.compose.runtime.MutableState
|
|
|
+import androidx.compose.runtime.collectAsState
|
|
|
+import androidx.compose.runtime.getValue
|
|
|
+import androidx.compose.runtime.mutableStateOf
|
|
|
+import androidx.compose.runtime.remember
|
|
|
+import androidx.compose.runtime.setValue
|
|
|
+import androidx.compose.ui.Alignment
|
|
|
+import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.draw.clip
|
|
|
+import androidx.compose.ui.graphics.Color
|
|
|
+import androidx.compose.ui.res.painterResource
|
|
|
+import androidx.compose.ui.text.font.FontWeight
|
|
|
+import androidx.compose.ui.text.style.TextAlign
|
|
|
+import androidx.compose.ui.unit.dp
|
|
|
+import androidx.compose.ui.unit.sp
|
|
|
+import androidx.hilt.navigation.compose.hiltViewModel
|
|
|
+import androidx.navigation.NavController
|
|
|
+import com.example.testirovanye_supabase.R
|
|
|
+import com.example.triphelper.view.navigation.NavigationRoutes
|
|
|
+import com.example.triphelper.view.style.ButtonStyleBackSquare
|
|
|
+import com.example.triphelper.view.style.StyleMainFone
|
|
|
+import com.example.triphelper.view.theme.Roboto
|
|
|
+import com.example.triphelper.view.theme.RobotoB
|
|
|
+import com.example.triphelper.view.theme.SeoulBold
|
|
|
+
|
|
|
+@Composable
|
|
|
+fun ChoiceLocation(navController: NavController, iconsRouteIsActivity: MutableState<Boolean>, viewModel: RouteViewModel = hiltViewModel()) {
|
|
|
+ iconsRouteIsActivity.value = true
|
|
|
+ var selectedItemCountry by remember { mutableStateOf("") } //Переменная для всплывающего списка
|
|
|
+ var selectedItemCity by remember { mutableStateOf("") }
|
|
|
+ val coutryTitle = remember { mutableStateOf("") } //Переменная для сохранения названия страны
|
|
|
+ val country by viewModel.country.collectAsState(initial = emptyList())
|
|
|
+ val city by viewModel.city.collectAsState(initial = emptyList())
|
|
|
+ val cityTitle = remember { mutableStateOf("") }
|
|
|
+ var expandedCountry by remember { mutableStateOf(false) } //Переменная для всплывающего списка
|
|
|
+ var expandedCity by remember { mutableStateOf(false) }
|
|
|
+
|
|
|
+ LaunchedEffect(key1 = viewModel.navigationTo) {
|
|
|
+ viewModel.navigationTo.collect { destination ->
|
|
|
+ destination?.let {
|
|
|
+ navController.navigate(destination)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ StyleMainFone()
|
|
|
+ Column(
|
|
|
+ modifier = Modifier.fillMaxWidth().fillMaxHeight(0.9f),
|
|
|
+ verticalArrangement = Arrangement.Center,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ) {
|
|
|
+ Column(
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
+ verticalArrangement = Arrangement.Center,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ){
|
|
|
+ Text(
|
|
|
+ text = "Страна",
|
|
|
+ fontFamily = SeoulBold,
|
|
|
+ fontWeight = FontWeight.Bold,
|
|
|
+ fontSize = 40.sp,
|
|
|
+ color = Color(0xFF510B3C),
|
|
|
+ modifier = Modifier.padding(20.dp)
|
|
|
+ )
|
|
|
+ Box(modifier = Modifier.padding(20.dp)) {
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ expandedCountry = true
|
|
|
+ viewModel.getCountry()
|
|
|
+ },
|
|
|
+ shape = RoundedCornerShape(15.dp),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(0.9f)
|
|
|
+ .height(70.dp)
|
|
|
+ .border(
|
|
|
+ width = 4.dp,
|
|
|
+ color = Color(0xFF510B3C),
|
|
|
+ shape = RoundedCornerShape(15.dp)
|
|
|
+ ),
|
|
|
+ colors = buttonColors(
|
|
|
+ containerColor = Color.White
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ Row(
|
|
|
+ modifier = Modifier.fillMaxSize(),
|
|
|
+ horizontalArrangement = Arrangement.Start,
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ )
|
|
|
+ {
|
|
|
+ if (selectedItemCountry.isEmpty()) {
|
|
|
+ Row(
|
|
|
+ horizontalArrangement = Arrangement.SpaceBetween,
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
+ modifier = Modifier.fillMaxWidth()
|
|
|
+ )
|
|
|
+ {
|
|
|
+ Text(
|
|
|
+ "Выберите страну",
|
|
|
+ fontFamily = RobotoB,
|
|
|
+ fontSize = 22.sp,
|
|
|
+ color = Color(0xFF510B3C).copy(alpha = 0.7f),
|
|
|
+ textAlign = TextAlign.Start
|
|
|
+ )
|
|
|
+ Icon(
|
|
|
+ painter = painterResource(id = R.drawable.galka_down),
|
|
|
+ contentDescription = null,
|
|
|
+ tint = Color(0xFFDC5B6E).copy(alpha = 0.7f),
|
|
|
+
|
|
|
+ )
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Text(
|
|
|
+ "$selectedItemCountry",
|
|
|
+ fontFamily = RobotoB,
|
|
|
+ fontWeight = FontWeight.W600,
|
|
|
+ fontSize = 23.sp,
|
|
|
+ color = Color(0xFF510B3C),
|
|
|
+ textAlign = TextAlign.Start
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DropdownMenu(
|
|
|
+ expanded = expandedCountry,
|
|
|
+ onDismissRequest = { expandedCountry = false },
|
|
|
+ containerColor = Color.White,
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(0.8f)
|
|
|
+ .height(200.dp)
|
|
|
+ ) {
|
|
|
+ country.forEach { item ->
|
|
|
+ DropdownMenuItem(
|
|
|
+ onClick = {
|
|
|
+ selectedItemCountry = item.title
|
|
|
+ coutryTitle.value = item.title
|
|
|
+ expandedCountry = false
|
|
|
+ },
|
|
|
+ text = {
|
|
|
+ Text(
|
|
|
+ text = item.title,
|
|
|
+ fontSize = 18.sp,
|
|
|
+ fontFamily = Roboto,
|
|
|
+ color = Color(0xFF510B3C),
|
|
|
+ fontWeight = FontWeight.Bold,
|
|
|
+ textAlign = TextAlign.Start
|
|
|
+ )
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Column(
|
|
|
+ modifier = Modifier.fillMaxWidth(),
|
|
|
+ verticalArrangement = Arrangement.Center,
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ){
|
|
|
+ Text(
|
|
|
+ text = "Город",
|
|
|
+ fontFamily = SeoulBold,
|
|
|
+ fontWeight = FontWeight.Bold,
|
|
|
+ fontSize = 40.sp,
|
|
|
+ color = Color(0xFF510B3C),
|
|
|
+ modifier = Modifier.padding(20.dp)
|
|
|
+ )
|
|
|
+ Box(modifier = Modifier.padding(20.dp)) {
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ expandedCity = true
|
|
|
+ viewModel.getCity(coutryTitle.value)
|
|
|
+ },
|
|
|
+ shape = RoundedCornerShape(15.dp),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(0.9f)
|
|
|
+ .height(70.dp)
|
|
|
+ .border(
|
|
|
+ width = 4.dp,
|
|
|
+ color = Color(0xFF510B3C),
|
|
|
+ shape = RoundedCornerShape(15.dp)
|
|
|
+ ),
|
|
|
+ colors = buttonColors(
|
|
|
+ containerColor = Color.White
|
|
|
+ )
|
|
|
+ ) {
|
|
|
+ Row(
|
|
|
+ modifier = Modifier.fillMaxSize(),
|
|
|
+ horizontalArrangement = Arrangement.Start,
|
|
|
+ verticalAlignment = Alignment.CenterVertically
|
|
|
+ )
|
|
|
+ {
|
|
|
+ if (selectedItemCity.isEmpty()) {
|
|
|
+ Row(
|
|
|
+ horizontalArrangement = Arrangement.SpaceBetween,
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
+ modifier = Modifier.fillMaxWidth()
|
|
|
+ )
|
|
|
+ {
|
|
|
+ Text(
|
|
|
+ "Выберите город",
|
|
|
+ fontFamily = RobotoB,
|
|
|
+ fontSize = 22.sp,
|
|
|
+ color = Color(0xFF510B3C).copy(alpha = 0.7f),
|
|
|
+ textAlign = TextAlign.Start
|
|
|
+ )
|
|
|
+ Icon(
|
|
|
+ painter = painterResource(id = R.drawable.galka_down),
|
|
|
+ contentDescription = null,
|
|
|
+ tint = Color(0xFFDC5B6E).copy(alpha = 0.7f),
|
|
|
+
|
|
|
+ )
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ Text(
|
|
|
+ "$selectedItemCity",
|
|
|
+ fontFamily = RobotoB,
|
|
|
+ fontWeight = FontWeight.W600,
|
|
|
+ fontSize = 23.sp,
|
|
|
+ color = Color(0xFF510B3C),
|
|
|
+ textAlign = TextAlign.Start
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ DropdownMenu(
|
|
|
+ expanded = expandedCity,
|
|
|
+ onDismissRequest = { expandedCity = false },
|
|
|
+ containerColor = Color.White,
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(0.8f)
|
|
|
+ .height(200.dp)
|
|
|
+ ) {
|
|
|
+ city.forEach { item ->
|
|
|
+ DropdownMenuItem(
|
|
|
+ onClick = {
|
|
|
+ selectedItemCity = item.title
|
|
|
+ cityTitle.value = item.title
|
|
|
+ expandedCity = false
|
|
|
+ },
|
|
|
+ text = {
|
|
|
+ Text(
|
|
|
+ text = item.title,
|
|
|
+ fontSize = 18.sp,
|
|
|
+ fontFamily = Roboto,
|
|
|
+ color = Color(0xFF510B3C),
|
|
|
+ fontWeight = FontWeight.Bold,
|
|
|
+ textAlign = TextAlign.Start
|
|
|
+ )
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(viewModel.wrong.value){
|
|
|
+ Box(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth(0.8f)
|
|
|
+ .clip(RoundedCornerShape(10.dp))
|
|
|
+ .background(color = Color.White)
|
|
|
+ .border(
|
|
|
+ width = 2.dp,
|
|
|
+ color = Color.White,
|
|
|
+ shape = RoundedCornerShape(10.dp)
|
|
|
+ ),
|
|
|
+ ){
|
|
|
+ Text(
|
|
|
+ text = "Не выбран город",
|
|
|
+ fontFamily = Roboto,
|
|
|
+ fontWeight = FontWeight.W600,
|
|
|
+ fontSize = 22.sp,
|
|
|
+ color = Color.Red,
|
|
|
+ modifier = Modifier.align(Alignment.Center)
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ Row(modifier = Modifier.fillMaxWidth(0.6f).padding(top = 20.dp)) {
|
|
|
+ ButtonStyleBackSquare("Далее",33.sp) {
|
|
|
+ navController.navigate("${NavigationRoutes.CH_TOUR}/${cityTitle.value}")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|