Răsfoiți Sursa

App: input user things

БезаеваАА 5 zile în urmă
părinte
comite
6ff14d6dde

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

@@ -4,7 +4,7 @@ import androidx.lifecycle.ViewModel
 import androidx.lifecycle.viewModelScope
 import androidx.navigation.NavController
 import androidx.navigation.NavHostController
-import androidx.privacysandbox.tools.core.model.Constant
+
 import com.example.exvesta.domain.utils.Constants
 import io.github.jan.supabase.gotrue.providers.builtin.OTP
 import kotlinx.coroutines.launch

+ 184 - 157
Project_exvesta/app/src/main/java/com/example/exvesta/Screans/Wardrob.kt

@@ -66,6 +66,7 @@ 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
@@ -76,7 +77,7 @@ fun Wardrob(navHost: NavHostController) {
     var drawerState = rememberDrawerState(DrawerValue.Closed)
     val scope = rememberCoroutineScope()
     var isFiltersVisible by remember { mutableStateOf(false) }
-    var filteredPublicThings by remember { mutableStateOf<List<Wardob>>(listOf()) }
+    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 season by remember { mutableStateOf<List<Season>>(listOf()) }
@@ -85,15 +86,16 @@ fun Wardrob(navHost: NavHostController) {
     var filtersApplied by remember { mutableStateOf(false) }
     var isFilterSheetVisible by remember { mutableStateOf(false) }
     var wardrobs by remember { mutableStateOf<List<Wardob>>(listOf()) }
-    var cwardrob by remember { mutableStateOf<List<Consists_wardrob>>(listOf()) }
+    var cwardrobs by remember { mutableStateOf<List<Consists_wardrob>>(listOf()) }
     var users by remember { mutableStateOf<List<Users>>(listOf()) }
+    val viewModel = Auth()
     LaunchedEffect(Unit) {
         withContext(Dispatchers.IO) {
             userthings  = Constants.supabase.from("Things_user")
                 .select().decodeList<Things_user>()
             wardrobs  = Constants.supabase.from("Wardob")
                 .select().decodeList<Wardob>()
-            cwardrob  = Constants.supabase.from("Consists_wardrob")
+            cwardrobs  = Constants.supabase.from("Consists_wardrob")
                 .select().decodeList<Consists_wardrob>()
             subdubtype = Constants.supabase.from("Type_subtype")
                 .select().decodeList<Type_subtype>()
@@ -103,11 +105,13 @@ fun Wardrob(navHost: NavHostController) {
                 .select().decodeList<Season>()
             style = Constants.supabase.from("Style")
                 .select().decodeList<Style>()
+            users = Constants.supabase.from("Users")
+                .select().decodeList<Users>()
             wardrobs.forEach { it ->
                 Log.d("ts", it.toString())
             }
         }
-        filteredPublicThings = wardrobs
+        filteredPublicThings = cwardrobs
 
     }
     ModalDrawer(
@@ -168,7 +172,7 @@ fun Wardrob(navHost: NavHostController) {
             if (filtersApplied) {
                 Button(
                     onClick = {
-                        filteredPublicThings = wardrobs
+                        filteredPublicThings = cwardrobs
                         filtersApplied = false
                     },
                     border = BorderStroke(1.dp, Color(0xFF92A2B0)),
@@ -281,142 +285,165 @@ fun Wardrob(navHost: NavHostController) {
                 items(
                     filteredPublicThings
 
-                ) { wardrob ->
-                    val userid = wardrob.id
-                    val conidwar = cwardrob.find { it.id == userid  }
-val user =
-         if(conidwar!= null) {
-            if (conidwar.id_wardrob == wardrob.id) {
-
-
-                 val imageState = rememberAsyncImagePainter(
-                  model = ImageRequest.Builder(LocalContext.current).data(userthing.img)
-                 .size(Size.ORIGINAL).build()
-                  ).state
-
-                 Box(
-                   modifier = Modifier
-                     .shadow(8.dp, RoundedCornerShape(30.dp))
-                   ) {
-            Box(
-                modifier = Modifier
-                    .background(
-
-                        Color.White,
-
-                        shape = RoundedCornerShape(30.dp)
-                    )
-                    .padding(8.dp)
-                    .wrapContentSize(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)
-//                                    .clip(RoundedCornerShape(8.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(
-                        "Название: ${userthing.title}",
-                        fontSize = 18.sp,
-                        modifier = Modifier.padding(start = 8.dp),
-                        color = Color(0xFF92A2B0)
-                    )
-                    val seasonid = userthing.id_season
-                    val season = season.find { it.id == seasonid }
-                    val styleid = userthing.style
-                    val style = style.find { it.id == styleid }
-                    val subtypeid = userthing.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
-                            )
+                ) { 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))
+                                                ) {
+                                                    Box(
+                                                        modifier = Modifier
+                                                            .background(
+
+                                                                Color.White,
+
+                                                                shape = RoundedCornerShape(30.dp)
+                                                            )
+                                                            .padding(8.dp)
+                                                            .wrapContentSize(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
+                                                                    )
+                                                                }
+
+
+                                                            }
+
+                                                        }
+
+                                                    }
+
+                                                    Spacer(modifier = Modifier.height(16.dp))
+
+
+                                                }
+                                                Spacer(modifier = Modifier.height(20.dp))
+                                        }
+
+                                    }
+
+
+                            }
                         }
 
-
-                    }
-
-                }
-
-            }
-
-            Spacer(modifier = Modifier.height(16.dp))
-
-
-        }
-                    Spacer(modifier = Modifier.height(20.dp))
-            }
 }
                 }
             }
@@ -425,24 +452,24 @@ val user =
         }
 
     }
-    if (isFilterSheetVisible) {
-        Column {
-            Filters(
-                onApplyFilters = { selectedSubtype, selectedSeason, selectedStyle ->
-                    // Применяем фильтры и обновляем отображение
-                    filteredPublicThings = 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 })
-
-        }
-    }
+//    if (isFilterSheetVisible) {
+//        Column {
+//            Filters(
+//                onApplyFilters = { selectedSubtype, selectedSeason, selectedStyle ->
+//                    // Применяем фильтры и обновляем отображение
+//                    filteredPublicThings = 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 })
+//
+//        }
+//    }
 
 
 

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

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