|
@@ -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)
|
|
|
|
+ )
|
|
|
|
+ }
|