|
@@ -0,0 +1,674 @@
|
|
|
+package com.example.exvesta.Screans
|
|
|
+
|
|
|
+import android.content.Context
|
|
|
+import android.net.Uri
|
|
|
+import android.util.Log
|
|
|
+import androidx.activity.compose.rememberLauncherForActivityResult
|
|
|
+import androidx.activity.result.contract.ActivityResultContracts
|
|
|
+import androidx.compose.foundation.BorderStroke
|
|
|
+import androidx.compose.foundation.Image
|
|
|
+import androidx.compose.foundation.background
|
|
|
+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.Spacer
|
|
|
+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.offset
|
|
|
+import androidx.compose.foundation.layout.padding
|
|
|
+import androidx.compose.foundation.layout.width
|
|
|
+import androidx.compose.foundation.shape.CircleShape
|
|
|
+import androidx.compose.foundation.shape.RoundedCornerShape
|
|
|
+import androidx.compose.material3.Button
|
|
|
+import androidx.compose.material3.ButtonDefaults
|
|
|
+import androidx.compose.material.DrawerValue
|
|
|
+import androidx.compose.material3.MaterialTheme
|
|
|
+import androidx.compose.material3.Text
|
|
|
+import androidx.compose.material3.rememberDrawerState
|
|
|
+import androidx.compose.runtime.Composable
|
|
|
+import androidx.compose.runtime.rememberCoroutineScope
|
|
|
+import androidx.compose.ui.Alignment
|
|
|
+import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.draw.clip
|
|
|
+import androidx.compose.ui.draw.shadow
|
|
|
+import androidx.compose.ui.graphics.Color
|
|
|
+import androidx.compose.ui.unit.dp
|
|
|
+import androidx.navigation.NavHostController
|
|
|
+
|
|
|
+//noinspection UsingMaterialAndMaterial3Libraries
|
|
|
+import androidx.compose.material.*
|
|
|
+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
|
|
|
+import androidx.compose.ui.graphics.Brush
|
|
|
+import androidx.compose.ui.layout.ContentScale
|
|
|
+import androidx.compose.ui.platform.LocalContext
|
|
|
+import androidx.compose.ui.text.font.FontWeight
|
|
|
+import androidx.compose.ui.unit.sp
|
|
|
+import coil.compose.AsyncImagePainter
|
|
|
+import coil.compose.rememberAsyncImagePainter
|
|
|
+import coil.request.ImageRequest
|
|
|
+import coil.size.Size
|
|
|
+import com.example.exvesta.domain.utils.Constants
|
|
|
+import com.example.exvesta.model.Consists_wardrob
|
|
|
+import com.example.exvesta.model.Publicthings
|
|
|
+import com.example.exvesta.model.Season
|
|
|
+import com.example.exvesta.model.Season_dublicate
|
|
|
+import com.example.exvesta.model.Style
|
|
|
+import com.example.exvesta.model.Style_dublicate
|
|
|
+import com.example.exvesta.model.Things_user
|
|
|
+import com.example.exvesta.model.Type
|
|
|
+import com.example.exvesta.model.Type_dublicate
|
|
|
+import com.example.exvesta.model.Type_subtype
|
|
|
+import com.example.exvesta.model.Type_subtype_dublicate
|
|
|
+import com.example.exvesta.model.Users
|
|
|
+import com.example.exvesta.model.Wardob
|
|
|
+import io.github.jan.supabase.gotrue.auth
|
|
|
+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.foundation.selection.selectable
|
|
|
+import androidx.compose.runtime.livedata.observeAsState
|
|
|
+import androidx.compose.ui.tooling.preview.Preview
|
|
|
+import androidx.core.content.ContextCompat
|
|
|
+import coil.compose.rememberImagePainter
|
|
|
+import android.Manifest
|
|
|
+import android.content.pm.PackageManager
|
|
|
+
|
|
|
+@OptIn(ExperimentalMaterialApi::class, ExperimentalLayoutApi::class)
|
|
|
+@Composable
|
|
|
+fun addBow(navHost: NavHostController) {
|
|
|
+ var drawerState = rememberDrawerState(DrawerValue.Closed)
|
|
|
+ var isBottomSheetVisible by remember { mutableStateOf(true) }
|
|
|
+ val scope = rememberCoroutineScope()
|
|
|
+ var filteredPublicThings by remember { mutableStateOf<List<Consists_wardrob>>(listOf()) }
|
|
|
+ var subdubtype by remember { mutableStateOf<List<Type_subtype>>(listOf()) }
|
|
|
+ var types by remember { mutableStateOf<List<Type>>(listOf()) }
|
|
|
+ var season by remember { mutableStateOf<List<Season>>(listOf()) }
|
|
|
+ var style by remember { mutableStateOf<List<Style>>(listOf()) }
|
|
|
+ var filtersApplied by remember { mutableStateOf(false) }
|
|
|
+ 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()) }
|
|
|
+ var openDialog by remember { mutableStateOf(false) }
|
|
|
+ var itemToDelete by remember { mutableStateOf<Things_user?>(null) }
|
|
|
+ var newThingName by remember { mutableStateOf("") }
|
|
|
+ var newThingName1 by remember { mutableStateOf("") }
|
|
|
+ var newThingName2 by remember { mutableStateOf("") }
|
|
|
+ var newThingName3 by remember { mutableStateOf("") }
|
|
|
+ var selectSeason by remember { mutableStateOf<Season?>(null) }
|
|
|
+ var selectStyle by remember { mutableStateOf<Style?>(null) }
|
|
|
+ var selectSubtype by remember { mutableStateOf<Type_subtype?>(null) }
|
|
|
+ var imageUri by remember { mutableStateOf<Uri?>(null) }
|
|
|
+ var selectwardrob by remember { mutableStateOf<Wardob?>(null) }
|
|
|
+ val context = LocalContext.current
|
|
|
+ var public by remember { mutableStateOf(false) }
|
|
|
+
|
|
|
+ val viewModel = remember { Auth(context) }
|
|
|
+ val userthings by viewModel.userThingsState.collectAsState() // Подписываемся на состояние
|
|
|
+
|
|
|
+ var rememberthings by remember { mutableStateOf<List<Things_user>>(listOf()) }
|
|
|
+ var isFilterSheetVisible by remember { mutableStateOf(false) }
|
|
|
+
|
|
|
+ LaunchedEffect(Unit) {
|
|
|
+ withContext(Dispatchers.IO) {
|
|
|
+// userthings = Constants.supabase.from("Things_user")
|
|
|
+// .select().decodeList<Things_user>()
|
|
|
+ rememberthings = Constants.supabase.from("Things_user")
|
|
|
+ .select().decodeList<Things_user>()
|
|
|
+ wardrobs = Constants.supabase.from("Wardob")
|
|
|
+ .select().decodeList<Wardob>()
|
|
|
+ cwardrobs = Constants.supabase.from("Consists_wardrob")
|
|
|
+ .select().decodeList<Consists_wardrob>()
|
|
|
+ subdubtype = Constants.supabase.from("Type_subtype")
|
|
|
+ .select().decodeList<Type_subtype>()
|
|
|
+ types = Constants.supabase.from("Type")
|
|
|
+ .select().decodeList<Type>()
|
|
|
+ season = Constants.supabase.from("Season")
|
|
|
+ .select().decodeList<Season>()
|
|
|
+ style = Constants.supabase.from("Style")
|
|
|
+ .select().decodeList<Style>()
|
|
|
+ users = Constants.supabase.from("Users")
|
|
|
+ .select().decodeList<Users>()
|
|
|
+// cwardrobs.forEach { it ->
|
|
|
+// Log.d("ts", it.toString())
|
|
|
+
|
|
|
+ }
|
|
|
+ viewModel.refreshUserThings()
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ filteredPublicThings = cwardrobs
|
|
|
+ val imagePickerLauncher = rememberLauncherForActivityResult(
|
|
|
+ contract = ActivityResultContracts.GetContent(),
|
|
|
+ onResult = { uri: Uri? ->
|
|
|
+ imageUri = uri
|
|
|
+ }
|
|
|
+ )
|
|
|
+ val permissionLauncher = rememberLauncherForActivityResult(
|
|
|
+ contract = ActivityResultContracts.RequestPermission(),
|
|
|
+ onResult = { isGranted: Boolean ->
|
|
|
+ if (isGranted) {
|
|
|
+ // Если разрешение предоставлено, открываем галерею
|
|
|
+ imagePickerLauncher.launch("image/*")
|
|
|
+ } else {
|
|
|
+ // Обработка случая, когда разрешение не предоставлено
|
|
|
+ Log.e("Permission", "Разрешение на чтение хранилища не предоставлено")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ )
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // Функция для проверки разрешений
|
|
|
+ @Composable
|
|
|
+ fun checkPermission() {
|
|
|
+ when {
|
|
|
+ ContextCompat.checkSelfPermission(LocalContext.current, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED -> {
|
|
|
+ // Если разрешение уже предоставлено, открываем галерею
|
|
|
+ imagePickerLauncher.launch("image/*")
|
|
|
+ }
|
|
|
+ else -> {
|
|
|
+ // Запрашиваем разрешение
|
|
|
+ permissionLauncher.launch(Manifest.permission.READ_EXTERNAL_STORAGE)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ModalDrawer(
|
|
|
+ drawerState = drawerState,
|
|
|
+ drawerContent = {
|
|
|
+ DrawerContent(navHost)
|
|
|
+ },
|
|
|
+ ) {
|
|
|
+
|
|
|
+ Column(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxSize()
|
|
|
+ .background(Color.White)
|
|
|
+ .padding(16.dp),
|
|
|
+ horizontalAlignment = Alignment.CenterHorizontally
|
|
|
+ ) {
|
|
|
+ Row(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(vertical = 16.dp),
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
+ horizontalArrangement = Arrangement.Start
|
|
|
+ ) {
|
|
|
+ IconButton(onClick = {
|
|
|
+ scope.launch { drawerState.open() }
|
|
|
+ }) {
|
|
|
+ Icon(imageVector = Icons.Filled.Menu, contentDescription = "Menu")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Column(){
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+
|
|
|
+ scope.launch { isFilterSheetVisible = true } // Закрываем drawer
|
|
|
+ },
|
|
|
+ border = BorderStroke(1.dp, Color(0xFF92A2B0)),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(vertical = 8.dp),
|
|
|
+ colors = ButtonDefaults.buttonColors(Color.White)
|
|
|
+ ) {
|
|
|
+ Text(text = "+ добавить фильтр", color = Color(0xFF92A2B0))
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (filtersApplied) {
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+// userthings = rememberthings
|
|
|
+ filtersApplied = false
|
|
|
+ },
|
|
|
+ border = BorderStroke(1.dp, Color(0xFF92A2B0)),
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(vertical = 8.dp),
|
|
|
+ colors = ButtonDefaults.buttonColors(Color(0xFFF1F1F3))
|
|
|
+ ) {
|
|
|
+ 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) {
|
|
|
+ val userWardrobes = wardrobs.filter { it.id_user == authorizedUser.id } // Предполагается, что у вас есть поле userId в Wardob
|
|
|
+
|
|
|
+ // Если у пользователя есть гардеробы, выбираем первый
|
|
|
+ if (userWardrobes.isNotEmpty()) {
|
|
|
+ selectwardrob = userWardrobes.first() // Сохраняем первый гардероб в selectwardrob
|
|
|
+ } else {
|
|
|
+ // Обработка случая, когда у пользователя нет гардеробов
|
|
|
+ Log.d("Wardrob", "У пользователя нет гардеробов.")
|
|
|
+ }
|
|
|
+ // 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().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
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(250.dp),
|
|
|
+ contentAlignment = Alignment.Center
|
|
|
+ ) {
|
|
|
+ CircularProgressIndicator()
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ 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)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ itemToDelete = thing
|
|
|
+ openDialog = true
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .padding(8.dp)
|
|
|
+ .align(Alignment.CenterHorizontally)
|
|
|
+ ) {
|
|
|
+
|
|
|
+
|
|
|
+ Text("Удалить")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (itemToDelete != null) {
|
|
|
+ DeleteConfirmationDialog(
|
|
|
+ openDialog = openDialog,
|
|
|
+ userthing = itemToDelete!!, // Уверены, что itemToDelete не null
|
|
|
+ onConfirm = { item ->
|
|
|
+ item?.let {
|
|
|
+
|
|
|
+ viewModel.deleteItem(it) // Вызов функции удаления из ViewModel
|
|
|
+
|
|
|
+ }
|
|
|
+ openDialog = false // Закрыть диалог
|
|
|
+ itemToDelete = null // Сбросить элемент после удаления
|
|
|
+ },
|
|
|
+ onDismiss = {
|
|
|
+ openDialog = false // Закрыть диалог при отмене
|
|
|
+ itemToDelete = null // Сбросить элемент после закрытия диалога
|
|
|
+ },
|
|
|
+ navHost
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ if (isBottomSheetVisible) {
|
|
|
+ ModalBottomSheetLayout(
|
|
|
+ sheetState = rememberModalBottomSheetState(ModalBottomSheetValue.Expanded),
|
|
|
+ sheetContent = {
|
|
|
+ Column( modifier = Modifier
|
|
|
+ .fillMaxHeight()
|
|
|
+ .fillMaxWidth()
|
|
|
+ .background(
|
|
|
+ Brush.verticalGradient(
|
|
|
+ colors = listOf(
|
|
|
+ Color(0xFFF4F4F4),
|
|
|
+ Color(0xFFE7D2A9),
|
|
|
+ Color(0xFFC1A88B),
|
|
|
+ Color(0xFF6F4A48)
|
|
|
+ )
|
|
|
+ )
|
|
|
+ )) {
|
|
|
+ Box(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth() // Бокс на всю ширину
|
|
|
+ .padding(start = 16.dp, end = 16.dp)
|
|
|
+ .background(
|
|
|
+ color = Color.White,
|
|
|
+ shape = RoundedCornerShape(16.dp) // Закругленные края
|
|
|
+ )
|
|
|
+ .padding(16.dp) // Отступы внутри бокса
|
|
|
+ ) {
|
|
|
+
|
|
|
+ // Отображение выбранного изображения
|
|
|
+
|
|
|
+
|
|
|
+ LazyColumn(horizontalAlignment = Alignment.CenterHorizontally) {
|
|
|
+ item {
|
|
|
+ Text("Новый образ", fontWeight = FontWeight.Bold)
|
|
|
+
|
|
|
+ // Поле для ввода названия вещи
|
|
|
+ TextField(
|
|
|
+ value = newThingName,
|
|
|
+ onValueChange = { newThingName = it },
|
|
|
+ label = { Text("Название образа") },
|
|
|
+ modifier = Modifier.fillMaxWidth()
|
|
|
+ )
|
|
|
+
|
|
|
+ // Выбор изображения
|
|
|
+ Button(onClick = {
|
|
|
+ imagePickerLauncher.launch("image/*")
|
|
|
+ }) {
|
|
|
+ Text("Выбрать изображение")
|
|
|
+ }
|
|
|
+ imageUri?.let {
|
|
|
+ Image(
|
|
|
+ painter = rememberImagePainter(it),
|
|
|
+ contentDescription = "Выбранное изображение",
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(200.dp)
|
|
|
+ .clip(RoundedCornerShape(8.dp))
|
|
|
+ .padding(vertical = 8.dp)
|
|
|
+ )
|
|
|
+ }
|
|
|
+ Spacer(modifier = Modifier.height(10.dp)) // Отступ между текстом и кнопкой
|
|
|
+ TextField(
|
|
|
+ value = newThingName1,
|
|
|
+ onValueChange = { newThingName1 = it },
|
|
|
+ label = { Text("Название вещи 1") },
|
|
|
+ modifier = Modifier.fillMaxWidth()
|
|
|
+ )
|
|
|
+ Spacer(modifier = Modifier.height(10.dp)) // Отступ между текстом и кнопкой
|
|
|
+ TextField(
|
|
|
+ value = newThingName2,
|
|
|
+ onValueChange = { newThingName2 = it },
|
|
|
+ label = { Text("Название вещи 2") },
|
|
|
+ modifier = Modifier.fillMaxWidth()
|
|
|
+ )
|
|
|
+ Spacer(modifier = Modifier.height(10.dp)) // Отступ между текстом и кнопкой
|
|
|
+ TextField(
|
|
|
+ value = newThingName3,
|
|
|
+ onValueChange = { newThingName3 = it },
|
|
|
+ label = { Text("Название вещи 2") },
|
|
|
+ modifier = Modifier.fillMaxWidth()
|
|
|
+ )
|
|
|
+
|
|
|
+ Spacer(modifier = Modifier.height(10.dp)) // Отступ между текстом и кнопкой
|
|
|
+ Text("Публиковать?")
|
|
|
+ Row(
|
|
|
+ verticalAlignment = Alignment.CenterVertically,
|
|
|
+ modifier = Modifier
|
|
|
+
|
|
|
+ .selectable(
|
|
|
+ selected = (public),
|
|
|
+ onClick = { public = true}
|
|
|
+ )
|
|
|
+ .padding(top = 14.dp)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ ) {
|
|
|
+ androidx.compose.material3.RadioButton(
|
|
|
+ selected = (public),
|
|
|
+ onClick = { public = true}
|
|
|
+ )
|
|
|
+ Text(
|
|
|
+ text = "Да",
|
|
|
+ fontSize = 16.sp,
|
|
|
+ modifier = Modifier.padding(start = 0.dp), // Отступ слева от радиокнопки
|
|
|
+ color = Color(0xFF92A2B0)
|
|
|
+
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ Column(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .padding(bottom = 50.dp), // Отступ внизу для всего столбца
|
|
|
+ verticalArrangement = Arrangement.Bottom // Располагаем кнопки внизу
|
|
|
+ ) {
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ viewModel.insertItem(
|
|
|
+ season = selectSeason?.id ?: 0,
|
|
|
+ styles = selectStyle?.id ?: 0,
|
|
|
+ title = newThingName,
|
|
|
+ subtype = selectSubtype?.id ?: 0,
|
|
|
+ imgUri = imageUri
|
|
|
+ )
|
|
|
+ // Закрываем панель
|
|
|
+
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(50.dp)
|
|
|
+ .padding(horizontal = 20.dp)
|
|
|
+ .background(
|
|
|
+ brush = Brush.horizontalGradient(
|
|
|
+ colors = listOf(
|
|
|
+ Color(0xFF6F4A48),
|
|
|
+ Color(0xFFE7D2A9),
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ shape = ButtonDefaults.shape
|
|
|
+ ),
|
|
|
+ colors = ButtonDefaults.buttonColors(containerColor = Color.Transparent),
|
|
|
+ ) {
|
|
|
+ Text("Добавить")
|
|
|
+ }
|
|
|
+
|
|
|
+ Spacer(modifier = Modifier.height(10.dp)) // Отступ между кнопками
|
|
|
+
|
|
|
+ Button(
|
|
|
+ onClick = {
|
|
|
+ val filteredSortedThings = userthings
|
|
|
+
|
|
|
+ // Обрабатываем результат
|
|
|
+ Log.d("SortedThings", filteredSortedThings.toString())
|
|
|
+ val lastId: Int? = filteredSortedThings.lastOrNull()?.id
|
|
|
+
|
|
|
+ if (lastId == null) {
|
|
|
+ Log.e("lastId", "lastId is null, filteredSortedThings is empty or does not have a valid id")
|
|
|
+ } else {
|
|
|
+ Log.d("lastId", lastId.toString())
|
|
|
+ viewModel.addc(
|
|
|
+ idWardrob = selectwardrob?.id ?: 0,
|
|
|
+ firstId = lastId
|
|
|
+ )
|
|
|
+ }
|
|
|
+
|
|
|
+ isBottomSheetVisible = false
|
|
|
+ navHost.navigate("Wardrob")
|
|
|
+
|
|
|
+ },
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxWidth()
|
|
|
+ .height(50.dp)
|
|
|
+ .padding(horizontal = 20.dp)
|
|
|
+ .background(
|
|
|
+ brush = Brush.horizontalGradient(
|
|
|
+ colors = listOf(
|
|
|
+ Color(0xFF6F4A48),
|
|
|
+ Color(0xFFE7D2A9),
|
|
|
+ )
|
|
|
+ ),
|
|
|
+ shape = ButtonDefaults.shape
|
|
|
+ ),
|
|
|
+ colors = ButtonDefaults.buttonColors(containerColor = Color.Transparent),
|
|
|
+ ) {
|
|
|
+ Text("Добавить")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ content = {
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ )
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (isFilterSheetVisible) {
|
|
|
+ Column {
|
|
|
+ FiltersUser(
|
|
|
+ onApplyFilter = { selectedSubtype, selectedSeason, selectedStyle ->
|
|
|
+ // Получаем текущего авторизованного пользователя
|
|
|
+ val userId = Constants.supabase.auth.currentUserOrNull()?.id
|
|
|
+ val authorizedUser = users.find { it.user == userId }
|
|
|
+
|
|
|
+ if (authorizedUser != null) {
|
|
|
+
|
|
|
+ userthings.filter { userthing ->
|
|
|
+ (selectedSubtype == null || userthing.subtype == selectedSubtype.id) &&
|
|
|
+ (selectedSeason == null || userthing.id_season == selectedSeason.id) &&
|
|
|
+ (selectedStyle == null || userthing.style == selectedStyle.id)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ isFilterSheetVisible = false // Закрываем окно фильтров
|
|
|
+ filtersApplied = true
|
|
|
+ },
|
|
|
+ onDismiss = { isFilterSheetVisible = false }
|
|
|
+ )
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|