sedypana hace 3 días
padre
commit
045365ac6d

+ 1 - 1
.idea/compiler.xml

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="CompilerConfiguration">
-    <bytecodeTargetLevel target="21" />
+    <bytecodeTargetLevel target="17" />
   </component>
 </project>

+ 0 - 1
.idea/gradle.xml

@@ -4,7 +4,6 @@
   <component name="GradleSettings">
     <option name="linkedExternalProjectsSettings">
       <GradleProjectSettings>
-        <option name="testRunner" value="CHOOSE_PER_TEST" />
         <option name="externalProjectPath" value="$PROJECT_DIR$" />
         <option name="gradleJvm" value="#GRADLE_LOCAL_JAVA_HOME" />
         <option name="modules">

+ 2 - 1
.idea/misc.xml

@@ -1,6 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
 <project version="4">
   <component name="ExternalStorageConfigurationManager" enabled="true" />
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_21" default="true" project-jdk-name="jbr-21" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="jbr-17" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">

+ 49 - 0
app/src/main/java/com/example/osnov_android/MainActivityViewModel.kt

@@ -6,15 +6,19 @@ import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
 import androidx.compose.runtime.setValue
 import androidx.lifecycle.ViewModel
+import androidx.lifecycle.ViewModelProvider.Factory.Companion.from
 import androidx.lifecycle.viewModelScope
 import com.example.osnov_android.components.Constants
 import com.example.osnov_android.models.Dishes
+import com.example.osnov_android.models.DishesBlog
 import com.example.osnov_android.models.UserState
 import com.example.osnov_android.models.Users
 import io.github.jan.supabase.auth.auth
 import io.github.jan.supabase.auth.providers.builtin.Email
 import io.github.jan.supabase.postgrest.from
+import io.github.jan.supabase.postgrest.query.Columns
 import kotlinx.coroutines.launch
