Bladeren bron

Доделать DropdownMenuItem на экране ProfileScreen

k1rakato 3 dagen geleden
bovenliggende
commit
d9d94b5d34

+ 12 - 7
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/Screens/AuthorizationScreen.kt

@@ -117,7 +117,7 @@ fun Authorization(
                 Column(
                     modifier = Modifier
                         .fillMaxSize()
-                        .padding(vertical = 120.dp)
+                        .padding(vertical = 90.dp)
                         .pointerInput(Unit) {
                             keyboardController?.hide()
                             focusManager.clearFocus()
@@ -133,7 +133,7 @@ fun Authorization(
                         fontSize = 40.sp
                     )
 
-                    Spacer(modifier = Modifier.height(150.dp))
+                    Spacer(modifier = Modifier.height(30.dp))
 
                     Row(
                         modifier = Modifier.fillMaxWidth(),
@@ -150,7 +150,9 @@ fun Authorization(
                     }
 
                     TextField(
-                        modifier = Modifier.width(320.dp),
+                        modifier = Modifier
+                            .width(320.dp)
+                            .padding(top = 30.dp),
                         maxLines = 1,
                         singleLine = true,
                         shape = RoundedCornerShape(20.dp),
@@ -162,7 +164,9 @@ fun Authorization(
                     )
 
                     TextField(
-                        modifier = Modifier.width(320.dp),
+                        modifier = Modifier
+                            .width(320.dp)
+                            .padding(bottom = 110.dp),
                         maxLines = 1,
                         singleLine = true,
                         shape = RoundedCornerShape(20.dp),
@@ -173,12 +177,13 @@ fun Authorization(
                         onValueChange = { userPassword = it }
                     )
 
-                    Spacer(modifier = Modifier.height(15.dp))
 
                     Button(
                         onClick =
-                        { viewModel.singIn(context,userEmail,userPassword)
-                        navController.navigate(Screens.ProfileScreen.route)},
+                        {
+                            viewModel.singIn(context, userEmail, userPassword)
+                            f.value = true
+                        },
                         modifier = Modifier
                             .width(278.dp)
                             .height(45.dp),

+ 176 - 78
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/Screens/ProfileScreen.kt

@@ -2,6 +2,7 @@ package com.example.tomatoandpotatoapp.Screens
 
 import android.widget.ImageButton
 import androidx.compose.foundation.background
+import androidx.compose.foundation.clickable
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Box
 import androidx.compose.foundation.layout.Column
@@ -14,36 +15,50 @@ import androidx.compose.foundation.layout.size
 import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.shape.RoundedCornerShape
 import androidx.compose.material.icons.Icons
+import androidx.compose.material.icons.filled.KeyboardArrowDown
+import androidx.compose.material.icons.filled.KeyboardArrowUp
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.DropdownMenu
+import androidx.compose.material3.DropdownMenuItem
 import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButton
+import androidx.compose.material3.OutlinedTextField
 import androidx.compose.material3.Text
+import androidx.compose.material3.TextFieldColors
+import androidx.compose.material3.TextFieldDefaults
 import androidx.compose.runtime.Composable
 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.geometry.Size
 import androidx.compose.ui.graphics.Brush
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.graphics.ImageBitmap
+import androidx.compose.ui.layout.onGloballyPositioned
 import androidx.compose.ui.platform.LocalContext
+import androidx.compose.ui.platform.LocalDensity
 import androidx.compose.ui.res.imageResource
 import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.text.style.TextAlign
 import androidx.compose.ui.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
+import androidx.compose.ui.unit.toSize
 import com.example.tomatoandpotatoapp.ViewModelsPack.SupabaseAuthViewModel
 import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.NavController
 import com.example.tomatoandpotatoapp.R
 import com.example.tomatoandpotatoapp.utils.EditProfileString
 
+
 @Preview
 @Composable
 fun MyProfile(
-    //viewModel: SupabaseAuthViewModel = viewModel(),
+    viewModel: SupabaseAuthViewModel = viewModel(),
     //navController: NavController
 ) {
 //    val userState by viewModel.userState
@@ -67,6 +82,15 @@ fun MyProfile(
 //        val birthDate = remember {
 //            mutableStateOf(people.last().birthDate)
 //        }
+    var mSelectedText by remember { mutableStateOf("") }
+    var expanded by remember { mutableStateOf(false) }
+    var mTextFieldSize by remember { mutableStateOf(Size.Zero) }
+    val genders = listOf("Мужской", "Женский")
+
+    val icon = if (expanded)
+        Icons.Filled.KeyboardArrowUp
+    else
+        Icons.Filled.KeyboardArrowDown
 
     Box(modifier = Modifier.fillMaxSize()) {
         Box(
@@ -113,102 +137,176 @@ fun MyProfile(
                 EditProfileString(search = "", onValueChange = {}, enabled = true)
             }
 
-
             Spacer(modifier = Modifier.height(30.dp))
 
             Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
 
-                EditProfileString(search = "", onValueChange = {}, enabled = true)
-            }
-
-
-            Spacer(modifier = Modifier.height(110.dp))
-
-            Row(
-                modifier = Modifier.fillMaxWidth(),
-                horizontalArrangement = Arrangement.Center,
-                verticalAlignment = Alignment.CenterVertically
-            ) {
-                Button(
-                    onClick = { },
+                OutlinedTextField(
+                    value = mSelectedText,
+                    onValueChange = { mSelectedText = it },
                     modifier = Modifier
-                        .width(278.dp)
-                        .height(45.dp),
+                        .height(50.dp)
+                        .width(316.dp)
+                        .onGloballyPositioned { coordinates ->
+                            mTextFieldSize = coordinates.size.toSize()
+                        },
                     shape = RoundedCornerShape(20),
-                    colors = ButtonDefaults.buttonColors(containerColor = Color(0xff78EE99))
+                    colors = TextFieldDefaults.colors(
+                        focusedContainerColor = Color(0xFFF2D6FA),
+                        focusedIndicatorColor = Color(0xFF4C2259),
+                        focusedTextColor = Color.Black,
+                        disabledIndicatorColor = Color.Transparent,
+                        unfocusedIndicatorColor = Color.Transparent,
+                        cursorColor = Color.Black,
+                        focusedSupportingTextColor = Color.Black
+                    ),
+                    label = {
+                        Text(
+                            "Пол",
+                            fontWeight = FontWeight.W600,
+                            color = Color.Black
+                        )
+                    },
+                    trailingIcon = {
+                        Icon(icon, "contentDescription",
+                            Modifier.clickable { expanded = !expanded })
+                    }
                 )
-                {
-                    Text(
-                        text = "Сохранить",
-                        fontSize = 20.sp,
-                        fontWeight = FontWeight.W700,
-                        color = Color.White
-                    )
+                DropdownMenu(
+                    expanded = expanded,
+                    onDismissRequest = { expanded = false },
+                    modifier = Modifier
+                        .width(with(LocalDensity.current) { mTextFieldSize.width.toDp() })
+                ) {
+                    genders.forEach { label ->
+                        DropdownMenuItem(onClick = {
+                            mSelectedText = label
+                            expanded = false
+                        }) {
+                            Text(text = label)
+                        }
+                    }
                 }
-            }
 
-            Spacer(modifier = Modifier.height(25.dp))
+                Spacer(modifier = Modifier.height(30.dp))
 
-            Row(
-                modifier = Modifier.fillMaxWidth(),
-                horizontalArrangement = Arrangement.Center,
-                verticalAlignment = Alignment.CenterVertically
-            ) {
-                Button(
-                    onClick = { },
-                    modifier = Modifier
-                        .width(278.dp)
-                        .height(45.dp),
-                    shape = RoundedCornerShape(20),
-                    colors = ButtonDefaults.buttonColors(containerColor = Color(0xffFC5050))
-                )
-                {
-                    Text(
-                        text = "Выход",
-                        fontSize = 20.sp,
-                        fontWeight = FontWeight.W700,
-                        color = Color.White
-                    )
+                Row(
+                    modifier = Modifier.fillMaxWidth(),
+                    horizontalArrangement = Arrangement.Center
+                ) {
+                    Button(
+                        onClick = {},
+                        modifier = Modifier
+                            .height(50.dp)
+                            .width(316.dp),
+                        shape = RoundedCornerShape(20),
+                        colors = ButtonDefaults
+                            .buttonColors(containerColor = Color(0xFFF5F5F9))
+                    ) {
+                        Text(
+                            text = "Мои растения",
+                            fontWeight = FontWeight.W800,
+                            color = Color.Black,
+                            fontSize = 22.sp
+                        )
+
+                    }
                 }
-            }
 
-            Spacer(modifier = Modifier.weight(0.2f))
 
-            Row(modifier = Modifier
-                .fillMaxWidth()
-                .height(95.dp)
-                .align(Alignment.End)
-                .background(color = Color(0xff718588)),
-                horizontalArrangement = Arrangement.SpaceEvenly
-            ) {
-                IconButton(
-                    onClick = { /*TODO*/ },
-                    modifier = Modifier.size(120.dp)
+
+                Spacer(modifier = Modifier.height(110.dp))
+
+                Row(
+                    modifier = Modifier.fillMaxWidth(),
+                    horizontalArrangement = Arrangement.Center,
+                    verticalAlignment = Alignment.CenterVertically
                 ) {
-                    Icon(
-                        bitmap = ImageBitmap.imageResource(R.drawable.message),
-                        contentDescription ="",
-                        modifier = Modifier.size(55.dp))
+                    Button(
+                        onClick = { },
+                        modifier = Modifier
+                            .width(278.dp)
+                            .height(45.dp),
+                        shape = RoundedCornerShape(20),
+                        colors = ButtonDefaults.buttonColors(containerColor = Color(0xff78EE99))
+                    )
+                    {
+                        Text(
+                            text = "Сохранить",
+                            fontSize = 22.sp,
+                            fontWeight = FontWeight.W700,
+                            color = Color.White
+                        )
+                    }
                 }
-                IconButton(
-                    onClick = { /*TODO*/ },
-                    modifier = Modifier.size(120.dp)
+
+                Spacer(modifier = Modifier.height(25.dp))
+
+                Row(
+                    modifier = Modifier.fillMaxWidth(),
+                    horizontalArrangement = Arrangement.Center,
+                    verticalAlignment = Alignment.CenterVertically
                 ) {
-                    Icon(
-                        bitmap = ImageBitmap.imageResource(R.drawable.catalog),
-                        contentDescription ="",
-                        modifier = Modifier.size(55.dp))
+                    Button(
+                        onClick = { },
+                        modifier = Modifier
+                            .width(278.dp)
+                            .height(45.dp),
+                        shape = RoundedCornerShape(20),
+                        colors = ButtonDefaults.buttonColors(containerColor = Color(0xffFC5050))
+                    )
+                    {
+                        Text(
+                            text = "Выход",
+                            fontSize = 22.sp,
+                            fontWeight = FontWeight.W700,
+                            color = Color.White
+                        )
+                    }
                 }
-                IconButton(
-                    onClick = { /*TODO*/ },
-                    modifier = Modifier.size(120.dp)
+
+                Spacer(modifier = Modifier.weight(0.2f))
+
+                Row(
+                    modifier = Modifier
+                        .fillMaxWidth()
+                        .height(95.dp)
+                        //.align(Alignment.End)
+                        .background(color = Color(0xff718588)),
+                    horizontalArrangement = Arrangement.SpaceEvenly
                 ) {
-                    Icon(
-                        bitmap = ImageBitmap.imageResource(R.drawable.profileblack),
-                        contentDescription ="",
-                        modifier = Modifier.size(55.dp))
-                }
+                    IconButton(
+                        onClick = { /*TODO*/ },
+                        modifier = Modifier.size(120.dp)
+                    ) {
+                        Icon(
+                            bitmap = ImageBitmap.imageResource(R.drawable.message),
+                            contentDescription = "Поддержка",
+                            modifier = Modifier.size(55.dp)
+                        )
+                    }
+                    IconButton(
+                        onClick = { /*TODO*/ },
+                        modifier = Modifier.size(120.dp)
+                    ) {
+                        Icon(
+                            bitmap = ImageBitmap.imageResource(R.drawable.catalog),
+                            contentDescription = "Каталог",
+                            modifier = Modifier.size(55.dp)
+                        )
+                    }
+                    IconButton(
+                        onClick = { /*TODO*/ },
+                        modifier = Modifier.size(120.dp)
+                    ) {
+                        Icon(
+                            bitmap = ImageBitmap.imageResource(R.drawable.profileblack),
+                            contentDescription = "Профиль",
+                            modifier = Modifier.size(55.dp)
+                        )
+                    }
 
+                }
             }
         }
     }

+ 10 - 5
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/Screens/RegistrationScreen.kt

@@ -128,7 +128,7 @@ fun Registration(
                     fontSize = 40.sp
                 )
 
-                Spacer(modifier = Modifier.height(50.dp))
+                Spacer(modifier = Modifier.height(30.dp))
 
                 Row(
                     modifier = Modifier.fillMaxWidth(),
@@ -145,7 +145,8 @@ fun Registration(
                 }
                 TextField(
                     modifier = Modifier
-                        .width(320.dp).padding(top = 30.dp),
+                        .width(320.dp)
+                        .padding(top = 30.dp),
                     maxLines = 1,
                     singleLine = true,
                     shape = RoundedCornerShape(20.dp),
@@ -160,7 +161,9 @@ fun Registration(
                 )
 
                 TextField(
-                    modifier = Modifier.width(320.dp).padding(bottom = 110.dp),
+                    modifier = Modifier
+                        .width(320.dp)
+                        .padding(bottom = 110.dp),
                     shape = RoundedCornerShape(20.dp),
                     maxLines = 1,
                     singleLine = true,
@@ -172,8 +175,10 @@ fun Registration(
                 )
 
                 Button(
-                    onClick = {viewModel.singUp(context,userEmail,userPassword)
-                        f.value = true},
+                    onClick = {
+                        viewModel.singUp(context, userEmail, userPassword)
+                        f.value = true
+                    },
                     modifier = Modifier
                         .width(278.dp)
                         .height(45.dp),

+ 1 - 1
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/ViewModelsPack/SupabaseAuthViewModel.kt

@@ -60,7 +60,7 @@ class SupabaseAuthViewModel : ViewModel() {
     ) {
         viewModelScope.launch {
             try {
-                client.auth.signInWith(Email) {
+                client.auth.signUpWith(Email) {
                     email = userEmail
                     password = userPassword
                 }