Ver código fonte

app: connect with database

Bobarik41p 2 semanas atrás
pai
commit
aa75fe1e13
23 arquivos alterados com 255 adições e 73 exclusões
  1. 1 1
      App/.idea/other.xml
  2. 12 0
      App/app/build.gradle.kts
  3. 1 1
      App/app/src/main/AndroidManifest.xml
  4. 20 0
      App/app/src/main/java/com/example/mystictale/Constants/SupabaseConnect.kt
  5. 4 0
      App/app/src/main/java/com/example/mystictale/MainActivity.kt
  6. 1 5
      App/app/src/main/java/com/example/mystictale/Screen/passwordRecovery/NewPassword.kt
  7. 1 1
      App/app/src/main/java/com/example/mystictale/Screen/passwordRecovery/PasswordRecovery.kt
  8. 7 3
      App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationDateOfBirth.kt
  9. 25 20
      App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationEmail.kt
  10. 36 5
      App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationGender.kt
  11. 7 3
      App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationName.kt
  12. 7 3
      App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationPassword.kt
  13. 2 5
      App/app/src/main/java/com/example/mystictale/Screen/signIn/SignIn.kt
  14. 65 0
      App/app/src/main/java/com/example/mystictale/ViewModels/AuthViewModel.kt
  15. 7 0
      App/app/src/main/java/com/example/mystictale/models/UserState.kt
  16. 8 5
      App/app/src/main/java/com/example/mystictale/navigation/Navigation.kt
  17. 25 0
      App/app/src/main/java/com/example/mystictale/resources/SharedPreferenceHelper.kt
  18. 9 13
      App/app/src/main/java/com/example/mystictale/resources/components/ChooseGender.kt
  19. 1 2
      App/app/src/main/java/com/example/mystictale/resources/components/GenericTextField.kt
  20. 1 3
      App/app/src/main/java/com/example/mystictale/resources/components/PasswordTextField.kt
  21. 1 2
      App/app/src/main/java/com/example/mystictale/resources/components/dateComponents/DateOfBirthTextField.kt
  22. 1 1
      App/app/src/main/java/com/example/mystictale/resources/components/dateComponents/dateOfBirthVisualTransformation.kt
  23. 13 0
      App/gradle/libs.versions.toml

+ 1 - 1
App/.idea/other.xml

@@ -262,7 +262,7 @@
           <option name="codename" value="q6q" />
           <option name="id" value="q6q" />
           <option name="manufacturer" value="Samsung" />
-          <option name="name" value="SM-F956B" />
+          <option name="name" value="Galaxy Z Fold6" />
           <option name="screenDensity" value="420" />
           <option name="screenX" value="1856" />
           <option name="screenY" value="2160" />

+ 12 - 0
App/app/build.gradle.kts

