소스 검색

сделал вывод всех мест в меню, и добавил логику перехода на нужную страницу с нужным местом при нажатии на место в меню

AlexMin 3 일 전
부모
커밋
42dae9c604

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


+ 7 - 0
app/src/main/java/com/example/iplace/domain/Constants.kt

@@ -1,10 +1,14 @@
+@file:OptIn(SupabaseInternal::class)
+
 package com.example.iplace.domain
 
 
+import io.github.jan.supabase.annotations.SupabaseInternal
 import io.github.jan.supabase.createSupabaseClient
 import io.github.jan.supabase.gotrue.Auth
 import io.github.jan.supabase.postgrest.Postgrest
 import io.github.jan.supabase.realtime.Realtime
+import io.ktor.client.plugins.websocket.WebSockets
 
 object Constants {
     val supabase = createSupabaseClient(
@@ -14,6 +18,9 @@ object Constants {
         install(Auth)
         install(Postgrest)
         install(Realtime)
+        httpConfig {
+            this.install(WebSockets)
+        }
     }
 }
 

+ 27 - 0
app/src/main/java/com/example/iplace/main/viewModel/MainViewModel.kt

@@ -1,3 +1,5 @@
+@file:OptIn(SupabaseExperimental::class)
+
 package com.example.iplace.main.viewModel
 
 import android.content.Context
@@ -21,14 +23,21 @@ 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
 import io.github.jan.supabase.gotrue.auth
 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() {
 
@@ -126,6 +135,24 @@ class MainViewModel(): ViewModel() {
         }
     }
 
+
+    suspend fun getPlaceList() = Constants.supabase.from("place")
+        .select()
+        .decodeList<Place>()
+    private val _place: MutableStateFlow<List<Place>> = MutableStateFlow(listOf())
+
+    fun getPlaceListRealTime() = Constants.supabase.from("Place")
+        .selectAsFlow(Place ::id_place)
+
+
+    suspend fun getPlaceById(id: Int) = 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
+            }
+        }.decodeSingle<Place>()
+
+
 }
 
 

+ 84 - 42
app/src/main/java/com/example/iplace/main/viewModel/dataView/MenuV.kt

@@ -14,18 +14,12 @@ 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.filled.ArrowBack
-import androidx.compose.material.icons.filled.Settings
 import androidx.compose.material3.Button
 import androidx.compose.material3.ButtonDefaults
-import androidx.compose.material3.Card
 import androidx.compose.material3.Icon
 import androidx.compose.material3.IconButton
-import androidx.compose.material3.MaterialTheme
 import androidx.compose.material3.OutlinedTextField
 import androidx.compose.material3.Text
 import androidx.compose.runtime.Composable
@@ -34,22 +28,17 @@ 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.tooling.preview.Preview
 import androidx.compose.ui.unit.dp
 import androidx.compose.ui.unit.sp
-import coil.compose.rememberImagePainter
 import com.example.iplace.R
 import com.example.iplace.main.viewModel.MainViewModel
-import com.example.iplace.ui.theme.beige_white
 import com.example.iplace.ui.theme.brown_contrast
 
-import androidx.compose.foundation.background
 import androidx.compose.foundation.clickable
 import androidx.compose.foundation.layout.*
 import androidx.compose.foundation.lazy.LazyColumn
 import androidx.compose.foundation.lazy.items
 //noinspection UsingMaterialAndMaterial3Libraries
-import androidx.compose.material.*
 import androidx.compose.material.icons.Icons
 import androidx.compose.material.icons.filled.Menu
 import androidx.compose.material.icons.filled.Person
@@ -62,8 +51,9 @@ import androidx.compose.ui.Modifier
 import androidx.compose.ui.graphics.Color
 import androidx.compose.ui.layout.ContentScale
 import androidx.compose.ui.res.painterResource
-import androidx.compose.ui.unit.dp
 import androidx.navigation.NavHostController
+import coil.compose.AsyncImage
+import com.example.iplace.model.Place
 
 
 @OptIn(ExperimentalMaterial3Api::class)
