Przeglądaj źródła

feat: Добавление файлов для навигации

http://gogs.ngknn.local:3000/K1rakato/MobileStore.git 1 tydzień temu
rodzic
commit
99d912b4d6
14 zmienionych plików z 168 dodań i 9 usunięć
  1. 1 1
      ProjectApp/TomatoAndPotatoAPP/.idea/other.xml
  2. 1 2
      ProjectApp/TomatoAndPotatoAPP/app/build.gradle.kts
  3. 108 0
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/ViewModelsPack/SupabaseAuthViewModel.kt
  4. 1 1
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/GenderTable.kt
  5. 1 1
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/Plants.kt
  6. 1 1
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/RolesTable.kt
  7. 1 1
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/TypesOfPlants.kt
  8. 7 0
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/UserState.kt
  9. 1 1
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/UsersTable.kt
  10. 1 1
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/network/TomatAndPotatClient.kt
  11. 11 0
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/navigationPack/AppNavigation.kt
  12. 8 0
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/utils/ProfileString.kt
  13. 24 0
      ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/utils/SharedPreferenceHelper.kt
  14. 2 0
      ProjectApp/TomatoAndPotatoAPP/gradle/libs.versions.toml

+ 1 - 1
ProjectApp/TomatoAndPotatoAPP/.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" />

+ 1 - 2
ProjectApp/TomatoAndPotatoAPP/app/build.gradle.kts

@@ -75,8 +75,7 @@ dependencies {
 
     implementation(libs.ktor.client.android)
 
-    implementation (libs.androidx.navigation.compose)
 
-    implementation ("androidx.lifecycle:lifecycle-extensions:2.2.0")
+    implementation (libs.androidx.navigation.compose.v282)
 
 }

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

@@ -0,0 +1,108 @@
+package com.example.tomatoandpotatoapp.ViewModelsPack
+
+import android.content.Context
+import android.content.SharedPreferences
+import androidx.compose.runtime.State
+import androidx.compose.runtime.mutableStateOf
+import androidx.lifecycle.ViewModel
+import androidx.lifecycle.viewModelScope
+import com.example.tomatoandpotatoapp.data.models.GenderTable
+import com.example.tomatoandpotatoapp.data.models.Plants
+import com.example.tomatoandpotatoapp.data.models.RolesTable
+import com.example.tomatoandpotatoapp.data.models.TypesOfPlants
+import com.example.tomatoandpotatoapp.data.models.UserState
+import com.example.tomatoandpotatoapp.data.models.UsersTable
+import com.example.tomatoandpotatoapp.data.network.TomatAndPotatClient.client
+import com.example.tomatoandpotatoapp.utils.SharedPreferenceHelper
+import io.github.jan.supabase.auth.admin.AdminUserBuilder
+import io.github.jan.supabase.auth.auth
+import io.github.jan.supabase.auth.providers.builtin.Email
+import kotlinx.coroutines.launch
+
+class SupabaseAuthViewModel : ViewModel() {
+    private val _userState = mutableStateOf<UserState>(UserState.Loading)
+    val userState: State<UserState> = _userState
+
+    private val _users = mutableStateOf(listOf<UsersTable>())
+    val users: State<List<UsersTable>> = _users
+
+    private val _plants = mutableStateOf(listOf<Plants>())
+    val plants: State<List<Plants>> = _plants
+
+    private val _typesOfPlants = mutableStateOf(listOf<TypesOfPlants>())
+    val typesOfPlants: State<List<TypesOfPlants>> = _typesOfPlants
+
+    private val _roles = mutableStateOf(listOf<RolesTable>())
+    val roles: State<List<RolesTable>> = _roles
+
+    private val _genders = mutableStateOf(listOf<GenderTable>())
+    val genders: State<List<GenderTable>> = _genders
+
+    fun singUp(
+        context: Context,
+        userEmail: String,
+        userPassword: String
+    ) {
+        viewModelScope.launch {
+            try {
+                client.auth.signInWith(Email) {
+                    email = userEmail
+                    password = userPassword
+                }
+                saveToken(context)
+                _userState.value = UserState.Success("Регистрация успешно пройдена!")
+            } catch (e: Exception) {
+                _userState.value = UserState.Error("Error${e.message}")
+            }
+        }
+
+    }
+
+    private fun saveToken(context: Context) {
+        viewModelScope.launch {
+            val accessToken = client.auth.currentAccessTokenOrNull() ?: ""
+            val sharedPref = SharedPreferenceHelper(context)
+            sharedPref.saveStringData("accessToken", accessToken)
+        }
+    }
+
+    private fun getToken(context: Context) {
+        val sharedPref = SharedPreferenceHelper(context)
+        sharedPref.getStringData("accessToken")
+    }
+
+    fun singIn(
+        context: Context,
+        userEmail: String,
+        userPassword: String
+    ) {
+        viewModelScope.launch {
+            try {
+                client.auth.signInWith(Email) {
+                    email = userEmail
+                    password = userPassword
+                }
+                saveToken(context)
+                _userState.value = UserState.Success("Успешный вход!")
+            }catch (e:Exception){
+                _userState.value = UserState.Error("Error ${e.message}")
+            }
+        }
+    }
+
+    fun singOut(context: Context){
+        val sharedPref =SharedPreferenceHelper(context)
+        viewModelScope.launch {
+            try {
+                client.auth.signOut()
+                sharedPref.clearPreferences()
+                _userState.value = UserState.Success("Успешный выход!")
+
+            }catch (e:Exception){
+                _userState.value =UserState.Error("Error ${e.message}")
+            }
+        }
+    }
+
+
+}