@@ -1,6 +1,7 @@
 plugins {
     alias(libs.plugins.android.application)
     alias(libs.plugins.jetbrains.kotlin.android)
+    kotlin("plugin.serialization") version "1.9.0"
 }
 
 android {
@@ -71,4 +72,15 @@ dependencies {
     implementation(libs.androidx.navigation.fragment)
     implementation(libs.androidx.navigation.ui)
     implementation(libs.androidx.navigation.dynamic.features.fragment)
+    implementation(platform(libs.bom))
+    implementation(libs.postgrest.kt)
+    implementation(libs.auth.kt)
+    implementation(libs.realtime.kt)
+    implementation(libs.ktor.client.okhttp)
+    implementation (libs.storage.kt)
+    implementation (libs.androidx.fragment.ktx)
+    implementation (libs.androidx.lifecycle.viewmodel.ktx)
+    implementation (libs.androidx.lifecycle.viewmodel.compose)
+
+
 }

+ 1 - 1
App/app/src/main/AndroidManifest.xml

@@ -1,7 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools">
-
+    <uses-permission android:name="android.permission.INTERNET"/>
     <application
         android:allowBackup="true"
         android:dataExtractionRules="@xml/data_extraction_rules"

+ 20 - 0
App/app/src/main/java/com/example/mystictale/Constants/SupabaseConnect.kt

@@ -0,0 +1,20 @@
+package com.example.mystictale.Constants
+
+import io.github.jan.supabase.auth.Auth
+import io.github.jan.supabase.createSupabaseClient
+import io.github.jan.supabase.postgrest.Postgrest
+import io.github.jan.supabase.postgrest.PropertyConversionMethod
+import io.github.jan.supabase.storage.Storage
+
+object SupabaseConnect {
+    val supabase = createSupabaseClient(
+        supabaseUrl = "https://eykhnnlgofgxdzlixydt.supabase.co",
+        supabaseKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImV5a2hubmxnb2ZneGR6bGl4eWR0Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MjkyMzQ4NzgsImV4cCI6MjA0NDgxMDg3OH0.gG_nBmJ1KjC3se3HHNoBJLN8UA-aTw7JJw9PIMwJoL0"
+    ) {
+        install(Auth)
+        install(Postgrest){
+            propertyConversionMethod = PropertyConversionMethod.SERIAL_NAME
+        }
+        install(Storage)
+    }
+}

+ 4 - 0
App/app/src/main/java/com/example/mystictale/MainActivity.kt

@@ -5,17 +5,21 @@ import android.os.Bundle
 import androidx.activity.ComponentActivity
 import androidx.activity.compose.setContent
 import androidx.activity.enableEdgeToEdge
+import androidx.activity.viewModels
 import androidx.annotation.RequiresApi
+import com.example.mystictale.ViewModels.AuthViewModel
 import com.example.mystictale.navigation.Navigation
 import com.example.mystictale.ui.theme.MysticTaleTheme
 
 class MainActivity : ComponentActivity() {
     @RequiresApi(Build.VERSION_CODES.O)
     override fun onCreate(savedInstanceState: Bundle?) {
+
         super.onCreate(savedInstanceState)
         enableEdgeToEdge()
         setContent {
             MysticTaleTheme {
+
                 Navigation()
 
             }

+ 1 - 5
App/app/src/main/java/com/example/mystictale/Screen/passwordRecovery/NewPassword.kt

@@ -5,7 +5,6 @@ import androidx.compose.foundation.gestures.detectTapGestures
 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
@@ -15,7 +14,6 @@ import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.shape.RoundedCornerShape
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonColors
-import androidx.compose.material3.LinearProgressIndicator
 import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
@@ -25,7 +23,6 @@ import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.draw.paint
 import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.graphics.StrokeCap
 import androidx.compose.ui.input.pointer.pointerInput
 import androidx.compose.ui.layout.ContentScale
 import androidx.compose.ui.platform.LocalFocusManager
@@ -37,9 +34,8 @@ import androidx.compose.ui.unit.sp
 import androidx.navigation.NavController
 import com.example.mystictale.R
 import com.example.mystictale.navigation.Screens
-import com.example.mystictale.resources.PasswordTextField
+import com.example.mystictale.resources.components.PasswordTextField
 import com.example.mystictale.ui.theme.DarkPurple
-import com.example.mystictale.ui.theme.Grey
 import com.example.mystictale.ui.theme.OpenSans
 
 @Composable

+ 1 - 1
App/app/src/main/java/com/example/mystictale/Screen/passwordRecovery/PasswordRecovery.kt

@@ -36,7 +36,7 @@ import androidx.compose.ui.unit.sp
 import androidx.navigation.NavController
 import com.example.mystictale.R
 import com.example.mystictale.navigation.Screens
-import com.example.mystictale.resources.GenericTextField
+import com.example.mystictale.resources.components.GenericTextField
 import com.example.mystictale.ui.theme.DarkPurple
 import com.example.mystictale.ui.theme.OpenSans
 

+ 7 - 3
App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationDateOfBirth.kt

@@ -41,8 +41,9 @@ import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.navigation.NavController
 import com.example.mystictale.R
+import com.example.mystictale.ViewModels.AuthViewModel
 import com.example.mystictale.navigation.Screens
-import com.example.mystictale.resources.DateOfBirthTextField
+import com.example.mystictale.resources.components.dateComponents.DateOfBirthTextField
 import com.example.mystictale.ui.theme.DarkPurple
 import com.example.mystictale.ui.theme.Grey
 import com.example.mystictale.ui.theme.OpenSans
@@ -54,7 +55,7 @@ import java.time.format.DateTimeFormatter
 
 @RequiresApi(Build.VERSION_CODES.O)
 @Composable
-fun RegistrationDateOfBirth(navController: NavController) {
+fun RegistrationDateOfBirth(navController: NavController, viewModel: AuthViewModel) {
     val focusManager = LocalFocusManager.current
     val keyboardController = LocalSoftwareKeyboardController.current
     var pickedDate by remember { mutableStateOf(LocalDate.now()) }
@@ -154,7 +155,10 @@ fun RegistrationDateOfBirth(navController: NavController) {
 
         Box(Modifier.padding(bottom = 50.dp)) {
             Button(
-                onClick = { navController.navigate(Screens.RegistrationGender.route) },
+                onClick = {
+                    viewModel.dateOfBirth = formattedDateFromBase
+                    navController.navigate(Screens.RegistrationGender.route)
+                },
                 modifier = Modifier
                     .width(290.dp)
                     .height(48.dp),

+ 25 - 20
App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationEmail.kt

@@ -37,14 +37,15 @@ import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.navigation.NavController
 import com.example.mystictale.R
+import com.example.mystictale.ViewModels.AuthViewModel
 import com.example.mystictale.navigation.Screens
-import com.example.mystictale.resources.GenericTextField
+import com.example.mystictale.resources.components.GenericTextField
 import com.example.mystictale.ui.theme.DarkPurple
 import com.example.mystictale.ui.theme.Grey
 import com.example.mystictale.ui.theme.OpenSans
 
 @Composable
-fun RegistrationEmail(navController: NavController) {
+fun RegistrationEmail(navController: NavController, viewModel: AuthViewModel) {
     val focusManager = LocalFocusManager.current
     val keyboardController = LocalSoftwareKeyboardController.current
     val email = remember {
@@ -77,7 +78,8 @@ fun RegistrationEmail(navController: NavController) {
                 contentAlignment = Alignment.TopStart
             ) {
                 Button(
-                    onClick = { navController.navigate(Screens.Start.route) }, colors = ButtonColors(
+                    onClick = { navController.navigate(Screens.Start.route) },
+                    colors = ButtonColors(
                         disabledContentColor = Color.White,
                         disabledContainerColor = Color.Transparent,
                         contentColor = Color.White,
@@ -111,26 +113,29 @@ fun RegistrationEmail(navController: NavController) {
                 }
             }
             Column(modifier = Modifier.padding(10.dp)) {
-            Spacer(modifier = Modifier.height(30.dp))
-            Text(
-                text = "Ваша электронная почта",
-                fontWeight = FontWeight.Bold,
-                fontFamily = OpenSans,
-                fontSize = 24.sp,
-                color = Color.White,
-                modifier = Modifier
-                    .fillMaxWidth(0.9f)
-                    .padding(start = 30.dp),
-                style = MaterialTheme.typography.headlineMedium
-            )
-            Spacer(modifier = Modifier.height(30.dp))
+                Spacer(modifier = Modifier.height(30.dp))
+                Text(
+                    text = "Ваша электронная почта",
+                    fontWeight = FontWeight.Bold,
+                    fontFamily = OpenSans,
+                    fontSize = 24.sp,
+                    color = Color.White,
+                    modifier = Modifier
+                        .fillMaxWidth(0.9f)
+                        .padding(start = 30.dp),
+                    style = MaterialTheme.typography.headlineMedium
+                )
+                Spacer(modifier = Modifier.height(30.dp))
 
-            GenericTextField(email.value,{email.value = it},"E-mail",KeyboardType.Email)
+                GenericTextField(email.value, { email.value = it }, "E-mail", KeyboardType.Email)
+            }
         }
-}
-        Box(Modifier.padding(bottom = 50.dp)){
+        Box(Modifier.padding(bottom = 50.dp)) {
             Button(
-                onClick = { navController.navigate(Screens.RegistrationPassword.route) },
+                onClick = {
+                    viewModel.email = email.value
+                    navController.navigate(Screens.RegistrationPassword.route)
+                },
                 modifier = Modifier
                     .width(310.dp)
                     .height(48.dp),

+ 36 - 5
App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationGender.kt

@@ -1,5 +1,6 @@
 package com.example.mystictale.Screen.registration
 
+import android.widget.Toast
 import androidx.compose.foundation.Image
 import androidx.compose.foundation.layout.Arrangement
 import androidx.compose.foundation.layout.Box
@@ -14,29 +15,40 @@ import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.shape.RoundedCornerShape
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonColors
+import androidx.compose.material3.CircularProgressIndicator
 import androidx.compose.material3.LinearProgressIndicator
 import androidx.compose.material3.MaterialTheme
 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.draw.paint
+import androidx.compose.ui.graphics.BlendMode.Companion.Screen
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.graphics.StrokeCap
 import androidx.compose.ui.layout.ContentScale
+import androidx.compose.ui.platform.LocalContext
 import androidx.compose.ui.res.painterResource
 import androidx.compose.ui.text.font.FontWeight
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.navigation.NavController
 import com.example.mystictale.R
+import com.example.mystictale.ViewModels.AuthViewModel
+import com.example.mystictale.models.UserState
 import com.example.mystictale.navigation.Screens
-import com.example.mystictale.resources.ChooseGender
+import com.example.mystictale.resources.components.ChooseGender
 import com.example.mystictale.ui.theme.DarkPurple
 import com.example.mystictale.ui.theme.OpenSans
 
 @Composable
-fun RegistrationGender(navController: NavController) {
+fun RegistrationGender(navController: NavController, viewModel: AuthViewModel) {
+    val userState by viewModel.userState
+    val flag = remember { mutableStateOf(false) }
+    val context = LocalContext.current
     Column(
         Modifier
             .fillMaxSize()
@@ -106,12 +118,12 @@ fun RegistrationGender(navController: NavController) {
                     style = MaterialTheme.typography.headlineMedium
                 )
                 Spacer(modifier = Modifier.height(30.dp))
-                ChooseGender()
+                ChooseGender(viewModel)
             }
         }
         Box(Modifier.padding(bottom = 40.dp)) {
             Button(
-                onClick = { },
+                onClick = {viewModel.onSignUpEmailPassword(context = context) },
                 modifier = Modifier
                     .width(290.dp)
                     .height(48.dp),
@@ -123,7 +135,7 @@ fun RegistrationGender(navController: NavController) {
                     disabledContainerColor = DarkPurple
                 )
             ) {
-                Text("Далее", fontSize = 20.sp, fontWeight = FontWeight.Bold)
+                Text("Завершить", fontSize = 20.sp, fontWeight = FontWeight.Bold)
 
             }
 
@@ -131,5 +143,24 @@ fun RegistrationGender(navController: NavController) {
 
 
     }
+    if(flag.value){
+        when (userState) {
+            is UserState.Loading -> {
+               CircularProgressIndicator()
+            }
+
+            is UserState.Success -> {
+                val message = (userState as UserState.Success).message
+                navController.navigate(Screens.Start.route)
+                flag.value = false
+            }
+
+            is UserState.Error -> {
+                val message = (userState as UserState.Error).message
+                Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
+                flag.value = false
+            }
+        }
+    }
 
 }

+ 7 - 3
App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationName.kt

@@ -37,14 +37,15 @@ import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.navigation.NavController
 import com.example.mystictale.R
+import com.example.mystictale.ViewModels.AuthViewModel
 import com.example.mystictale.navigation.Screens
-import com.example.mystictale.resources.GenericTextField
+import com.example.mystictale.resources.components.GenericTextField
 import com.example.mystictale.ui.theme.DarkPurple
 import com.example.mystictale.ui.theme.Grey
 import com.example.mystictale.ui.theme.OpenSans
 
 @Composable
-fun RegistrationName(navController: NavController) {
+fun RegistrationName(navController: NavController, viewModel: AuthViewModel) {
     val focusManager = LocalFocusManager.current
     val keyboardController = LocalSoftwareKeyboardController.current
     val name = remember {
@@ -135,7 +136,10 @@ fun RegistrationName(navController: NavController) {
 
         Box(Modifier.padding(bottom = 50.dp)) {
             Button(
-                onClick = { navController.navigate(Screens.RegistrationDateOfBirth.route) },
+                onClick = {
+                    viewModel.name = name.value
+                    navController.navigate(Screens.RegistrationDateOfBirth.route)
+                },
                 modifier = Modifier
                     .width(310.dp)
                     .height(48.dp),

+ 7 - 3
App/app/src/main/java/com/example/mystictale/Screen/registration/RegistrationPassword.kt

@@ -36,14 +36,15 @@ import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.navigation.NavController
 import com.example.mystictale.R
+import com.example.mystictale.ViewModels.AuthViewModel
 import com.example.mystictale.navigation.Screens
-import com.example.mystictale.resources.PasswordTextField
+import com.example.mystictale.resources.components.PasswordTextField
 import com.example.mystictale.ui.theme.DarkPurple
 import com.example.mystictale.ui.theme.Grey
 import com.example.mystictale.ui.theme.OpenSans
 
 @Composable
-fun RegistrationPassword(navController: NavController) {
+fun RegistrationPassword(navController: NavController, viewModel: AuthViewModel) {
     val focusManager = LocalFocusManager.current
     val keyboardController = LocalSoftwareKeyboardController.current
     val password = remember {
@@ -159,7 +160,10 @@ fun RegistrationPassword(navController: NavController) {
 
         Box(Modifier.padding(bottom = 50.dp)) {
             Button(
-                onClick = { navController.navigate(Screens.RegistrationName.route) },
+                onClick = {
+                    viewModel.password = password.value
+                    navController.navigate(Screens.RegistrationName.route)
+                },
                 modifier = Modifier
                     .width(310.dp)
                     .height(48.dp),

+ 2 - 5
App/app/src/main/java/com/example/mystictale/Screen/signIn/SignIn.kt

@@ -6,7 +6,6 @@ import androidx.compose.foundation.gestures.detectTapGestures
 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
@@ -16,7 +15,6 @@ import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.shape.RoundedCornerShape
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonColors
-import androidx.compose.material3.LinearProgressIndicator
 import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
@@ -26,7 +24,6 @@ import androidx.compose.ui.Alignment
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.draw.paint
 import androidx.compose.ui.graphics.Color
-import androidx.compose.ui.graphics.StrokeCap
 import androidx.compose.ui.input.pointer.pointerInput
 import androidx.compose.ui.layout.ContentScale
 import androidx.compose.ui.platform.LocalFocusManager
@@ -39,8 +36,8 @@ import androidx.compose.ui.unit.sp
 import androidx.navigation.NavController
 import com.example.mystictale.R
 import com.example.mystictale.navigation.Screens
-import com.example.mystictale.resources.GenericTextField
-import com.example.mystictale.resources.PasswordTextField
+import com.example.mystictale.resources.components.GenericTextField
+import com.example.mystictale.resources.components.PasswordTextField
 import com.example.mystictale.ui.theme.DarkPurple
 import com.example.mystictale.ui.theme.Grey
 import com.example.mystictale.ui.theme.OpenSans

+ 65 - 0
App/app/src/main/java/com/example/mystictale/ViewModels/AuthViewModel.kt

@@ -0,0 +1,65 @@
+package com.example.mystictale.ViewModels
+
+import android.content.Context
+import android.util.Log
+import androidx.compose.runtime.State
+import androidx.compose.runtime.getValue
+import androidx.compose.runtime.mutableStateOf
+import androidx.compose.runtime.setValue
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.example.mystictale.Constants.SupabaseConnect
+import com.example.mystictale.models.UserState
+import com.example.mystictale.resources.SharedPreferenceHelper
+import io.github.jan.supabase.auth.auth
+import io.github.jan.supabase.auth.providers.builtin.Email
+import kotlinx.coroutines.launch
+
+class AuthViewModel: ViewModel() {
+    private val _userState = mutableStateOf<UserState>(UserState.Loading)
+    val userState: State<UserState> = _userState
+    var email by mutableStateOf<String?>(null)
+    var password by mutableStateOf<String?>(null)
+    var dateOfBirth by mutableStateOf<String?>(null)
+    var gender by mutableStateOf<Int?>(null)
+    var name by mutableStateOf<String?>(null)
+    fun onSignUpEmailPassword(context: Context) {
+        viewModelScope.launch {
+            try {
+                _userState.value = UserState.Loading
+                SupabaseConnect.supabase.auth.signUpWith(Email) {
+                    email
+                    password
+                }
+                saveToken(context)
+                _userState.value = UserState.Success("Success sing up")
+                Log.d("my_tag","Success sing up")
+
+
+            } catch (e: Exception) {
+                _userState.value = UserState.Error("Error: ${e.message}")
+                Log.d("my_tag",e.message!!)
+
+            }
+
+        }
+    }
+
+    private fun saveToken(context: Context) {
+        viewModelScope.launch {
+            val accessToken = SupabaseConnect.supabase.auth.currentAccessTokenOrNull()
+            val sharedPref = SharedPreferenceHelper(context)
+            sharedPref.saveStringData("accessToken", accessToken)
+        }
+    }
+
+    private fun getToken(context: Context): String? {
+        val sharedPref = SharedPreferenceHelper(context)
+        return sharedPref.getStringData("accessToken")
+
+    }
+
+
+
+
+}

+ 7 - 0
App/app/src/main/java/com/example/mystictale/models/UserState.kt

@@ -0,0 +1,7 @@
+package com.example.mystictale.models
+
+sealed class UserState {
+    object Loading: UserState()
+    data class Success(val message:String):UserState()
+    data class Error(val message:String):UserState()
+}

+ 8 - 5
App/app/src/main/java/com/example/mystictale/navigation/Navigation.kt

@@ -3,6 +3,7 @@ package com.example.mystictale.navigation
 import android.os.Build
 import androidx.annotation.RequiresApi
 import androidx.compose.runtime.Composable
+import androidx.lifecycle.viewmodel.compose.viewModel
 import androidx.navigation.compose.NavHost
 import androidx.navigation.compose.composable
 import androidx.navigation.compose.rememberNavController
@@ -15,10 +16,12 @@ import com.example.mystictale.Screen.Start
 import com.example.mystictale.Screen.passwordRecovery.NewPassword
 import com.example.mystictale.Screen.passwordRecovery.PasswordRecovery
 import com.example.mystictale.Screen.signIn.SignIn
+import com.example.mystictale.ViewModels.AuthViewModel
 
 @RequiresApi(Build.VERSION_CODES.O)
 @Composable
 fun Navigation() {
+    val viewModel: AuthViewModel = viewModel()
     val navController = rememberNavController()
     NavHost(navController = navController, startDestination = Screens.Start.route)
     {
@@ -28,23 +31,23 @@ fun Navigation() {
         }
         composable(Screens.RegistrationEmail.route)
         {
-            RegistrationEmail(navController)
+            RegistrationEmail(navController,viewModel)
         }
         composable(Screens.RegistrationName.route)
         {
-            RegistrationName(navController)
+            RegistrationName(navController,viewModel)
         }
         composable(Screens.RegistrationPassword.route)
         {
-            RegistrationPassword(navController)
+            RegistrationPassword(navController,viewModel)
         }
         composable(Screens.RegistrationDateOfBirth.route)
         {
-            RegistrationDateOfBirth(navController)
+            RegistrationDateOfBirth(navController,viewModel)
         }
         composable(Screens.RegistrationGender.route)
         {
-            RegistrationGender(navController)
+            RegistrationGender(navController,viewModel)
         }
         composable(Screens.SingIn.route)
         {

+ 25 - 0
App/app/src/main/java/com/example/mystictale/resources/SharedPreferenceHelper.kt

@@ -0,0 +1,25 @@
+package com.example.mystictale.resources
+
+import android.content.Context
+
+class SharedPreferenceHelper(private val context: Context) {
+
+    companion object {
+        private const val MY_PREF_KEY = "MY_PREF"
+    }
+
+    fun saveStringData(key: String, data: String?) {
+        val sharedPreferences = context.getSharedPreferences(MY_PREF_KEY, Context.MODE_PRIVATE)
+        sharedPreferences.edit().putString(key, data).apply()
+    }
+
+    fun getStringData(key: String): String? {
+        val sharedPreferences = context.getSharedPreferences(MY_PREF_KEY, Context.MODE_PRIVATE)
+        return sharedPreferences.getString(key, null)
+    }
+
+    fun clearPreferences() {
+        val sharedPreferences = context.getSharedPreferences(MY_PREF_KEY, Context.MODE_PRIVATE)
+        sharedPreferences.edit().clear().apply()
+    }
+}

+ 9 - 13
App/app/src/main/java/com/example/mystictale/resources/ChooseGender.kt → App/app/src/main/java/com/example/mystictale/resources/components/ChooseGender.kt

@@ -1,4 +1,4 @@
-package com.example.mystictale.resources
+package com.example.mystictale.resources.components
 
 import androidx.compose.foundation.background
 import androidx.compose.foundation.layout.Arrangement
@@ -9,9 +9,6 @@ import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.layout.height
 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
@@ -24,7 +21,6 @@ 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.Offset
 import androidx.compose.ui.geometry.Size
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.layout.onGloballyPositioned
@@ -34,11 +30,12 @@ import androidx.compose.ui.unit.DpOffset
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.compose.ui.unit.toSize
+import com.example.mystictale.ViewModels.AuthViewModel
 import com.example.mystictale.ui.theme.DarkPurple
 import com.example.mystictale.ui.theme.OpenSans
 
 @Composable
-fun ChooseGender() {
+fun ChooseGender( viewModel: AuthViewModel) {
     var expanded by remember {
         mutableStateOf(false)
     }
@@ -49,12 +46,6 @@ fun ChooseGender() {
     var textFiledSize by remember {
         mutableStateOf(Size.Zero)
     }
-    val icon = if (expanded) {
-        Icons.Filled.KeyboardArrowUp
-    } else {
-        Icons.Filled.KeyboardArrowDown
-    }
-    var buttonPosition by remember { mutableStateOf(Offset.Zero) }
     Column(
         modifier = Modifier
             .fillMaxWidth(),
@@ -80,7 +71,7 @@ fun ChooseGender() {
                 verticalAlignment = Alignment.CenterVertically
             ) {
                 Text(
-                    text = if (selectedItem.isNotEmpty()) selectedItem else "Выберете пол",
+                    text = selectedItem.ifEmpty { "Выберете пол" },
                     fontSize = 20.sp,
                     fontFamily = OpenSans,
                     fontWeight = FontWeight.Bold,
@@ -111,6 +102,11 @@ fun ChooseGender() {
                 }, onClick = {
                     selectedItem = label
                     expanded = false
+                    if(selectedItem == "Женский"){
+                        viewModel.gender = 1
+                    }else{
+                        viewModel.gender = 2
+                    }
 
                 })
             }

+ 1 - 2
App/app/src/main/java/com/example/mystictale/resources/GenericTextField.kt → App/app/src/main/java/com/example/mystictale/resources/components/GenericTextField.kt

@@ -1,6 +1,5 @@
-package com.example.mystictale.resources
+package com.example.mystictale.resources.components
 
-import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.text.KeyboardOptions

+ 1 - 3
App/app/src/main/java/com/example/mystictale/resources/PasswordTextField.kt → App/app/src/main/java/com/example/mystictale/resources/components/PasswordTextField.kt

@@ -1,6 +1,5 @@
-package com.example.mystictale.resources
+package com.example.mystictale.resources.components
 
-import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.width
 import androidx.compose.foundation.text.KeyboardOptions
@@ -15,7 +14,6 @@ import androidx.compose.runtime.remember
 import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.res.painterResource
-import androidx.compose.ui.text.Placeholder
 import androidx.compose.ui.text.TextStyle
 import androidx.compose.ui.text.font.FontWeight
 import androidx.compose.ui.text.input.KeyboardType

+ 1 - 2
App/app/src/main/java/com/example/mystictale/resources/DateOfBirthTextField.kt → App/app/src/main/java/com/example/mystictale/resources/components/dateComponents/DateOfBirthTextField.kt

@@ -1,7 +1,6 @@
-package com.example.mystictale.resources
+package com.example.mystictale.resources.components.dateComponents
 
 import androidx.compose.foundation.clickable
-import androidx.compose.foundation.layout.fillMaxWidth
 import androidx.compose.foundation.layout.offset
 import androidx.compose.foundation.layout.padding
 import androidx.compose.foundation.layout.width

+ 1 - 1
App/app/src/main/java/com/example/mystictale/resources/dateOfBirthVisualTransformation.kt → App/app/src/main/java/com/example/mystictale/resources/components/dateComponents/dateOfBirthVisualTransformation.kt

@@ -1,4 +1,4 @@
-package com.example.mystictale.resources
+package com.example.mystictale.resources.components.dateComponents
 
 import androidx.compose.ui.text.AnnotatedString
 import androidx.compose.ui.text.input.OffsetMapping

+ 13 - 0
App/gradle/libs.versions.toml

@@ -1,19 +1,28 @@
 [versions]
 agp = "8.5.1"
+bom = "3.0.2"
+fragmentKtx = "1.8.5"
 kotlin = "1.9.0"
 datetime = "0.8.1-rc"
 coreKtx = "1.13.1"
 junit = "4.13.2"
 junitVersion = "1.2.1"
 espressoCore = "3.6.1"
+ktorClientOkhttp = "3.0.0-rc-1"
 lifecycleRuntimeKtx = "2.8.5"
 activityCompose = "1.9.2"
 composeBom = "2024.04.01"
+lifecycleViewmodelKtx = "2.8.7"
 material3 = "1.4.0-alpha03"
 navigationCompose = "2.8.0"
 
 [libraries]
 androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
+androidx-fragment-ktx = { module = "androidx.fragment:fragment-ktx", version.ref = "fragmentKtx" }
+androidx-lifecycle-viewmodel-compose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "lifecycleViewmodelKtx" }
+androidx-lifecycle-viewmodel-ktx = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "lifecycleViewmodelKtx" }
+auth-kt = { module = "io.github.jan-tennert.supabase:auth-kt" }
+bom = { module = "io.github.jan-tennert.supabase:bom", version.ref = "bom" }
 junit = { group = "junit", name = "junit", version.ref = "junit" }
 datetime = { module = "io.github.vanpra.compose-material-dialogs:datetime", version.ref = "datetime" }
 androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" }
@@ -28,12 +37,16 @@ androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-toolin
 androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" }
 androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" }
 androidx-material3 = { group = "androidx.compose.material3", name = "material3" }
+ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktorClientOkhttp" }
 material3 = { module = "androidx.compose.material3:material3", version.ref = "material3" }
+storage-kt = { module = "io.github.jan-tennert.supabase:storage-kt", version.ref = "bom" }
 
 androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
 androidx-navigation-dynamic-features-fragment = { module = "androidx.navigation:navigation-dynamic-features-fragment", version.ref = "navigationCompose" }
 androidx-navigation-fragment = { module = "androidx.navigation:navigation-fragment", version.ref = "navigationCompose" }
 androidx-navigation-ui = { module = "androidx.navigation:navigation-ui", version.ref = "navigationCompose" }
+postgrest-kt = { module = "io.github.jan-tennert.supabase:postgrest-kt" }
+realtime-kt = { module = "io.github.jan-tennert.supabase:realtime-kt" }
 
 [plugins]
 android-application = { id = "com.android.application", version.ref = "agp" }