Prechádzať zdrojové kódy

сделалпереход на место при нажатии на его в меню

AlexMin 1 týždeň pred
rodič
commit
3fb7e13751

BIN
.gradle/8.7/executionHistory/executionHistory.bin


BIN
.gradle/8.7/executionHistory/executionHistory.lock


BIN
.gradle/8.7/fileHashes/fileHashes.bin


BIN
.gradle/8.7/fileHashes/fileHashes.lock


BIN
.gradle/8.7/fileHashes/resourceHashesCache.bin


BIN
.gradle/buildOutputCleanup/buildOutputCleanup.lock


BIN
.gradle/file-system.probe


+ 1 - 22
app/src/main/java/com/example/iplace/main/viewModel/MainViewModel.kt

@@ -2,27 +2,13 @@
 
 package com.example.iplace.main.viewModel
 
-import android.content.Context
-import android.os.Bundle
 import android.util.Log
-import android.widget.Toast
-import androidx.compose.runtime.MutableState
 import androidx.compose.runtime.State
-import androidx.compose.runtime.derivedStateOf
-import androidx.compose.runtime.getValue
 import androidx.compose.runtime.mutableStateOf
-import androidx.compose.runtime.remember
-import androidx.compose.runtime.setValue
-import androidx.core.os.bundleOf
-import androidx.lifecycle.LiveData
-import androidx.lifecycle.MutableLiveData
 import androidx.lifecycle.ViewModel
-import androidx.lifecycle.ViewModelProvider
 import androidx.lifecycle.viewModelScope
 import androidx.navigation.NavHostController
-import com.example.iplace.R
 import com.example.iplace.domain.Constants
-import com.example.iplace.model.Gender
 import com.example.iplace.model.Place
 import com.example.iplace.model.Users
 import io.github.jan.supabase.annotations.SupabaseExperimental
@@ -31,13 +17,8 @@ import io.github.jan.supabase.gotrue.providers.builtin.Email
 import io.github.jan.supabase.postgrest.from
 import io.github.jan.supabase.postgrest.query.Columns
 import io.github.jan.supabase.realtime.selectAsFlow
-import io.github.jan.supabase.supabaseJson
-import kotlinx.coroutines.Dispatchers
 import kotlinx.coroutines.flow.MutableStateFlow
-import kotlinx.coroutines.flow.StateFlow
-import kotlinx.coroutines.flow.asStateFlow
 import kotlinx.coroutines.launch
-import kotlinx.coroutines.withContext
 
 class MainViewModel(): ViewModel() {
 
@@ -135,7 +116,6 @@ class MainViewModel(): ViewModel() {
         }
     }
 
-
     suspend fun getPlaceList() = Constants.supabase.from("place")
         .select()
         .decodeList<Place>()
@@ -144,8 +124,7 @@ class MainViewModel(): ViewModel() {
     fun getPlaceListRealTime() = Constants.supabase.from("Place")
         .selectAsFlow(Place ::id_place)
 
-
-    suspend fun getPlaceById(id: Int) = Constants.supabase.from("place")
+    suspend fun getPlaceById(id: String?) = Constants.supabase.from("place")
         .select(columns = Columns.list("id_place","title","img_place","id_categoryFK","description","address","mapping","author")){
             filter {
                 Place::id_place eq id

+ 8 - 2
app/src/main/java/com/example/iplace/main/viewModel/dataView/MenuV.kt

@@ -53,12 +53,13 @@ import androidx.compose.ui.layout.ContentScale
 import androidx.compose.ui.res.painterResource
 import androidx.navigation.NavHostController
 import coil.compose.AsyncImage
+import com.example.iplace.main.viewModel.AuthData
 import com.example.iplace.model.Place
 
 
 @OptIn(ExperimentalMaterial3Api::class)
 @Composable
-fun MenuV(navController: NavHostController) {
+fun MenuV(navController: NavHostController){
     val viewModel = MainViewModel()
     var showDrawer by remember { mutableStateOf(false) }
 
@@ -260,12 +261,17 @@ fun MenuV(navController: NavHostController) {
 
 @Composable
 fun PlaceCard(place: Place, navController: NavHostController){
+    val viewModel = MainViewModel()
+    val placeId = place.id_place
     Box(
         modifier = Modifier
             .fillMaxWidth()
             .height(300.dp)
             .clip(RoundedCornerShape(20.dp))
-            .clickable(onClick = { navController.navigate("placeV") })
+            .clickable(onClick = {
+
+                navController.navigate("placeV/$placeId")
+            })
         ,
         contentAlignment = Alignment.Center
     ){

+ 5 - 9
app/src/main/java/com/example/iplace/main/viewModel/dataView/PlaceV.kt

@@ -11,13 +11,10 @@ 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.size
 import androidx.compose.foundation.layout.width
-import androidx.compose.foundation.shape.CircleShape
 import androidx.compose.foundation.shape.RoundedCornerShape
 import androidx.compose.material.icons.Icons
 import androidx.compose.material.icons.filled.ArrowBack
-import androidx.compose.material.icons.filled.Settings
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonDefaults
 import androidx.compose.material3.Icon
@@ -29,6 +26,7 @@ import androidx.compose.runtime.LaunchedEffect
 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
@@ -38,7 +36,6 @@ import androidx.compose.ui.res.painterResource
 import androidx.compose.ui.text.font.Font
 import androidx.compose.ui.text.font.FontFamily
 import androidx.compose.ui.text.font.FontWeight
-import androidx.compose.ui.text.style.TextAlign
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
 import androidx.navigation.NavHostController
@@ -49,13 +46,12 @@ import com.example.iplace.model.Place
 import com.example.iplace.ui.theme.brown_contrast
 
 @Composable
-fun PlaceV(navController: NavHostController, PlaceId : Int) {
+fun PlaceV(navController: NavHostController, placeId: String) {
     val viewModel = MainViewModel()
+    var place by remember { mutableStateOf<Place?>(null) }
 
-    val place by remember { mutableStateOf<Place?>(null) }
-
-    LaunchedEffect (key1 = true){
-        viewModel.getPlaceById(id = PlaceId)
+    LaunchedEffect (key1 = placeId) {
+        place = viewModel.getPlaceById(id = placeId)
     }
 
 

+ 5 - 3
app/src/main/java/com/example/iplace/main/viewModel/navigation.kt

@@ -31,7 +31,7 @@ import com.example.iplace.main.viewModel.mainView.UserSettings
 @RequiresApi(Build.VERSION_CODES.O)
 @Composable
 fun Navigation(controller: NavHostController) {
-    var PlaceId by remember { mutableStateOf(0) }
+
     NavHost(
         navController = controller,
         startDestination = View.splashScreen.route
@@ -39,6 +39,7 @@ fun Navigation(controller: NavHostController) {
         composable(View.splashScreen.route){
             SplashScreen(controller)
         }
+
         composable(View.selectEnter.route){
             SelectEnter(controller)
         }
@@ -75,8 +76,9 @@ fun Navigation(controller: NavHostController) {
         composable(View.favouritesV.route){
             FavouritesV(controller)
         }
-        composable(View.placeV.route){
-            PlaceV(controller, PlaceId)
+        composable(View.placeV.route + "/{placeId}") { backStackEntry ->
+            val placeId = backStackEntry.arguments?.getString("placeId") ?: ""
+            PlaceV(controller, placeId)
         }
         composable(View.addPlace.route){
             AddPlace(controller)