@@ -71,6 +61,16 @@ import androidx.navigation.NavHostController
 fun MenuV(navController: NavHostController) {
     val viewModel = MainViewModel()
     var showDrawer by remember { mutableStateOf(false) }
+
+    var placeList by remember { mutableStateOf<List<Place>>(emptyList()) }
+//    LaunchedEffect(key1 = true) {
+//        viewModel.getPlaceListRealTime()
+//            .collect {list -> placeList = list}
+//    }
+    LaunchedEffect(key1 = true) {
+        placeList = viewModel.getPlaceList()
+    }
+
     val headlinesOswald = FontFamily( //выбор шрифта
         Font(resId = R.font.headlines_oswald)
     )
@@ -240,43 +240,85 @@ fun MenuV(navController: NavHostController) {
                     .fillMaxWidth(),
                 textAlign = TextAlign.Center
             )
+            LazyColumn(
+                contentPadding = PaddingValues(
+                    horizontal = 16.dp,
+                    vertical = 10.dp),
+                verticalArrangement = Arrangement.spacedBy(10.dp)
+            ){
+                items(placeList) {
+                    place ->
+                        PlaceCard(place = place, navController
 
-            // 4 блока данных
-            LazyColumn {
-                items(listOf(1, 2, 3, 4)) { item ->
-                    Box(
-                        modifier = Modifier
-                            .fillMaxWidth()
-                            .height(230.dp)
-                            .padding(16.dp)
-                            .background(Color.LightGray)
-                            .clickable{navController.navigate("placeV")}
-                    ) {
-                        Column(
-                            modifier = Modifier
-                                .align(Alignment.BottomStart) // Выравниваем Column по левому нижнему углу
-                        ) {
-                            Text(text = "Название $item", modifier = Modifier)
-                            Text(text = "Категория $item", modifier = Modifier)
-                        }
-
-                        Button(
-                            onClick = { /* Обработка нажатия на фильтр */ },
-                            modifier = Modifier
-                                .align(Alignment.TopEnd) // Выравниваем Button по правому верхнему углу
-                                .width(40.dp)
-                                .height(40.dp),
-                            colors = ButtonDefaults.buttonColors(brown_contrast)
-                        ) {
-                            Text(text = "☆")
-                        }
-                    }
+                        )
                 }
+
+            }
+        }
+    }
+}
+
+@Composable
+fun PlaceCard(place: Place, navController: NavHostController){
+    Box(
+        modifier = Modifier
+            .fillMaxWidth()
+            .height(300.dp)
+            .clip(RoundedCornerShape(20.dp))
+            .clickable(onClick = { navController.navigate("placeV") })
+        ,
+        contentAlignment = Alignment.Center
+    ){
+
+        AsyncImage(
+            model = place.img_place,
+            contentDescription = null,
+            modifier = Modifier.fillMaxSize(),
+            contentScale = ContentScale.Crop
+        )
+        Box(
+
+            modifier = Modifier
+                .matchParentSize()
+                .background(color = Color.LightGray.copy(alpha = 0.6f))
+        ){
+            Column(
+                modifier = Modifier
+                    .align(Alignment.BottomStart) // Выравниваем Column по левому нижнему углу
+            ) {
+                Text(
+                    text = place.title,
+                    fontSize = 18.sp,
+                    color = Color.Black,
+
+                    )
+                Text(
+                    text = place.id_categoryFK.toString(),
+                    fontSize = 18.sp,
+                    color = Color.Black,
+
+                    )
+            }
+
+            Button(
+                onClick = { /* Обработка нажатия на фильтр */ },
+                modifier = Modifier
+                    .align(Alignment.TopEnd) // Выравниваем Button по правому верхнему углу
+                    .width(40.dp)
+                    .height(40.dp),
+                colors = ButtonDefaults.buttonColors(brown_contrast)
+            ) {
+                Text(text = "☆")
             }
         }
+
+
+
     }
+
 }
 
+
 @Composable
 fun DrawerContent(showDrawer: Boolean, navController: NavHostController) {
     val headlinesOswald = FontFamily( //выбор шрифта

+ 31 - 2
app/src/main/java/com/example/iplace/main/viewModel/dataView/PlaceV.kt

@@ -25,6 +25,10 @@ import androidx.compose.material3.IconButton
 import androidx.compose.material3.OutlinedTextField
 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
@@ -36,15 +40,25 @@ 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
+import coil.compose.AsyncImage
 import com.example.iplace.R
 import com.example.iplace.main.viewModel.MainViewModel
+import com.example.iplace.model.Place
 import com.example.iplace.ui.theme.brown_contrast
 
 @Composable
-fun PlaceV(navController: NavHostController) {
+fun PlaceV(navController: NavHostController, PlaceId : Int) {
     val viewModel = MainViewModel()
 
+    val place by remember { mutableStateOf<Place?>(null) }
+
+    LaunchedEffect (key1 = true){
+        viewModel.getPlaceById(id = PlaceId)
+    }
+
+
     val headlinesOswald = FontFamily( //выбор шрифта
         Font(resId = R.font.headlines_oswald)
     )
@@ -69,6 +83,12 @@ fun PlaceV(navController: NavHostController) {
                 .background(Color.LightGray.copy(alpha = 0.6f))
                 .padding(16.dp)
         ) {
+            AsyncImage(
+                model = place?.img_place,
+                contentDescription = null,
+                modifier = Modifier.fillMaxSize(),
+                contentScale = ContentScale.Crop
+            )
             // Кнопки назад и автора
             Row(
                 modifier = Modifier
@@ -94,7 +114,16 @@ fun PlaceV(navController: NavHostController) {
                     .align(Alignment.BottomStart) // Выравнивание по левому нижнему углу
                     .padding(16.dp) // Отступ от краев
             ) {
-                Text(text = "Название")
+                Text(
+                    text = place?.title ?:"",
+                    fontWeight = FontWeight.Bold,
+                    fontSize = 32.sp
+                )
+                Text(
+                    text = place?.id_categoryFK.toString() ?:"",
+                    fontWeight = FontWeight.Bold,
+                    fontSize = 18.sp
+                )
                 Spacer(modifier = Modifier.height(8.dp)) // Отступ между текстами
                 Text(text = "Категория")
             }

+ 7 - 1
app/src/main/java/com/example/iplace/main/viewModel/navigation.kt

@@ -3,9 +3,14 @@ package com.example.iplace.main.viewModel
 import android.os.Build
 import androidx.annotation.RequiresApi
 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.navigation.NavHostController
 import androidx.navigation.compose.NavHost
 import androidx.navigation.compose.composable
+import androidx.navigation.compose.rememberNavController
 import com.example.iplace.main.viewModel.dataView.FavouritesV
 import com.example.iplace.main.viewModel.dataView.MenuV
 import com.example.iplace.main.viewModel.dataView.PlaceV
@@ -26,6 +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
@@ -70,7 +76,7 @@ fun Navigation(controller: NavHostController) {
             FavouritesV(controller)
         }
         composable(View.placeV.route){
-            PlaceV(controller)
+            PlaceV(controller, PlaceId)
         }
         composable(View.addPlace.route){
             AddPlace(controller)