CoolVery 2 днів тому
батько
коміт
ad43f3122d

+ 5 - 1
app/src/main/java/com/example/collectionofshortstories/navigation/navigation.kt → app/src/main/java/com/example/collectionofshortstories/navigation/Navigation.kt

@@ -1,12 +1,13 @@
 package com.example.collectionofshortstories.navigation
 
 import androidx.compose.runtime.Composable
-import androidx.lifecycle.ViewModel
+import androidx.compose.runtime.internal.composableLambda
 import androidx.navigation.compose.NavHost
 import androidx.navigation.compose.composable
 import androidx.navigation.compose.rememberNavController
 import com.example.collectionofshortstories.view.authorization.AuthorizationAndLogin
 import com.example.collectionofshortstories.view.catalog.Catalog
+import com.example.collectionofshortstories.view.createArticle.СreateArticle
 import com.example.collectionofshortstories.view.start.LoadProgram
 
 @Composable
@@ -25,5 +26,8 @@ fun Navigathion() {
         composable(Routes.CATALOG) {
             Catalog(navController)
         }
+        composable(Routes.CREATEARTICLE) {
+            СreateArticle(navController)
+        }
     }
 }

+ 1 - 0
app/src/main/java/com/example/collectionofshortstories/navigation/routers.kt → app/src/main/java/com/example/collectionofshortstories/navigation/Routes.kt

@@ -4,4 +4,5 @@ object Routes {
     const val START = "LoadProgram"
     const val AUTH = "AuthorizationAndLogin"
     const val CATALOG = "Catalog"
+    const val CREATEARTICLE = "СreateArticle"
 }

+ 0 - 2
app/src/main/java/com/example/collectionofshortstories/view/authorization/AuthorizationAndLogin.kt