+ 1 - 1
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/models/GenderTable.kt → ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/GenderTable.kt

@@ -1,4 +1,4 @@
-package com.example.tomatoandpotatoapp.models
+package com.example.tomatoandpotatoapp.data.models
 
 import kotlinx.serialization.Serializable
 

+ 1 - 1
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/models/Plants.kt → ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/Plants.kt

@@ -1,4 +1,4 @@
-package com.example.tomatoandpotatoapp.models
+package com.example.tomatoandpotatoapp.data.models
 
 import kotlinx.serialization.Serializable
 

+ 1 - 1
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/models/RolesTable.kt → ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/RolesTable.kt

@@ -1,4 +1,4 @@
-package com.example.tomatoandpotatoapp.models
+package com.example.tomatoandpotatoapp.data.models
 
 import kotlinx.serialization.Serializable
 

+ 1 - 1
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/models/TypesOfPlants.kt → ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/TypesOfPlants.kt

@@ -1,4 +1,4 @@
-package com.example.tomatoandpotatoapp.models
+package com.example.tomatoandpotatoapp.data.models
 
 import kotlinx.serialization.Serializable
 

+ 7 - 0
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/UserState.kt

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

+ 1 - 1
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/models/UsersTable.kt → ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/models/UsersTable.kt

@@ -1,4 +1,4 @@
-package com.example.tomatoandpotatoapp.models
+package com.example.tomatoandpotatoapp.data.models
 
 import kotlinx.serialization.Serializable
 import java.sql.Date

+ 1 - 1
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/network/TomatAndPotatClient.kt → ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/data/network/TomatAndPotatClient.kt

@@ -1,4 +1,4 @@
-package com.example.tomatoandpotatoapp.network
+package com.example.tomatoandpotatoapp.data.network
 
 import io.github.jan.supabase.auth.Auth
 import io.github.jan.supabase.createSupabaseClient

+ 11 - 0
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/navigationPack/AppNavigation.kt

@@ -0,0 +1,11 @@
+package com.example.tomatoandpotatoapp.navigationPack
+
+import androidx.compose.runtime.Composable
+import com.example.tomatoandpotatoapp.ViewModelsPack.SupabaseAuthViewModel
+
+@Composable
+fun AppNavigation(viewModel: SupabaseAuthViewModel){
+
+    
+
+}

+ 8 - 0
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/utils/ProfileString.kt

@@ -0,0 +1,8 @@
+package com.example.tomatoandpotatoapp.utils
+
+import androidx.compose.runtime.Composable
+
+@Composable
+fun EditProfileString(){
+
+}

+ 24 - 0
ProjectApp/TomatoAndPotatoAPP/app/src/main/java/com/example/tomatoandpotatoapp/utils/SharedPreferenceHelper.kt

@@ -0,0 +1,24 @@
+package com.example.tomatoandpotatoapp.utils
+
+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 sharedPreferenceHelper = context.getSharedPreferences(MY_PREF_KEY, Context.MODE_PRIVATE)
+        sharedPreferenceHelper.edit().clear().apply()
+    }
+}

+ 2 - 0
ProjectApp/TomatoAndPotatoAPP/gradle/libs.versions.toml

@@ -13,10 +13,12 @@ lifecycleRuntimeKtx = "2.8.6"
 activityCompose = "1.9.2"
 composeBom = "2024.04.01"
 navigationCompose = "2.8.1"
+navigationComposeVersion = "2.8.2"
 
 [libraries]
 androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
 androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "navigationCompose" }
+androidx-navigation-compose-v282 = { module = "androidx.navigation:navigation-compose", version.ref = "navigationComposeVersion" }
 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" }