Переглянути джерело

input user things completed

Anna 1 тиждень тому
батько
коміт
0d9f99759d

+ 1 - 0
Project_exvesta/app/build.gradle.kts

@@ -66,6 +66,7 @@ dependencies {
     implementation(libs.volley)
     implementation(libs.androidx.espresso.core)
     implementation(libs.androidx.tools.core)
+    implementation(libs.androidx.appcompat)
     testImplementation(libs.junit)
     androidTestImplementation(libs.androidx.junit)
     androidTestImplementation(libs.androidx.espresso.core)

+ 19 - 0
Project_exvesta/app/src/main/java/com/example/exvesta/Screans/Auth.kt

@@ -6,12 +6,15 @@ import androidx.navigation.NavController
 import androidx.navigation.NavHostController
 
 import com.example.exvesta.domain.utils.Constants
+import com.example.exvesta.model.Consists_wardrob
+import com.example.exvesta.model.Things_user
 import io.github.jan.supabase.gotrue.providers.builtin.OTP
 import kotlinx.coroutines.launch
 
 
 import io.github.jan.supabase.gotrue.auth
 import io.github.jan.supabase.gotrue.providers.builtin.Email
+import io.github.jan.supabase.postgrest.from
 
 
 class  Auth(): ViewModel(){
@@ -67,6 +70,22 @@ class  Auth(): ViewModel(){
         }
     }
 
+fun deleteItem(userthing: Consists_wardrob){
+    viewModelScope.launch {
 
+        try {
+            val del = Constants.supabase.from("Things_user").delete() {
+
+                filter{
+                    Things_user::id eq userthing.id
+                }
+            }.decodeList<Things_user>()
+        }
+        catch (e: Exception){
+            println("Error")
+            println(e.message.toString())
+        }
+    }
+}
 
 }

+ 3 - 1
Project_exvesta/app/src/main/java/com/example/exvesta/Screans/Home.kt

@@ -68,6 +68,7 @@ import androidx.compose.material.icons.filled.Menu
 import androidx.compose.material.*
 import androidx.compose.ui.graphics.Brush
 import androidx.navigation.NavHost
+import io.github.jan.supabase.gotrue.auth
 import kotlinx.coroutines.launch
 
 
@@ -484,8 +485,9 @@ fun Home(navHost: NavHostController) {
                     contentAlignment = Alignment.Center
             ){}}
             Spacer(modifier = Modifier.height(16.dp))
+            val username = Constants.supabase.auth.currentUserOrNull()?.email
             Text(
-                text = "user_name",
+                text = "${username}",
                 fontSize = 16.sp,
                 fontWeight = FontWeight.Medium,
                 color = Color(0xFF92A2B0)

+ 161 - 247
Project_exvesta/app/src/main/java/com/example/exvesta/Screans/Wardrob.kt

@@ -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("Нет")
+                }
+            }
+        )
+    }
+}
+
 

+ 1 - 1
Project_exvesta/app/src/main/java/com/example/exvesta/model/Things_user.kt

@@ -9,5 +9,5 @@ public data class Things_user (
     val img: String?,
     val id_season: Int,
     val no: Boolean?,
-    val public_status: Boolean?
+    val public_status: Boolean?,
 )

+ 1 - 1
Project_exvesta/app/src/main/java/com/example/exvesta/model/Users.kt

@@ -4,5 +4,5 @@ import kotlinx.serialization.Serializable
 public data class Users(
     val id: Int,
     val user: String?,
-    val Name: String
+    val Name: String?
 )

+ 2 - 0
Project_exvesta/gradle/libs.versions.toml

@@ -24,6 +24,7 @@ volley = "1.2.1"
 material = "1.7.5"
 coilCompose = "2.4.0"
 toolsCore = "1.0.0-alpha10"
+appcompat = "1.7.0"
 [libraries]
 androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
 bom = { module = "io.github.jan-tennert.supabase:bom", version.ref = "bom" }
@@ -69,6 +70,7 @@ androidx-runtime-android = { group = "androidx.compose.runtime", name = "runtime
 androidx-ui-android = { group = "androidx.compose.ui", name = "ui-android", version.ref = "uiAndroid" }
 volley = { group = "com.android.volley", name = "volley", version.ref = "volley" }
 androidx-tools-core = { group = "androidx.privacysandbox.tools", name = "tools-core", version.ref = "toolsCore" }
+androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "appcompat" }
 
 [plugins]
 android-application = { id = "com.android.application", version.ref = "agp" }