|
@@ -1,5 +1,6 @@
|
|
|
package com.example.exvesta.Screans
|
|
|
|
|
|
+import android.content.Context
|
|
|
import android.util.Log
|
|
|
import androidx.compose.foundation.BorderStroke
|
|
|
import androidx.compose.foundation.Image
|
|
@@ -40,6 +41,7 @@ import androidx.compose.runtime.*
|
|
|
|
|
|
import androidx.compose.foundation.layout.*
|
|
|
import androidx.compose.foundation.lazy.LazyColumn
|
|
|
+import androidx.compose.foundation.lazy.LazyRow
|
|
|
import androidx.compose.foundation.lazy.items
|
|
|
import androidx.compose.material.icons.Icons
|
|
|
import androidx.compose.material.icons.filled.Menu
|
|
@@ -71,6 +73,8 @@ import io.github.jan.supabase.postgrest.from
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
import kotlinx.coroutines.launch
|
|
|
import kotlinx.coroutines.withContext
|
|
|
+import androidx.appcompat.app.AlertDialog
|
|
|
+import androidx.compose.ui.tooling.preview.Preview
|
|
|
|
|
|
@Composable
|
|
|
fun Wardrob(navHost: NavHostController) {
|
|
@@ -79,7 +83,7 @@ fun Wardrob(navHost: NavHostController) {
|
|
|
var isFiltersVisible by remember { mutableStateOf(false) }
|
|
|
var filteredPublicThings by remember { mutableStateOf<List<Consists_wardrob>>(listOf()) }
|
|
|
var subdubtype by remember { mutableStateOf<List<Type_subtype>>(listOf()) }
|
|
|
- var type by remember { mutableStateOf<List<Type>>(listOf()) }
|
|
|
+ var types by remember { mutableStateOf<List<Type>>(listOf()) }
|
|
|
var season by remember { mutableStateOf<List<Season>>(listOf()) }
|
|
|
var userthings by remember { mutableStateOf<List<Things_user>>(listOf()) }
|
|
|
var style by remember { mutableStateOf<List<Style>>(listOf()) }
|
|
@@ -88,6 +92,11 @@ fun Wardrob(navHost: NavHostController) {
|
|
|
var wardrobs by remember { mutableStateOf<List<Wardob>>(listOf()) }
|
|
|
var cwardrobs by remember { mutableStateOf<List<Consists_wardrob>>(listOf()) }
|
|
|
var users by remember { mutableStateOf<List<Users>>(listOf()) }
|
|
|
+ val context = LocalContext.current // Получение контекста
|
|
|
+ val coroutineScope = rememberCoroutineScope() // Создание корутинного скоупа
|
|
|
+ var openDialog by remember { mutableStateOf(false) }
|
|
|
+ var itemToDelete by remember { mutableStateOf<Consists_wardrob?>(null) }
|
|
|
+
|
|
|
val viewModel = Auth()
|
|
|
LaunchedEffect(Unit) {
|
|
|
withContext(Dispatchers.IO) {
|
|
@@ -99,7 +108,7 @@ fun Wardrob(navHost: NavHostController) {
|
|
|
.select().decodeList<Consists_wardrob>()
|
|
|
subdubtype = Constants.supabase.from("Type_subtype")
|
|
|
.select().decodeList<Type_subtype>()
|
|
|
- type = Constants.supabase.from("Type")
|
|
|
+ types = Constants.supabase.from("Type")
|
|
|
.select().decodeList<Type>()
|
|
|
season = Constants.supabase.from("Season")
|
|
|
.select().decodeList<Season>()
|
|
@@ -107,13 +116,13 @@ fun Wardrob(navHost: NavHostController) {
|
|
|
.select().decodeList<Style>()
|
|
|
users = Constants.supabase.from("Users")
|
|
|
.select().decodeList<Users>()
|
|
|
- wardrobs.forEach { it ->
|
|
|
- Log.d("ts", it.toString())
|
|
|
+// cwardrobs.forEach { it ->
|
|
|
+// Log.d("ts", it.toString())
|
|
|
}
|
|
|
}
|
|
|
filteredPublicThings = cwardrobs
|
|
|
|
|
|
- }
|
|
|
+
|
|
|
ModalDrawer(
|
|
|
drawerState = drawerState,
|
|
|
drawerContent = {
|
|
@@ -184,271 +193,143 @@ fun Wardrob(navHost: NavHostController) {
|
|
|
Text(text = "сбросить фильтры", color = Color(0xFF92A2B0))
|
|
|
}
|
|
|
}
|
|
|
- Spacer(modifier = Modifier.height(10.dp))
|
|
|
-
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- Row(
|
|
|
- modifier = Modifier.fillMaxWidth(),
|
|
|
- horizontalArrangement = Arrangement.SpaceAround
|
|
|
- ) {
|
|
|
- // Кнопка "вещи"
|
|
|
- Box(
|
|
|
- modifier = Modifier
|
|
|
- .weight(1f)
|
|
|
- .padding(bottom = 4.dp) // Паддинг для отступа от нижней тени
|
|
|
- .clip(RoundedCornerShape(16.dp))
|
|
|
- ) {
|
|
|
- // Тень
|
|
|
- Box(
|
|
|
- modifier = Modifier
|
|
|
- .shadow(8.dp, RoundedCornerShape(30.dp))
|
|
|
-
|
|
|
-
|
|
|
- )
|
|
|
-
|
|
|
- // Кнопка
|
|
|
- Button(
|
|
|
- onClick = { /*TODO*/ },
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
-
|
|
|
- .shadow(
|
|
|
- 0.dp,
|
|
|
- shape = CircleShape,
|
|
|
- clip = false
|
|
|
- )// Убираем тень у кнопки
|
|
|
- .background(
|
|
|
- brush = Brush.horizontalGradient(
|
|
|
- colors = listOf(
|
|
|
- Color(0xFFF1F1F3),
|
|
|
- Color(0xFFFFFFFF),
|
|
|
- )
|
|
|
- ), shape = ButtonDefaults.shape
|
|
|
- ), // Убираем тень у кнопки
|
|
|
- colors = ButtonDefaults.buttonColors(containerColor = Color.Transparent)
|
|
|
-
|
|
|
- ) {
|
|
|
- Text(text = "вещи", color = Color(0xFF92A2B0))
|
|
|
- }
|
|
|
+ DeleteConfirmationDialog(
|
|
|
+ openDialog = openDialog,
|
|
|
+ userthing = itemToDelete!!, // Убедитесь, что itemToDelete не null
|
|
|
+ onConfirm = { item ->
|
|
|
+ viewModel.deleteItem(item) // Вызов функции удаления из ViewModel
|
|
|
+ },
|
|
|
+ onDismiss = {
|
|
|
+ openDialog = false
|
|
|
+ itemToDelete = null // Сбросить элемент после закрытия диалога
|
|
|
}
|
|
|
+ )
|
|
|
|
|
|
- Spacer(modifier = Modifier.width(16.dp))
|
|
|
-
|
|
|
- // Кнопка "образы"
|
|
|
- Box(
|
|
|
- modifier = Modifier
|
|
|
- .weight(1f)
|
|
|
- .padding(bottom = 4.dp) // Паддинг для отступа от нижней тени
|
|
|
- .clip(RoundedCornerShape(16.dp))
|
|
|
- ) {
|
|
|
- // Тень
|
|
|
- Box(
|
|
|
- modifier = Modifier
|
|
|
- .shadow(8.dp, RoundedCornerShape(30.dp))
|
|
|
- )
|
|
|
-
|
|
|
- // Кнопка
|
|
|
- Button(
|
|
|
- onClick = { /*TODO*/ },
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
|
|
|
- .background(
|
|
|
- brush = Brush.horizontalGradient(
|
|
|
- colors = listOf(
|
|
|
- Color(0xFFF1F1F3),
|
|
|
- Color(0xFFFFFFFF),
|
|
|
- )
|
|
|
- ), shape = ButtonDefaults.shape
|
|
|
- ), // Убираем тень у кнопки
|
|
|
- colors = ButtonDefaults.buttonColors(containerColor = Color.Transparent),
|
|
|
-
|
|
|
- ) {
|
|
|
- Text(text = "образы", color = Color(0xFF92A2B0))
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
Spacer(modifier = Modifier.height(10.dp))
|
|
|
+ val userId = Constants.supabase.auth.currentUserOrNull()?.id
|
|
|
+ val authorizedUser = users.find { it.user == userId }
|
|
|
+
|
|
|
+ if (authorizedUser != null) {
|
|
|
+ // Group items by type
|
|
|
+ val itemsByType = filteredPublicThings.groupBy { userthing ->
|
|
|
+ val thing = userthings.find { it.id == userthing.id_thing }
|
|
|
+ thing?.subtype?.let { subtype ->
|
|
|
+ subdubtype.find { it.id == subtype }?.id_type
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- LazyColumn(
|
|
|
-
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxSize(1f)
|
|
|
- .padding(10.dp)
|
|
|
- ) {
|
|
|
-
|
|
|
- items(
|
|
|
- filteredPublicThings
|
|
|
-
|
|
|
- ) { cwardrob ->
|
|
|
- val userid = cwardrob.id
|
|
|
- val war = wardrobs.find { it.id == userid }
|
|
|
- val user = users.find { it.id == userid}
|
|
|
- val userId = Constants.supabase.auth.currentUserOrNull()?.id
|
|
|
-
|
|
|
- if(user != null){
|
|
|
- if( user.user == userId) {
|
|
|
- Log.d("пользователь таблицы ", user.user.toString())
|
|
|
- Log.d("пользователь авторизации ",userId.toString())
|
|
|
-
|
|
|
- if (war != null) {
|
|
|
- if (cwardrob.id_wardrob == war.id &&user.id == war.id ) {
|
|
|
- val thingid = cwardrob.id_thing
|
|
|
- val thing = userthings.find {it.id == thingid }
|
|
|
- if(thing!=null) {
|
|
|
-
|
|
|
- val imageState = rememberAsyncImagePainter(
|
|
|
- model = ImageRequest.Builder(LocalContext.current)
|
|
|
- .data(thing.img)
|
|
|
- .size(Size.ORIGINAL).build()
|
|
|
- ).state
|
|
|
-
|
|
|
- Box(
|
|
|
- modifier = Modifier
|
|
|
- .shadow(8.dp, RoundedCornerShape(30.dp))
|
|
|
- ) {
|
|
|
+ LazyColumn(modifier = Modifier.fillMaxSize().padding(10.dp)) {
|
|
|
+ items(types) { type ->
|
|
|
+ val typeItems = itemsByType[type.id] ?: emptyList()
|
|
|
+
|
|
|
+ if (typeItems.isNotEmpty()) {
|
|
|
+ Text(
|
|
|
+ text = type.title_type,
|
|
|
+
|
|
|
+ modifier = Modifier.padding(8.dp)
|
|
|
+ )
|
|
|
+
|
|
|
+ LazyRow {
|
|
|
+ items(typeItems) { userthing ->
|
|
|
+ val thing = userthings.find { it.id == userthing.id_thing }
|
|
|
+ if (thing != null) {
|
|
|
+ val imageState = rememberAsyncImagePainter(
|
|
|
+ model = ImageRequest.Builder(LocalContext.current)
|
|
|
+ .data(thing.img)
|
|
|
+ .size(Size.ORIGINAL).build()
|
|
|
+ ).state
|
|
|
+
|
|
|
+ Card(
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(8.dp)
|
|
|
+ .width(330.dp)
|
|
|
+ .shadow(8.dp, RoundedCornerShape(30.dp)),
|
|
|
+ shape = RoundedCornerShape(30.dp),
|
|
|
+ backgroundColor = Color.White
|
|
|
+ ) {
|
|
|
+ Column {
|
|
|
+ if (imageState is AsyncImagePainter.State.Error) {
|
|
|
Box(
|
|
|
modifier = Modifier
|
|
|
- .background(
|
|
|
-
|
|
|
- Color.White,
|
|
|
-
|
|
|
- shape = RoundedCornerShape(30.dp)
|
|
|
- )
|
|
|
- .padding(8.dp)
|
|
|
- .wrapContentSize(Alignment.Center)
|
|
|
-
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(250.dp),
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
) {
|
|
|
-
|
|
|
- Column(
|
|
|
- )
|
|
|
- {
|
|
|
- if (imageState is AsyncImagePainter.State.Error) {
|
|
|
- Box(
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
-
|
|
|
- .height(250.dp),
|
|
|
- contentAlignment = Alignment.Center
|
|
|
- ) {
|
|
|
- androidx.compose.material3.CircularProgressIndicator()
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (imageState is AsyncImagePainter.State.Success) {
|
|
|
- Image(
|
|
|
- modifier = Modifier
|
|
|
- .fillMaxWidth()
|
|
|
- .height(250.dp)
|
|
|
-
|
|
|
- ,
|
|
|
- painter = imageState.painter,
|
|
|
- contentDescription = "",
|
|
|
- contentScale = ContentScale.Crop
|
|
|
-
|
|
|
-
|
|
|
- )
|
|
|
- }
|
|
|
- androidx.compose.material3.Divider(
|
|
|
- modifier = Modifier.padding(vertical = 8.dp),
|
|
|
- color = Color.LightGray,
|
|
|
- thickness = 1.dp
|
|
|
- )
|
|
|
- Spacer(modifier = Modifier.height(8.dp))
|
|
|
- Text(
|
|
|
- "Название: ${thing.title}",
|
|
|
- fontSize = 18.sp,
|
|
|
- modifier = Modifier.padding(start = 8.dp),
|
|
|
- color = Color(0xFF92A2B0)
|
|
|
- )
|
|
|
- val seasonid = thing.id_season
|
|
|
- val season =
|
|
|
- season.find { it.id == seasonid }
|
|
|
- val styleid =thing.style
|
|
|
- val style =
|
|
|
- style.find { it.id == styleid }
|
|
|
- val subtypeid = thing.subtype
|
|
|
- val subtype =
|
|
|
- subdubtype.find { it.id == subtypeid }
|
|
|
-
|
|
|
- if (subtype != null) {
|
|
|
- val typeid = subtype.id_type
|
|
|
- val type =
|
|
|
- type.find { it.id == typeid }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- if (season != null && style != null && type != null) {
|
|
|
- Text(
|
|
|
- "Категории: ${style.title_style}, ${type.title_type}, ${subtype.sub_type}, ${season.title_season}",
|
|
|
- fontSize = 18.sp,
|
|
|
- modifier = Modifier.padding(
|
|
|
- start = 8.dp
|
|
|
- ),
|
|
|
- color = Color(0xFF92A2B0)
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- Spacer(modifier = Modifier.height(8.dp))
|
|
|
- Row(
|
|
|
- horizontalArrangement = Arrangement.SpaceAround
|
|
|
- )
|
|
|
- {
|
|
|
-
|
|
|
-
|
|
|
- Button(
|
|
|
- onClick = { navHost.navigate("Registration") },
|
|
|
- modifier = Modifier
|
|
|
- .width(200.dp)
|
|
|
- .height(50.dp)
|
|
|
- .padding(start = 50.dp),
|
|
|
- colors = ButtonDefaults.buttonColors(
|
|
|
- Color(0xFF6F4A48),
|
|
|
- contentColor = Color.White
|
|
|
- ),
|
|
|
- shape = ButtonDefaults.shape
|
|
|
- ) {
|
|
|
- Text(
|
|
|
- text = "Удалить",
|
|
|
- fontSize = 16.sp,
|
|
|
- fontWeight = FontWeight.Medium
|
|
|
- )
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
+ CircularProgressIndicator()
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- Spacer(modifier = Modifier.height(16.dp))
|
|
|
-
|
|
|
+ if (imageState is AsyncImagePainter.State.Success) {
|
|
|
+ Image(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(250.dp),
|
|
|
+ painter = imageState.painter,
|
|
|
+ contentDescription = "",
|
|
|
+ contentScale = ContentScale.Crop
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
+ Divider(
|
|
|
+ modifier = Modifier.padding(vertical = 8.dp),
|
|
|
+ color = Color.LightGray,
|
|
|
+ thickness = 1.dp
|
|
|
+ )
|
|
|
+
|
|
|
+ Text(
|
|
|
+ "Название: ${thing.title}",
|
|
|
+ fontSize = 18.sp,
|
|
|
+ modifier = Modifier.padding(start = 8.dp),
|
|
|
+ color = Color(0xFF92A2B0)
|
|
|
+ )
|
|
|
+
|
|
|
+ // Display categories
|
|
|
+ val seasonid = thing.id_season
|
|
|
+ val seasonItem = season.find { it.id == seasonid }
|
|
|
+ val styleid = thing.style
|
|
|
+ val styleItem = style.find { it.id == styleid }
|
|
|
+ val subtypeid = thing.subtype
|
|
|
+ val subtypeItem =
|
|
|
+ subdubtype.find { it.id == subtypeid }
|
|
|
+
|
|
|
+ if (subtypeItem != null) {
|
|
|
+ val typeid = subtypeItem.id_type
|
|
|
+ val typeItem = types.find { it.id == typeid }
|
|
|
+ if (seasonItem != null && styleItem != null && typeItem != null) {
|
|
|
+ Text(
|
|
|
+ "Категории: ${styleItem.title_style}, ${typeItem.title_type}, ${subtypeItem.sub_type}, ${seasonItem.title_season}",
|
|
|
+ fontSize = 18.sp,
|
|
|
+ modifier = Modifier.padding(start = 8.dp),
|
|
|
+ color = Color(0xFF92A2B0)
|
|
|
+ )
|
|
|
+ }
|
|
|
}
|
|
|
- Spacer(modifier = Modifier.height(20.dp))
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ itemToDelete = userthing
|
|
|
+ openDialog = true
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(8.dp)
|
|
|
+ .align(Alignment.CenterHorizontally)
|
|
|
+ ) {
|
|
|
+ Text("Удалить")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-}
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -475,4 +356,37 @@ fun Wardrob(navHost: NavHostController) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+@Composable
|
|
|
+fun DeleteConfirmationDialog(
|
|
|
+ openDialog: Boolean,
|
|
|
+ userthing: Consists_wardrob,
|
|
|
+ onConfirm: (Consists_wardrob) -> Unit,
|
|
|
+ onDismiss: () -> Unit
|
|
|
+) {
|
|
|
+ if (openDialog) {
|
|
|
+ AlertDialog(
|
|
|
+ onDismissRequest = onDismiss,
|
|
|
+ title = {
|
|
|
+ Text(text = "Подтверждение удаления")
|
|
|
+ },
|
|
|
+ text = {
|
|
|
+ Text("Вы уверены, что хотите удалить эту вещь?")
|
|
|
+ },
|
|
|
+ confirmButton = {
|
|
|
+ Button(onClick = {
|
|
|
+ onConfirm(userthing) // Вызов функции для удаления элемента
|
|
|
+ onDismiss() // Закрыть диалог после подтверждения
|
|
|
+ }) {
|
|
|
+ Text("Да")
|
|
|
+ }
|
|
|
+ },
|
|
|
+ dismissButton = {
|
|
|
+ Button(onClick = onDismiss) {
|
|
|
+ Text("Нет")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
|