+import java.util.jar.Attributes.Name
 
 
 class MainActivityViewModel : ViewModel() {
@@ -29,6 +33,11 @@ class MainActivityViewModel : ViewModel() {
     val dish by mutableStateOf<Dishes?>(null)
     private val _user = mutableStateOf(listOf<Users>())
     val user: State<List<Users>> = _user
+    private val _cookingsblog = mutableStateOf(listOf<DishesBlog>())
+    val cookingsblog: State<List<DishesBlog>> = _cookingsblog
+    private var _iduserblog = mutableStateOf(listOf<DishesBlog>())
+    val iduserblog: State<List<DishesBlog>> = _iduserblog
+    val name = mutableStateOf("")
 
     fun SignIn(emailUser: String, userPassword: String) {
         viewModelScope.launch {
@@ -103,7 +112,29 @@ class MainActivityViewModel : ViewModel() {
     fun DishesBlogUser()
     {
         viewModelScope.launch {
+            try {
+                _userState.value = UserState.Loading
+
+                _iduserblog.value = Constants.supabase.from("DishesBLog").select(columns = Columns.list("id_user")) {
+                    filter {
+                        eq("Name" , cookingsblog.value.last().Name)
+                    }
+                }.decodeSingleOrNull()!!
+
+                name.value = Constants.supabase.from("Users").select()
+                {
+                    filter {
+
+                    }
+
+                }.decodeSingleOrNull()!!
 
+
+        }
+        catch (e: Exception)
+        {
+            _userState.value = UserState.Error(e.message!!)
+        }
         }
     }
 
@@ -125,6 +156,24 @@ class MainActivityViewModel : ViewModel() {
         }
     }
 
+    fun allDishesBlog()
+    {
+        viewModelScope.launch {
+            try {
+                _userState.value = UserState.Loading
+                _cookingsblog.value = Constants.supabase.from("DishesBlog").select().decodeList<DishesBlog>()
+                Log.d("blog_tag","Ехала еда блог")
+                _userState.value = UserState.Success("Блог успешно выбран")
+                Log.d("blog_tag", "данные с блога suc!")
+            }
+            catch (e: Exception)
+            {
+                _userState.value = UserState.Error(e.message!!)
+            }
+
+        }
+    }
+
     fun UsersProfile()
     {
         viewModelScope.launch {

+ 1 - 0
app/src/main/java/com/example/osnov_android/models/DishesBlog.kt

@@ -9,4 +9,5 @@ data class DishesBlog(
     val Name:String = "",
     val Image:String = "",
     val id_user:Int = 0,
+    val Description:String = ""
 )

+ 137 - 4
app/src/main/java/com/example/osnov_android/views/Blog.kt

@@ -1,17 +1,150 @@
 package com.example.osnov_android.views
 
-import android.annotation.SuppressLint
+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.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.lazy.LazyColumn
+import androidx.compose.foundation.lazy.items
+import androidx.compose.material3.Card
+import androidx.compose.material3.CircularProgressIndicator
+import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.layout.ContentScale
+import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import coil.compose.AsyncImagePainter
+import coil.compose.rememberAsyncImagePainter
+import coil.request.ImageRequest
 import com.example.osnov_android.MainActivityViewModel
 
-@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
 @Composable
-fun Blog(viewModel: MainActivityViewModel) {
-    Column(Modifier.fillMaxSize().background(Color.Black)) {
+fun Blog(viewModel: MainActivityViewModel, ) {
+    val background = Color(0xFF1B1A20)
+    Column(
+        Modifier
+            .fillMaxSize()
+            .background(background)) {
+        val flag = remember { mutableStateOf(true) }
+        val cookingsblog by viewModel.cookingsblog
+        val user by viewModel.user
+
+        if (flag.value) {
+            viewModel.allDishesBlog()
+            viewModel.DishesBlogUser()
+            flag.value = false
+        }
+
+        Column(
+            modifier = Modifier
+                .fillMaxSize()
+                .background(background)
+                .padding(top = 50.dp),
+            horizontalAlignment = Alignment.CenterHorizontally
+        ) {
+            Text(
+                text = "БЛОГ",
+                fontWeight = FontWeight.Light,
+                fontSize = 24.sp,
+                color = Color(0xFFFFFFFF),
+                letterSpacing = 10.sp
+            )
+
+            if (cookingsblog.isNotEmpty()) {
+                LazyColumn {
+                    items(cookingsblog) { cookingblog ->
+                        val image = rememberAsyncImagePainter(
+                            model = ImageRequest.Builder(LocalContext.current)
+                                .data(cookingblog.Image)
+                                .size(200, 200).build()
+                        ).state
+                        Card(
+                            modifier = Modifier
+                                .fillMaxWidth()
+                                .padding(20.dp)
+
+
+                        ) {
+                            Column(
+                                Modifier.fillMaxSize(),
+                                verticalArrangement = Arrangement.Center,
+                                horizontalAlignment = Alignment.CenterHorizontally
+                            ) {
+
+
+
+                                if (image is AsyncImagePainter.State.Success) {
+                                    Box(
+                                        modifier = Modifier
+                                            .height(200.dp)
+                                            .padding(10.dp),
+                                        contentAlignment = Alignment.Center
+                                    ) {
+                                        Image(
+                                            modifier = Modifier
+                                                .fillMaxWidth()
+                                                .height(200.dp),
+                                            painter = image.painter,
+                                            contentDescription = "",
+                                            contentScale = ContentScale.Crop,
+                                            alignment = Alignment.Center
+                                        )
+                                    }
+                                }
+                                if (image is AsyncImagePainter.State.Loading) {
+                                    Box(
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .height(250.dp),
+                                        contentAlignment = Alignment.Center
+                                    ) {
+                                        CircularProgressIndicator()
+                                    }
+                                }
+                            }
+                            Column(
+                                Modifier
+                                    .fillMaxSize()
+                                    .padding(12.dp),
+                                horizontalAlignment = Alignment.Start
+                            ) {
+
+                                Text(
+                                    text = cookingblog.Name,
+                                    fontWeight = FontWeight.Medium,
+                                    fontSize = 20.sp,
+                                    color = Color.Black,
+                                    modifier = Modifier.padding(5.dp)
+                                )
+                                Text(
+                                    text = cookingblog.Description,
+                                    fontWeight = FontWeight.Light,
+                                    fontSize = 14.sp,
+                                    color = Color.Black,
+                                    modifier = Modifier.padding(5.dp)
+                                )
+                            }
+                        }
+                    }
+                }
+            } else {
+                Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
+                    CircularProgressIndicator()
+                }
+            }
+        }
     }
 }

+ 79 - 63
app/src/main/java/com/example/osnov_android/views/Cooking.kt

@@ -49,80 +49,96 @@ fun Cookings(viewModel: MainActivityViewModel, navController: NavController) {
             flag.value = false
         }
 
-        if (cookings.isNotEmpty()) {
-            LazyColumn {
-                items(cookings) { cooking ->
-                    val image = rememberAsyncImagePainter(
-                        model = ImageRequest.Builder(LocalContext.current).data(cooking.Image)
-                            .size(200, 200).build()
-                    ).state
-                    Card(
-                        modifier = Modifier
-                            .fillMaxWidth()
-                            .padding(20.dp)
+        Column(
+            modifier = Modifier
+                .fillMaxSize()
+                .background(background)
+                .padding(top = 50.dp),
+            horizontalAlignment = Alignment.CenterHorizontally
+        ) {
+            Text(
+                text = "ПРОФИЛЬ",
+                fontWeight = FontWeight.Light,
+                fontSize = 24.sp,
+                color = Color(0xFFFFFFFF),
+                letterSpacing = 10.sp
+            )
+
+            if (cookings.isNotEmpty()) {
+                LazyColumn {
+                    items(cookings) { cooking ->
+                        val image = rememberAsyncImagePainter(
+                            model = ImageRequest.Builder(LocalContext.current).data(cooking.Image)
+                                .size(200, 200).build()
+                        ).state
+                        Card(
+                            modifier = Modifier
+                                .fillMaxWidth()
+                                .padding(20.dp)
 
 
-                    ) {
-                        Column(
-                            Modifier.fillMaxSize(),
-                            verticalArrangement = Arrangement.Center,
-                            horizontalAlignment = Alignment.CenterHorizontally
                         ) {
-                            if (image is AsyncImagePainter.State.Success) {
-                                Box(
-                                    modifier = Modifier
-                                        .height(200.dp)
-                                        .padding(10.dp),
-                                    contentAlignment = Alignment.Center
-                                ) {
-                                    Image(
+                            Column(
+                                Modifier.fillMaxSize(),
+                                verticalArrangement = Arrangement.Center,
+                                horizontalAlignment = Alignment.CenterHorizontally
+                            ) {
+                                if (image is AsyncImagePainter.State.Success) {
+                                    Box(
                                         modifier = Modifier
-                                            .fillMaxWidth()
-                                            .height(200.dp),
-                                        painter = image.painter,
-                                        contentDescription = "",
-                                        contentScale = ContentScale.Crop,
-                                        alignment = Alignment.Center
-                                    )
+                                            .height(200.dp)
+                                            .padding(10.dp),
+                                        contentAlignment = Alignment.Center
+                                    ) {
+                                        Image(
+                                            modifier = Modifier
+                                                .fillMaxWidth()
+                                                .height(200.dp),
+                                            painter = image.painter,
+                                            contentDescription = "",
+                                            contentScale = ContentScale.Crop,
+                                            alignment = Alignment.Center
+                                        )
+                                    }
                                 }
-                            }
-                            if (image is AsyncImagePainter.State.Loading) {
-                                Box(
-                                    modifier = Modifier
-                                        .fillMaxWidth()
-                                        .height(250.dp),
-                                    contentAlignment = Alignment.Center
-                                ) {
-                                    CircularProgressIndicator()
+                                if (image is AsyncImagePainter.State.Loading) {
+                                    Box(
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .height(250.dp),
+                                        contentAlignment = Alignment.Center
+                                    ) {
+                                        CircularProgressIndicator()
+                                    }
                                 }
                             }
-                        }
-                        Column(
-                            Modifier.fillMaxSize().padding(12.dp),
-                            horizontalAlignment = Alignment.Start
-                        ) {
+                            Column(
+                                Modifier.fillMaxSize().padding(12.dp),
+                                horizontalAlignment = Alignment.Start
+                            ) {
 
-                            Text(
-                                text = cooking.Name,
-                                fontWeight = FontWeight.Medium,
-                                fontSize = 20.sp,
-                                color = Color.Black,
-                                modifier = Modifier.padding(5.dp)
-                            )
-                            Text(
-                                text = cooking.Descriptions,
-                                fontWeight = FontWeight.Light,
-                                fontSize = 14.sp,
-                                color = Color.Black,
-                                modifier = Modifier.padding(5.dp)
-                            )
+                                Text(
+                                    text = cooking.Name,
+                                    fontWeight = FontWeight.Medium,
+                                    fontSize = 20.sp,
+                                    color = Color.Black,
+                                    modifier = Modifier.padding(5.dp)
+                                )
+                                Text(
+                                    text = cooking.Descriptions,
+                                    fontWeight = FontWeight.Light,
+                                    fontSize = 14.sp,
+                                    color = Color.Black,
+                                    modifier = Modifier.padding(5.dp)
+                                )
+                            }
                         }
                     }
                 }
-            }
-        } else {
-            Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
-                CircularProgressIndicator()
+            } else {
+                Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
+                    CircularProgressIndicator()
+                }
             }
         }
     }

+ 114 - 95
app/src/main/java/com/example/osnov_android/views/CookingAdmin.kt

@@ -47,117 +47,136 @@ fun CookingAdmin(viewModel: MainActivityViewModel, navController: NavController)
             viewModel.allDishes()
             flag.value = false
         }
-        if (cookings.isNotEmpty()) {
-            LazyColumn {
-                items(cookings) { cooking ->
-                    val image = rememberAsyncImagePainter(
-                        model = ImageRequest.Builder(LocalContext.current).data(cooking.Image)
-                            .size(200, 200).build()
-                    ).state
-                    Card(
-                        modifier = Modifier
-                            .fillMaxWidth()
-                            .padding(20.dp)
+
+        Column(
+            modifier = Modifier
+                .fillMaxSize()
+                .background(background)
+                .padding(top = 50.dp),
+            horizontalAlignment = Alignment.CenterHorizontally
+        ) {
+            Text(
+                text = "ПРОФИЛЬ",
+                fontWeight = FontWeight.Light,
+                fontSize = 24.sp,
+                color = Color(0xFFFFFFFF),
+                letterSpacing = 10.sp
+            )
+
+            if (cookings.isNotEmpty()) {
+                LazyColumn {
+                    items(cookings) { cooking ->
+                        val image = rememberAsyncImagePainter(
+                            model = ImageRequest.Builder(LocalContext.current).data(cooking.Image)
+                                .size(200, 200).build()
+                        ).state
+                        Card(
+                            modifier = Modifier
+                                .fillMaxWidth()
+                                .padding(20.dp)
 
 
-                    ) {
-                        Column(
-                            Modifier.fillMaxSize(),
-                            verticalArrangement = Arrangement.Center,
-                            horizontalAlignment = Alignment.CenterHorizontally
                         ) {
-                            if (image is AsyncImagePainter.State.Success) {
-                                Box(
-                                    modifier = Modifier
-                                        .height(200.dp)
-                                        .padding(10.dp),
-                                    contentAlignment = Alignment.Center
-                                ) {
-                                    Image(
+                            Column(
+                                Modifier.fillMaxSize(),
+                                verticalArrangement = Arrangement.Center,
+                                horizontalAlignment = Alignment.CenterHorizontally
+                            ) {
+                                if (image is AsyncImagePainter.State.Success) {
+                                    Box(
                                         modifier = Modifier
-                                            .fillMaxWidth()
-                                            .height(200.dp),
-                                        painter = image.painter,
-                                        contentDescription = "",
-                                        contentScale = ContentScale.Crop,
-                                        alignment = Alignment.Center
-                                    )
+                                            .height(200.dp)
+                                            .padding(10.dp),
+                                        contentAlignment = Alignment.Center
+                                    ) {
+                                        Image(
+                                            modifier = Modifier
+                                                .fillMaxWidth()
+                                                .height(200.dp),
+                                            painter = image.painter,
+                                            contentDescription = "",
+                                            contentScale = ContentScale.Crop,
+                                            alignment = Alignment.Center
+                                        )
+                                    }
                                 }
-                            }
-                            if (image is AsyncImagePainter.State.Loading) {
-                                Box(
-                                    modifier = Modifier
-                                        .fillMaxWidth()
-                                        .height(250.dp),
-                                    contentAlignment = Alignment.Center
-                                ) {
-                                    CircularProgressIndicator()
+                                if (image is AsyncImagePainter.State.Loading) {
+                                    Box(
+                                        modifier = Modifier
+                                            .fillMaxWidth()
+                                            .height(250.dp),
+                                        contentAlignment = Alignment.Center
+                                    ) {
+                                        CircularProgressIndicator()
+                                    }
                                 }
                             }
-                        }
-                        Column(
-                            Modifier.fillMaxSize().padding(12.dp),
-                            horizontalAlignment = Alignment.Start
-                        ) {
+                            Column(
+                                Modifier.fillMaxSize().padding(12.dp),
+                                horizontalAlignment = Alignment.Start
+                            ) {
 
-                            Text(
-                                text = cooking.Name,
-                                fontWeight = FontWeight.Medium,
-                                fontSize = 20.sp,
-                                color = Color.Black,
-                                modifier = Modifier.padding(5.dp)
-                            )
-                            Text(
-                                text = cooking.Descriptions,
-                                fontWeight = FontWeight.Light,
-                                fontSize = 14.sp,
-                                color = Color.Black,
-                                modifier = Modifier.padding(5.dp)
-                            )
+                                Text(
+                                    text = cooking.Name,
+                                    fontWeight = FontWeight.Medium,
+                                    fontSize = 20.sp,
+                                    color = Color.Black,
+                                    modifier = Modifier.padding(5.dp)
+                                )
+                                Text(
+                                    text = cooking.Descriptions,
+                                    fontWeight = FontWeight.Light,
+                                    fontSize = 14.sp,
+                                    color = Color.Black,
+                                    modifier = Modifier.padding(5.dp)
+                                )
 
-                            Column(Modifier, horizontalAlignment = Alignment.CenterHorizontally) {
-                                Button(
-                                    onClick = { viewModel.deleteCooking(cooking.id!!) },
-                                    modifier = Modifier
-                                        .fillMaxWidth(0.5f)
-                                        .padding(5.dp),
-                                    shape = RoundedCornerShape(20),
-                                    colors = ButtonColors(
-                                        contentColor = Color.White,
-                                        containerColor = Color(0xFF7DAD01),
-                                        disabledContentColor = Color.White,
-                                        disabledContainerColor = Color(0xFF7DAD01)
-                                    )
+                                Column(
+                                    Modifier,
+                                    horizontalAlignment = Alignment.CenterHorizontally
                                 ) {
-                                    Text("Удалить")
-                                }
-                                Button(
-                                    onClick = {
-                                        viewModel.giveCooking(cooking)
-                                        navController.navigate(Screen.CookingUpdate.route)
-                                    }, modifier = Modifier
-                                        .fillMaxWidth(0.5f)
-                                        .padding(5.dp),
-                                    shape = RoundedCornerShape(20),
-                                    colors = ButtonColors(
-                                        contentColor = Color.White,
-                                        containerColor = Color(0xFF7DAD01),
-                                        disabledContentColor = Color.White,
-                                        disabledContainerColor = Color(0xFF7DAD01)
-                                    )
-                                ) {
-                                    Text("Изменить")
+                                    Button(
+                                        onClick = { viewModel.deleteCooking(cooking.id!!) },
+                                        modifier = Modifier
+                                            .fillMaxWidth(0.5f)
+                                            .padding(5.dp),
+                                        shape = RoundedCornerShape(20),
+                                        colors = ButtonColors(
+                                            contentColor = Color.White,
+                                            containerColor = Color(0xFF7DAD01),
+                                            disabledContentColor = Color.White,
+                                            disabledContainerColor = Color(0xFF7DAD01)
+                                        )
+                                    ) {
+                                        Text("Удалить")
+                                    }
+                                    Button(
+                                        onClick = {
+                                            viewModel.giveCooking(cooking)
+                                            navController.navigate(Screen.CookingUpdate.route)
+                                        }, modifier = Modifier
+                                            .fillMaxWidth(0.5f)
+                                            .padding(5.dp),
+                                        shape = RoundedCornerShape(20),
+                                        colors = ButtonColors(
+                                            contentColor = Color.White,
+                                            containerColor = Color(0xFF7DAD01),
+                                            disabledContentColor = Color.White,
+                                            disabledContainerColor = Color(0xFF7DAD01)
+                                        )
+                                    ) {
+                                        Text("Изменить")
+                                    }
                                 }
                             }
                         }
                     }
                 }
-                    }
+            } else {
+                Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
+                    CircularProgressIndicator()
                 }
-        else {
-            Box(Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
-                CircularProgressIndicator()
             }
         }
     }
-}
+}