Pārlūkot izejas kodu

Подходящие рецепты, рецепты

Anastasia 4 dienas atpakaļ
vecāks
revīzija
60937bd83f

+ 4 - 0
EatWell/app/src/main/java/com/example/eatwell/Resources.kt

@@ -5,6 +5,7 @@ import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.setValue
 import com.example.eatwell.model.Category
 import com.example.eatwell.model.Diets
+import com.example.eatwell.model.Dish
 import com.example.eatwell.model.Fridge
 import com.example.eatwell.model.Ingredients
 import com.example.eatwell.model.Recipes
@@ -21,6 +22,9 @@ class Resources {
         var ingredients: MutableList<Ingredients> by mutableStateOf(mutableListOf())
         var chosenIngredients: MutableList<Ingredients> by mutableStateOf(mutableListOf())
         var fridge: MutableList<Fridge> by mutableStateOf(mutableListOf())
+        var myRecipes: MutableList<Recipes> by mutableStateOf(mutableListOf())
+        var dishes: MutableList<Dish> by mutableStateOf(mutableListOf())
+        lateinit var recept: Recipes;
         // Состояние для выбранных рецептов
     }
 }

+ 1 - 0
EatWell/app/src/main/java/com/example/eatwell/model/Dish.kt

@@ -8,4 +8,5 @@ data class Dish(
     val id: Int,
     val recipes: Int,
     val fridge: Int,
+    val user_id: String
 )

+ 16 - 1
EatWell/app/src/main/java/com/example/eatwell/view/MainViewModel.kt

@@ -7,6 +7,7 @@ import com.example.eatwell.Resources
 import com.example.eatwell.domain.Constant
 import com.example.eatwell.model.Category
 import com.example.eatwell.model.Diets
+import com.example.eatwell.model.Dish
 import com.example.eatwell.model.Fridge
 import com.example.eatwell.model.Ingredients
 import com.example.eatwell.model.Recipes
@@ -19,7 +20,6 @@ import java.util.UUID
 
 class MainViewModel():ViewModel() {
 
-
     fun onSignInEmailPassword(emailUser: String, passwordUser: String) {
         viewModelScope.launch {
             try {
@@ -97,6 +97,21 @@ class MainViewModel():ViewModel() {
         }
     }
 
+    fun getDishes(){
+
+        viewModelScope.launch {
+            try {
+                Resources.dishes = Constant.supabase.from("Dish").select{
+                    "*"
+                }.decodeList<Dish>() as ArrayList<Dish>
+
+                Log.d("Блюда: ",  Resources.dishes.toString())
+            } catch (e: Exception) {
+                Log.e("Ошибка б: ", e.message.toString())
+            }
+        }
+    }
+
     fun deleteIngredient(ingredientId: Int) {
 
         viewModelScope.launch {

+ 9 - 3
EatWell/app/src/main/java/com/example/eatwell/view/mainActivity/Dish.kt

@@ -1,5 +1,6 @@
 package com.example.eatwell.view.mainActivity
 
+import android.util.Log
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Box
@@ -65,12 +66,17 @@ import io.github.jan.supabase.gotrue.auth
 @Composable
 fun dish(navController: NavController) {
     var list = remember { mutableStateListOf<Recipes>() }
-    if(!flag) {
+    for (j in 0..Resources.dishes.size-1) {
         for (i in 0..Resources.recipes.size - 1) {
-            list.add(Resources.recipes.get(i))
+            if(Resources.dishes.get(j).recipes == Resources.recipes.get(i).id &&
+                Resources.dishes.get(j).user_id == Constant.supabase.auth.currentUserOrNull()!!.id) {
+
+                list.add(Resources.recipes.get(i))
+            }
         }
-        flag = true
     }
+
+    Log.d("Рецепты: ", list.toString())
     Box(
         modifier = Modifier
             .fillMaxSize()

+ 3 - 1
EatWell/app/src/main/java/com/example/eatwell/view/mainActivity/Home.kt

@@ -281,7 +281,9 @@ fun home(navController: NavController) {
                                     modifier = Modifier
                                         .fillMaxWidth()
                                         .padding(top = 7.5.dp)
-                                        .clickable { navController.navigate("recept") },
+                                        .clickable {
+                                            Resources.recept = list.get(itemId)
+                                            navController.navigate("recept") },
                                     text = list.get(itemId).name,
                                     color = Color.Black,
                                     fontSize = 20.sp,

+ 7 - 6
EatWell/app/src/main/java/com/example/eatwell/view/mainActivity/MainActivity.kt

@@ -38,11 +38,12 @@ class MainActivity : ComponentActivity() {
 //        viewModel.getDiets()
 //        viewModel.getCategory()
 //        viewModel.getIngredients()
-        Resources.viewModel.getDiets()
-        Resources.viewModel.getCategory()
-        Resources.viewModel.getRecipes()
-        Resources.viewModel.getIngredients()
-        Log.d("Диеты: ", Resources.diets.toString())
+       Resources.viewModel.getDiets()
+       Resources.viewModel.getCategory()
+       Resources.viewModel.getRecipes()
+       Resources.viewModel.getIngredients()
+       Resources.viewModel.getDishes()
+       Log.d("Диеты: ", Resources.diets.toString())
 
         setContent {
             EatWellTheme {
@@ -67,7 +68,7 @@ class MainActivity : ComponentActivity() {
                 composable("myplan") {
                     myplan(navController)    }
                 composable("recept") {
-                    recept(navController)
+                    recept(navController, Resources.recept)
                 }
                 composable("ingredients") {
                     ingredients(navController)    }

+ 3 - 7
EatWell/app/src/main/java/com/example/eatwell/view/mainActivity/Recept.kt

@@ -62,14 +62,10 @@ import io.github.jan.supabase.gotrue.auth
 @OptIn(ExperimentalMaterial3Api::class)
 //@Preview
 @Composable
-fun recept(navController: NavController) {
+fun recept(navController: NavController, recept: Recipes) {
     var list = remember { mutableStateListOf<Recipes>() }
-    if(!flag) {
-        for (i in 0..Resources.recipes.size - 1) {
-            list.add(Resources.recipes.get(i))
-        }
-        flag = true
-    }
+
+    list.add(recept)
     Box(
         modifier = Modifier
             .fillMaxSize()