@@ -63,9 +63,7 @@ fun AuthorizationAndLogin(navHostController: NavHostController, viewModel: Autho
         Column(
             horizontalAlignment = Alignment.CenterHorizontally,
             modifier = Modifier
-
                 .padding(0.dp, 0.dp, 0.dp, 80.dp)
-
         ) {
             Text(
                 text = "СБОРНИК РАССКАЗОВ",

+ 2 - 0
app/src/main/java/com/example/collectionofshortstories/view/authorization/AuthorizationAndLoginViewModel.kt

@@ -38,6 +38,8 @@ class AuthorizationViewModel @Inject constructor() : ViewModel() {
                 _navigationTo.value = Routes.CATALOG;
 
             } catch (e: Exception) {
+                Log.d("User", e.toString())
+                Log.d("User", e.message.toString())
                 wrongSignIn.value = true
             }
         }

+ 4 - 1
app/src/main/java/com/example/collectionofshortstories/view/catalog/Catalog.kt

@@ -30,6 +30,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.NavHostController
 import com.example.collectionofshortstories.domain.untils.Constants
 import com.example.collectionofshortstories.model.Categories
+import com.example.collectionofshortstories.navigation.Routes
 import io.github.jan.supabase.postgrest.from
 import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.withContext
@@ -68,7 +69,9 @@ fun Catalog(navHostController: NavHostController, viewModel: CatalogViewModel =
         }
         if (viewModel.showButton.value) {
             Button(
-                onClick = { /* Действия при нажатии на кнопку */ },
+                onClick = {
+                    navHostController.navigate(Routes.CREATEARTICLE)
+                },
                 modifier = Modifier
                     .align(Alignment.BottomEnd)
                     .padding(0.dp, 0.dp, 40.dp, 80.dp)

+ 168 - 0
app/src/main/java/com/example/collectionofshortstories/view/createArticle/СreateArticle.kt

@@ -0,0 +1,168 @@
+package com.example.collectionofshortstories.view.createArticle
+
+import androidx.compose.animation.expandIn
+import androidx.compose.foundation.BorderStroke
+import androidx.compose.foundation.background
+import androidx.compose.foundation.border
+import androidx.compose.foundation.layout.Arrangement
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Row
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.Divider
+import androidx.compose.material3.DropdownMenu
+import androidx.compose.material3.DropdownMenuItem
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextField
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.MutableState
+import androidx.compose.runtime.collectAsState
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.remember
+import androidx.compose.runtime.setValue
+import androidx.compose.ui.Alignment
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.graphics.Color
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import androidx.hilt.navigation.compose.hiltViewModel
+import androidx.navigation.NavHostController
+import com.example.collectionofshortstories.view.authorization.AuthorizationViewModel
+import com.example.collectionofshortstories.view.authorization.CreateTextFolder
+
+
+@Composable
+fun СreateArticle(
+    navHostController: NavHostController,
+    viewModel: СreateArticleViewModel = hiltViewModel()
+) {
+    var expanded by remember { mutableStateOf(false) }
+    var selectedItem by remember { mutableStateOf("Выберите категорию") }
+    val listCategories by viewModel.categories.collectAsState(initial = emptyList())
+
+    viewModel.GetCategories()
+
+    val title = remember { mutableStateOf("") }
+    val category = remember { mutableStateOf("") }
+    Column(
+        horizontalAlignment = Alignment.CenterHorizontally,
+        modifier = Modifier
+            .fillMaxSize()
+            .background(Color(0xFFFCE0C6))
+    ) {
+        Column(
+            horizontalAlignment = Alignment.CenterHorizontally,
+            modifier = Modifier
+                .padding(0.dp, 0.dp, 0.dp, 80.dp)
+        ) {
+            Text(
+                text = "СБОРНИК РАССКАЗОВ",
+                color = Color.Black,
+                fontSize = 30.sp,
+                fontWeight = FontWeight.Bold,
+                modifier = Modifier
+                    .padding(0.dp, 50.dp, 0.dp, 30.dp)
+            )
+            Divider(
+                modifier = Modifier.fillMaxWidth(),
+                thickness = 5.dp,
+                color = Color.Black
+            )
+        }
+        Column(
+            horizontalAlignment = Alignment.CenterHorizontally,
+        ) {
+            Text(
+                text = "Создание рассказа",
+                color = Color.Black,
+                fontSize = 30.sp
+            )
+            Row(
+                horizontalArrangement = Arrangement.spacedBy(10.dp),
+                modifier = Modifier.fillMaxWidth()
+            ) {
+                TextField(
+                    value = title.value,
+                    onValueChange = { newEmail -> title.value = newEmail },
+                    maxLines = 1,
+                    placeholder = { Text("Название") },
+                    modifier = Modifier
+                        .padding(0.dp, 30.dp, 0.dp, 0.dp)
+                        .weight(2f)
+                )
+                Column (
+                ) {
+                    Button(
+                        onClick = { expanded = !expanded }
+                    ) {
+                        Text(text = selectedItem)
+                    }
+                    DropdownMenu(
+                        expanded = expanded,
+                        onDismissRequest = { expanded = false },
+
+                        ) {
+                        for (categories in listCategories) {
+                            DropdownMenuItem(onClick = {
+                                selectedItem = categories.title
+                                expanded = false
+                            },
+                                text = { Text(categories.title) }
+                            )
+                        }
+                    }
+                }
+            }
+            Button(
+                onClick = {
+
+                    },
+                    colors = ButtonDefaults.buttonColors(
+                        containerColor = Color(0xFFFCE0C6)
+                    ),
+                    modifier = Modifier
+                        .fillMaxWidth()
+                        .padding(40.dp, 20.dp)
+                        .border(BorderStroke(2.dp, Color.Black), shape = RoundedCornerShape(25.dp))
+
+                ) {
+                    Text(
+                        text = "Сохранить рассказ",
+                        color = Color.Black
+                    )
+                }
+
+        }
+    }
+}
+
+    @Composable
+    fun CreateTextFolder(
+        titleState: MutableState<String>,
+        categoryState: MutableState<String>
+    ) {
+        TextField(
+            value = titleState.value,
+            onValueChange = { newEmail -> titleState.value = newEmail },
+            maxLines = 1,
+            placeholder = { Text("Название") },
+            modifier = Modifier
+                .padding(0.dp, 30.dp, 0.dp, 0.dp)
+
+        )
+        TextField(
+            value = categoryState.value,
+            onValueChange = { newPass -> categoryState.value = newPass },
+            maxLines = 1,
+            placeholder = { Text("Категория рассказа") },
+            modifier = Modifier
+                .padding(0.dp, 30.dp, 0.dp, 0.dp)
+        )
+    }

+ 35 - 0
app/src/main/java/com/example/collectionofshortstories/view/createArticle/СreateArticleViewModel.kt

@@ -0,0 +1,35 @@
+package com.example.collectionofshortstories.view.createArticle
+
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.tooling.preview.Preview
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.example.collectionofshortstories.domain.untils.Constants
+import com.example.collectionofshortstories.model.Article
+import com.example.collectionofshortstories.model.Categories
+import dagger.hilt.android.lifecycle.HiltViewModel
+import io.github.jan.supabase.postgrest.from
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.flow.MutableStateFlow
+import kotlinx.coroutines.flow.StateFlow
+import kotlinx.coroutines.flow.asStateFlow
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import javax.inject.Inject
+
+@HiltViewModel
+class СreateArticleViewModel @Inject constructor() : ViewModel() {
+    private val _categories: MutableStateFlow<List<Categories>> = MutableStateFlow( listOf() )
+    val categories: StateFlow<List<Categories>> = _categories.asStateFlow()
+
+    fun GetCategories() {
+        viewModelScope.launch {
+            withContext(Dispatchers.IO) {
+                val updatedCategories = Constants.supabase.from("categories")
+                    .select()
+                _categories.value = updatedCategories.decodeList<Categories>()
+            }
+        }
+    }
+
+}