Selaa lähdekoodia

app: add home page

Anna 2 viikkoa sitten
vanhempi
commit
bef4c99cb2

+ 1 - 0
Project_exvesta/app/build.gradle.kts

@@ -60,6 +60,7 @@ dependencies {
     implementation(libs.androidx.ui.tooling.preview)
     implementation(libs.androidx.material3)
     implementation(libs.androidx.navigation.compose)
+    implementation(libs.androidx.storage)
     testImplementation(libs.junit)
     androidTestImplementation(libs.androidx.junit)
     androidTestImplementation(libs.androidx.espresso.core)

+ 74 - 0
Project_exvesta/app/src/main/java/com/example/exvesta/MainViewModel.kt

@@ -0,0 +1,74 @@
+package com.example.exvesta
+
+import androidx.lifecycle.LiveData
+import androidx.lifecycle.MutableLiveData
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.example.exvesta.domain.utils.Constants
+import io.github.jan.supabase.auth.auth
+import io.github.jan.supabase.auth.providers.builtin.Email
+import io.github.jan.supabase.auth.providers.builtin.OTP
+import kotlinx.coroutines.launch
+
+import kotlinx.coroutines.launch
+class MainViewModel(): ViewModel() {
+    private val _loginResult = MutableLiveData<Boolean>()
+    val loginResult: LiveData<Boolean> = _loginResult
+
+    fun onSignInEmailCode(emailUser: String) {
+        viewModelScope.launch {
+            try {
+                Constants.supabase.auth.signInWith(OTP) {
+                    email = emailUser
+                    createUser = false
+                }
+
+            } catch (e: Exception) {
+                println(e.message.toString())
+
+            }
+
+        }
+    }
+
+    fun onSignInEmailPassword(emailUser: String, passwordUser: String): Boolean {
+        viewModelScope.launch {
+            try {
+                val user = Constants.supabase.auth.signInWith(Email) {
+                    email = emailUser
+                    password = passwordUser
+                }
+                println(user.toString())
+                println(Constants.supabase.auth.currentUserOrNull()!!.id)
+                println("Success")
+                _loginResult.postValue(true)
+            } catch (e: Exception) {
+                println("Error")
+                println(e.message.toString())
+                _loginResult.postValue(false)
+            }
+        }
+        return _loginResult.value ?: false
+    }
+    fun onSignUpEmail(emailUser: String, passwordUser: String): Boolean {
+        viewModelScope.launch {
+            try{
+                var  user =  Constants.supabase.auth.signUpWith(Email) {
+                    email = emailUser
+                    password = passwordUser
+                }
+                println(user.toString())
+                println(Constants.supabase.auth.currentUserOrNull()!!.id)
+                println("Success")
+                _loginResult.postValue(true)
+            }
+            catch (e: Exception) {
+                println("Error")
+                println(e.message.toString())
+                _loginResult.postValue(false)
+            }
+
+        }
+        return _loginResult.value ?: false
+    }
+}

+ 174 - 0
Project_exvesta/app/src/main/java/com/example/exvesta/Screans/Home.kt

@@ -0,0 +1,174 @@
+package com.example.exvesta.Screans
+
+import androidx.compose.foundation.BorderStroke
+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.Row
+import androidx.compose.foundation.layout.Spacer
+import androidx.compose.foundation.layout.fillMaxSize
+import androidx.compose.foundation.layout.fillMaxWidth
+import androidx.compose.foundation.layout.height
+import androidx.compose.foundation.layout.offset
+import androidx.compose.foundation.layout.padding
+import androidx.compose.foundation.layout.width
+import androidx.compose.foundation.shape.CircleShape
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.Card
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.runtime.LaunchedEffect
+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.draw.clip
+import androidx.compose.ui.draw.shadow
+import androidx.compose.ui.graphics.Color
+
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.unit.dp
+import androidx.navigation.NavHostController
+
+import com.example.exvesta.R
+import com.example.exvesta.domain.utils.Constants
+import com.example.exvesta.model.Publicthings
+import com.example.exvesta.model.Type_dublicate
+import io.github.jan.supabase.postgrest.from
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.withContext
+
+@Composable
+fun Home(navHost: NavHostController) {
+var dubtype by remember { mutableStateOf<List<Type_dublicate>>(listOf()) }
+
+  var thingsdub by remember {mutableStateOf<List<Publicthings>>(listOf())}
+    LaunchedEffect(Unit){
+        withContext(Dispatchers.IO) {
+            thingsdub = Constants.supabase.from("Publicthings")
+                .select().decodeList<Publicthings>()
+        }
+    }
+    Column(
+        modifier = Modifier
+            .fillMaxSize()
+            .background(Color.White)
+            .padding(16.dp),
+        horizontalAlignment = Alignment.CenterHorizontally
+    ) {
+        Spacer(modifier = Modifier.height(40.dp))
+
+        Button(
+            onClick = { /*TODO*/ },
+            border = BorderStroke(1.dp, Color(0xFF92A2B0)),
+            modifier = Modifier
+                .fillMaxWidth()
+                .padding(vertical = 8.dp),
+            colors = ButtonDefaults.buttonColors(Color.White)
+        ) {
+            Text(text = "+ добавить фильтр", color = Color(0xFF92A2B0))
+        }
+
+        Spacer(modifier = Modifier.height(16.dp))
+
+        Row(
+            modifier = Modifier.fillMaxWidth(),
+            horizontalArrangement = Arrangement.SpaceAround
+        ) {
+            // Кнопка "вещи"
+            Box(
+                modifier = Modifier
+                    .weight(1f)
+                    .padding(bottom = 4.dp) // Паддинг для отступа от нижней тени
+                    .clip(RoundedCornerShape(16.dp))
+            ) {
+                // Тень
+                Box(
+                    modifier = Modifier
+                        .align(Alignment.BottomCenter)
+                        .fillMaxWidth()
+                        .height(4.dp) // Высота тени
+                        .background(Color.Black.copy(alpha = 0.2f)) // Цвет и прозрачность тени
+                        .offset(y = 2.dp), // Смещение тени вниз
+
+                )
+
+                // Кнопка
+                Button(
+                    onClick = { /*TODO*/ },
+                    modifier = Modifier
+                        .fillMaxWidth()
+                        .shadow(0.dp, shape = CircleShape, clip = false), // Убираем тень у кнопки
+                    colors = ButtonDefaults.buttonColors(Color.White),
+                    shape = RoundedCornerShape(16.dp) // Скругление кнопки
+                ) {
+                    Text(text = "вещи", color = Color(0xFF92A2B0))
+                }
+            }
+
+            Spacer(modifier = Modifier.width(16.dp))
+
+            // Кнопка "образы"
+            Box(
+                modifier = Modifier
+                    .weight(1f)
+                    .padding(bottom = 4.dp) // Паддинг для отступа от нижней тени
+                    .clip(RoundedCornerShape(16.dp))
+            ) {
+                // Тень
+                Box(
+                    modifier = Modifier
+                        .align(Alignment.BottomCenter)
+                        .fillMaxWidth()
+                        .height(4.dp) // Высота тени
+                        .background(Color.Black.copy(alpha = 0.2f)) // Цвет и прозрачность тени
+                        .offset(y = 2.dp) // Смещение тени вниз
+                )
+
+                // Кнопка
+                Button(
+                    onClick = { /*TODO*/ },
+                    modifier = Modifier
+                        .fillMaxWidth()
+                        .shadow(0.dp, shape = CircleShape, clip = false), // Убираем тень у кнопки
+                    colors = ButtonDefaults.buttonColors(Color.White),
+                    shape = RoundedCornerShape(16.dp) // Скругление кнопки
+                ) {
+                    Text(text = "образы", color = Color(0xFF92A2B0))
+                }
+            }
+        }
+
+        Spacer(modifier = Modifier.height(16.dp))
+
+        Card(
+            modifier = Modifier
+                .fillMaxWidth()
+                .height(250.dp),
+        ) {
+            Column(
+                modifier = Modifier
+                    .fillMaxSize()
+                    .padding(16.dp)
+            ) {
+                Image(
+                    painter = painterResource(id = R.drawable.i),
+                    contentDescription = "Свитер",
+                    modifier = Modifier
+                        .fillMaxWidth()
+                        .height(150.dp)
+                        .clip(RoundedCornerShape(8.dp))
+                )
+                Spacer(modifier = Modifier.height(8.dp))
+                Text(text = "название: свитер")
+                Text(text = "категории: верхняя одежда, кофты, пряжа")
+                Text(text = "артикул: 38423")
+            }
+        }
+    }
+}

+ 39 - 13
Project_exvesta/app/src/main/java/com/example/exvesta/Screans/Login.kt

@@ -14,8 +14,11 @@ import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonDefaults
 import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButton
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.OutlinedTextFieldDefaults
 import androidx.compose.material3.Text
 import androidx.compose.material3.TextField
+import androidx.compose.material3.TextFieldColors
 import androidx.compose.material3.TextFieldDefaults
 import androidx.compose.runtime.Composable
 import androidx.compose.runtime.getValue
@@ -28,6 +31,7 @@ import androidx.compose.ui.draw.clip
 import androidx.compose.ui.geometry.Offset
 import androidx.compose.ui.graphics.Brush
 import androidx.compose.ui.graphics.Color
+
 import androidx.compose.ui.res.painterResource
 import androidx.compose.ui.text.TextStyle
 import androidx.compose.ui.text.font.FontWeight
@@ -74,36 +78,58 @@ fun Login(navHost: NavHostController) {
                 .height(350.dp)
                 .clip(RoundedCornerShape(16.dp))
         )
-
-        TextField(
+        Text(
+            text = "Добро пожаловать в  ваш личный гардероб exvesta",
+            fontSize = 12.sp,
+            color = Color(0xFF92A2B0)
+        )
+        Spacer(modifier = Modifier.height(16.dp))
+        OutlinedTextField(
             value = email.value,
             onValueChange = { email.value = it },
-            label = { Text("Логин") },
-            modifier = Modifier.fillMaxWidth()
+            label = { Text("Логин", color = Color(0xFFB9A791)) },
+            modifier = Modifier
+                .width(350.dp)
+                .height(50.dp)
+            ,
+            colors = TextFieldDefaults.colors(
+                unfocusedContainerColor =  Color(0xFFFEFAF3),
+               focusedContainerColor = Color(0xFFFFFFFF),
+                unfocusedIndicatorColor = Color(0xFFB9A791),
+                focusedIndicatorColor = Color(0xFFA18B72),
+
+            ),
+            shape = RoundedCornerShape(30.dp)
+
         )
         Spacer(modifier = Modifier.height(16.dp))
-        TextField(
+        OutlinedTextField(
             value = password.value,
             onValueChange = { password.value = it },
-            label = { Text("Пароль") },
+            label = { Text("Пароль", color = Color(0xFFB9A791)) },
             modifier = Modifier
 
                 .width(350.dp)
                 .height(50.dp)
 
+
             ,
-//            colors = TextFieldDefaults.Colors(
-//                backgroundColor = Color.White),
-//            visualTransformation = PasswordVisualTransformation(),
-//            shape = TextFieldDefaults.shape
+            colors = TextFieldDefaults.colors(
+                unfocusedContainerColor =  Color(0xFFFEFAF3),
+                focusedContainerColor = Color(0xFFFFFFFF),
+                unfocusedIndicatorColor = Color(0xFFB9A791),
+                focusedIndicatorColor = Color(0xFFA18B72),
+            ),
+            shape = RoundedCornerShape(30.dp)
+
         )
 
         Spacer(modifier = Modifier.height(30.dp))
         Button(
-            onClick = {  navHost.navigate("Login") },
+            onClick = {  navHost.navigate("Home") },
             modifier = Modifier
-                .width(350.dp)
-                .height(50.dp)
+                .width(370.dp)
+                .height(60.dp)
                 .padding(horizontal = 20.dp)
                 .background(
                     brush = Brush.horizontalGradient(

+ 2 - 1
Project_exvesta/app/src/main/java/com/example/exvesta/Screans/RegAuth.kt

@@ -83,9 +83,10 @@ fun RegAuth(navHost: NavHostController) {
                 fontWeight = FontWeight.Medium
             )
         }
+
         Spacer(modifier = Modifier.height(16.dp))
         Button(
-            onClick = { navHost.navigate("registration") },
+            onClick = { navHost.navigate("Registration") },
             modifier = Modifier
                 .width(350.dp)
                 .height(50.dp)

+ 176 - 0
Project_exvesta/app/src/main/java/com/example/exvesta/Screans/Registration.kt

@@ -0,0 +1,176 @@
+package com.example.exvesta.Screans
+
+import androidx.compose.foundation.Image
+import androidx.compose.foundation.background
+import androidx.compose.foundation.layout.Column
+import androidx.compose.foundation.layout.Spacer
+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.layout.width
+import androidx.compose.foundation.shape.RoundedCornerShape
+import androidx.compose.material3.Button
+import androidx.compose.material3.ButtonDefaults
+import androidx.compose.material3.Icon
+import androidx.compose.material3.IconButton
+import androidx.compose.material3.OutlinedTextField
+import androidx.compose.material3.OutlinedTextFieldDefaults
+import androidx.compose.material3.Text
+import androidx.compose.material3.TextField
+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.draw.clip
+import androidx.compose.ui.geometry.Offset
+import androidx.compose.ui.graphics.Brush
+import androidx.compose.ui.graphics.Color
+
+import androidx.compose.ui.res.painterResource
+import androidx.compose.ui.text.TextStyle
+import androidx.compose.ui.text.font.FontWeight
+import androidx.compose.ui.text.input.PasswordVisualTransformation
+import androidx.compose.ui.text.input.VisualTransformation
+import androidx.compose.ui.unit.dp
+import androidx.compose.ui.unit.sp
+import androidx.navigation.NavHostController
+
+import com.example.exvesta.R
+import com.example.exvesta.model.MainViewModel
+
+@Composable
+fun Registration(navHost: NavHostController) {
+    val viewModel = MainViewModel()
+    val email = remember { mutableStateOf("") }
+    val password = remember { mutableStateOf("")}
+    val gradientButton = Brush.linearGradient(
+        colors = listOf(
+            Color(0xFF6F4A48),
+            Color(0xFFC09F9C)
+        ),
+
+        start =  Offset(30.0f, 50.0f),
+        end =  Offset(200.0f, 50.0f)
+    );
+
+
+
+    Column(
+        modifier = Modifier
+            .fillMaxSize()
+            .background(Color.White),
+//        verticalArrangement = Arrangement.Center,
+        horizontalAlignment = Alignment.CenterHorizontally
+    ) {
+
+        Spacer(modifier = Modifier.height(100.dp))
+        Image(
+            painter = painterResource(id = R.drawable.back),
+            contentDescription = "Background Image",
+            modifier = Modifier
+                .fillMaxWidth()
+                .height(350.dp)
+                .clip(RoundedCornerShape(16.dp))
+        )
+        Text(
+            text = "Добро пожаловать в  ваш личный гардероб exvesta",
+            fontSize = 12.sp,
+            color = Color(0xFF92A2B0)
+        )
+        Spacer(modifier = Modifier.height(16.dp))
+        OutlinedTextField(
+            value = email.value,
+            onValueChange = { email.value = it },
+            label = { Text("Логин", color = Color(0xFFB9A791)) },
+            modifier = Modifier
+                .width(350.dp)
+                .height(50.dp)
+            ,
+            colors = TextFieldDefaults.colors(
+                unfocusedContainerColor =  Color(0xFFFEFAF3),
+                focusedContainerColor = Color(0xFFFFFFFF),
+                unfocusedIndicatorColor = Color(0xFFB9A791),
+                focusedIndicatorColor = Color(0xFFA18B72),
+
+                ),
+            shape = RoundedCornerShape(30.dp)
+
+        )
+        Spacer(modifier = Modifier.height(16.dp))
+        OutlinedTextField(
+            value = password.value,
+            onValueChange = { password.value = it },
+            label = { Text("Пароль", color = Color(0xFFB9A791)) },
+            modifier = Modifier
+
+                .width(350.dp)
+                .height(50.dp)
+
+
+            ,
+            colors = TextFieldDefaults.colors(
+                unfocusedContainerColor =  Color(0xFFFEFAF3),
+                focusedContainerColor = Color(0xFFFFFFFF),
+                unfocusedIndicatorColor = Color(0xFFB9A791),
+                focusedIndicatorColor = Color(0xFFA18B72),
+            ),
+            shape = RoundedCornerShape(30.dp)
+
+        )
+        Spacer(modifier = Modifier.height(16.dp))
+        OutlinedTextField(
+            value = password.value,
+            onValueChange = { password.value = it },
+            label = { Text("почта@mail.com", color = Color(0xFFB9A791)) },
+            modifier = Modifier
+
+                .width(350.dp)
+                .height(50.dp)
+
+
+            ,
+            colors = TextFieldDefaults.colors(
+                unfocusedContainerColor =  Color(0xFFFEFAF3),
+                focusedContainerColor = Color(0xFFFFFFFF),
+                unfocusedIndicatorColor = Color(0xFFB9A791),
+                focusedIndicatorColor = Color(0xFFA18B72),
+            ),
+            shape = RoundedCornerShape(30.dp)
+
+        )
+        Spacer(modifier = Modifier.height(30.dp))
+        Button(
+            onClick = {  navHost.navigate("Login") },
+            modifier = Modifier
+                .width(370.dp)
+                .height(60.dp)
+                .padding(horizontal = 20.dp)
+                .background(
+                    brush = Brush.horizontalGradient(
+                        colors = listOf(
+                            Color(0xFF6F4A48),
+                            Color(0xFFE7D2A9),
+                        )
+                    ), shape = ButtonDefaults.shape
+                )
+                .height(ButtonDefaults.MinHeight),
+
+            colors = ButtonDefaults.buttonColors(containerColor = Color.Transparent)
+        ) {
+            Text(
+                text = "зарегистрироваться",
+                fontSize = 16.sp,
+                fontWeight = FontWeight.Medium
+            )
+        }
+        Spacer(modifier = Modifier.height(16.dp))
+
+
+    }
+}

+ 16 - 0
Project_exvesta/app/src/main/java/com/example/exvesta/Screans/itempublicthings.kt

@@ -0,0 +1,16 @@
+package com.example.exvesta.Screans
+
+import androidx.compose.foundation.layout.padding
+import androidx.compose.material3.Text
+import androidx.compose.runtime.Composable
+import androidx.compose.ui.Modifier
+import androidx.compose.ui.unit.dp
+import com.example.exvesta.model.Publicthings
+
+@Composable
+fun Itempublicthings(publicthimgs: Publicthings){
+    Text(
+        publicthimgs.title,
+        modifier = Modifier.padding(8.dp),
+    )
+}

+ 1 - 1
Project_exvesta/app/src/main/java/com/example/exvesta/model/Publicthimgs.kt → Project_exvesta/app/src/main/java/com/example/exvesta/model/Publicthings.kt

@@ -1,7 +1,7 @@
 package com.example.exvesta.model
 import kotlinx.serialization.Serializable
 @Serializable
-public data class Publicthimgs(
+public data class Publicthings(
     val  id: Int,
     val title: String,
     val id_style: Int,

+ 9 - 0
Project_exvesta/app/src/main/java/com/example/exvesta/navigation/Navigation.kt

@@ -1,12 +1,15 @@
 package com.example.exvesta.navigation
 
 import androidx.compose.runtime.Composable
+import androidx.compose.ui.input.key.Key.Companion.Home
 import androidx.navigation.compose.NavHost
 import androidx.navigation.compose.composable
 import androidx.navigation.compose.rememberNavController
+import com.example.exvesta.Screans.Home
 import com.example.exvesta.Screans.Login
 import com.example.exvesta.Screans.Preloading
 import com.example.exvesta.Screans.RegAuth
+import com.example.exvesta.Screans.Registration
 
 @Composable
 fun Navigation(){
@@ -23,5 +26,11 @@ fun Navigation(){
         composable("Login"){
             Login(navController)
         }
+        composable("Registration"){
+            Registration(navController)
+        }
+        composable("Home"){
+            Home(navController)
+        }
     }
 }

+ 2 - 0
Project_exvesta/gradle/libs.versions.toml

@@ -24,6 +24,7 @@ storageKtVersion = "1.9.0"
 volley = "1.2.1"
 uiAndroid = "1.7.2"
 navigationCompose = "2.8.3"
+storage = "1.5.0"
 [libraries]
 androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
 auth-kt = { module = "io.github.jan-tennert.supabase:auth-kt" }
@@ -58,6 +59,7 @@ supabase-auth-kt = { module = "io.github.jan-tennert.supabase:auth-kt" }
 supabase-postgrest-kt = { module = "io.github.jan-tennert.supabase:postgrest-kt" }
 supabase-realtime-kt = { module = "io.github.jan-tennert.supabase:realtime-kt" }
 androidx-navigation-compose = { group = "androidx.navigation", name = "navigation-compose", version.ref = "navigationCompose" }
+androidx-storage = { group = "androidx.test.services", name = "storage", version.ref = "storage" }
 
 [plugins]
 android-application = { id = "com.android.application", version.ref = "agp" }