소스 검색

App: вывод данных

ПроваленкоЛН 5 일 전
부모
커밋
56d8c774b8

+ 1 - 1
OscellaMobile/.idea/deploymentTargetSelector.xml

@@ -2,7 +2,7 @@
 <project version="4">
   <component name="deploymentTargetSelector">
     <selectionStates>
-      <SelectionState runConfigName="Unnamed">
+      <SelectionState runConfigName="app">
         <option name="selectionMode" value="DROPDOWN" />
       </SelectionState>
     </selectionStates>

+ 9 - 0
OscellaMobile/app/src/main/java/com/example/oscellamobile/models/Age_rating.kt

@@ -0,0 +1,9 @@
+package com.example.oscellamobile.models
+
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class Age_rating(
+    var id: Int,
+    var rating: String
+)

+ 9 - 0
OscellaMobile/app/src/main/java/com/example/oscellamobile/models/Basic_labels.kt

@@ -0,0 +1,9 @@
+package com.example.oscellamobile.models
+
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class Basic_labels(
+    var id_game: Int,
+    var id_label: Int,
+)

+ 2 - 1
OscellaMobile/app/src/main/java/com/example/oscellamobile/models/Game.kt

@@ -14,5 +14,6 @@ data class Game(
     val age_rating: Int?,
     val link_torrent: String?,
     val link_oficial: String?,
-    val short_description: String
+    val short_description: String,
+    val genre: Int
 )

+ 9 - 0
OscellaMobile/app/src/main/java/com/example/oscellamobile/models/Label.kt

@@ -0,0 +1,9 @@
+package com.example.oscellamobile.models
+
+import kotlinx.serialization.Serializable
+
+@Serializable
+data class Label(
+    var id: Int,
+    var label_name: String
+)

+ 116 - 128
OscellaMobile/app/src/main/java/com/example/oscellamobile/screens/MainWindow.kt

@@ -38,6 +38,7 @@ 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.draw.shadow
 import androidx.compose.ui.geometry.Offset
 import androidx.compose.ui.graphics.Brush
@@ -71,6 +72,9 @@ import coil.compose.AsyncImagePainter
 import coil.compose.rememberAsyncImagePainter
 import coil.request.ImageRequest
 import coil.size.Size
+import com.example.oscellamobile.models.Age_rating
+import com.example.oscellamobile.models.Basic_labels
+import com.example.oscellamobile.models.Label
 import org.intellij.lang.annotations.JdkConstants
 
 
@@ -101,12 +105,18 @@ fun MainWindow(navController: NavHostController) {
 
     var games by remember { mutableStateOf<List<Game>>(listOf()) }
     var сompany by remember { mutableStateOf<List<Company>>(listOf()) }
+    var labels by remember{ mutableStateOf<List<Label>>(listOf()) }
+    var basiclabels by remember{ mutableStateOf<List<Basic_labels>>(listOf()) }
+    var age by remember{ mutableStateOf<List<Age_rating>>(listOf()) }
 
     LaunchedEffect(Unit) {
         withContext(Dispatchers.IO) {
             try {
                 сompany = Constant.supabase.from("Company").select().decodeList<Company>()
                 games = Constant.supabase.from("Game").select().decodeList<Game>()
+                labels = Constant.supabase.from("Label").select().decodeList<Label>()
+                basiclabels = Constant.supabase.from("Basic_labels").select().decodeList<Basic_labels>()
+                age = Constant.supabase.from("Age_rating").select().decodeList<Age_rating>()
                 games.forEach { Game ->
                     Log.d("C", Game.name_game)
                 }
@@ -245,10 +255,13 @@ fun MainWindow(navController: NavHostController) {
             items(
                 games,
                 key = { Game -> Game.id },
-            ) { film ->
+            ) { Game ->
                 GameItem(
-                    game = film,
-                    company = сompany
+                    game = Game,
+                    company = сompany,
+                    label = labels,
+                    basic = basiclabels,
+                    age = age
                 )
             }
         }
@@ -259,84 +272,56 @@ fun MainWindow(navController: NavHostController) {
     fun GameItem(
         game: Game,
         company: List<Company>,
+        label: List<Label>,
+        basic: List<Basic_labels>,
+        age: List<Age_rating>
     ) {
     val imageState = rememberAsyncImagePainter(
         model = ImageRequest.Builder(LocalContext.current).data(game.picture)
             .size(Size.ORIGINAL).build()
     ).state
 
-        Card(
-            modifier = Modifier
-                .padding(20.dp, 10.dp)
-                .background(color = Color(0xFFFDFFFC), shape = RoundedCornerShape(15.dp)),
-        ) {
-            Row {
-                Spacer(Modifier.width(10.dp))
-                Column {
-                    val companyId = game.company
-                    val companyy = company.find { it.id == companyId }
-                    if (company != null) {
-                        Text(
-                            "${companyy?.name_company}",
-                            fontSize = 20.sp,
-                            fontFamily = kdamFontFamily,
-                            color = Color(0xFF2EC4B6)
-                        )
+    Card(
+        modifier = Modifier
+            .padding(20.dp, 10.dp)
+            .background(color = Color(0xFFFDFFFC), shape = RoundedCornerShape(15.dp)),
+    ) {
+        Row {
+            Spacer(Modifier.width(10.dp))
+            Column {
+                val companyId = game.company
+                val companyy = company.find { it.id == companyId }
+                if (company != null) {
+                    Text(
+                        "${companyy?.name_company}",
+                        fontSize = 20.sp,
+                        fontFamily = kdamFontFamily,
+                        color = Color(0xFF2EC4B6)
+                    )
+                    Text(
+                        text = "Фэнтези",
+                        fontSize = 12.sp,
+                        fontFamily = kdamFontFamily,
+                        color = Color(0xFFE71D36)
+                    )
+                    Spacer(Modifier.width(20.dp))
+                    Column {
                         Text(
-                            text = "Фэнтези",
-                            fontSize = 12.sp,
+                            text = "Основные метки:",
+                            fontSize = 14.sp,
                             fontFamily = kdamFontFamily,
-                            color = Color(0xFFE71D36)
+                            color = Color(0xFF7F807E)
                         )
-                        Spacer(Modifier.width(20.dp))
-                        Column {
-                            Text(
-                                text = "Основные метки:",
-                                fontSize = 14.sp,
-                                fontFamily = kdamFontFamily,
-                                color = Color(0xFF7F807E)
-                            )
-                            Column(
-                                Modifier.padding(10.dp)
-                            ) {
-                                Box(
-                                    modifier = Modifier
-                                        .width(107.dp)
-                                        .height(22.dp)
-                                        .background(
-                                            color = Color(0xFF2EC4B6),
-                                            shape = RoundedCornerShape(20.dp)
-                                        ),
-                                    contentAlignment = Alignment.Center
-                                )
-                                {
-                                    Text(
-                                        text = "Пошаговая",
-                                        color = Color(0xFFFDFFFC),
-                                        fontFamily = caveat,
-                                        fontSize = 20.sp
-                                    )
-                                }
-                                Spacer(Modifier.height(7.dp))
-                                Box(
-                                    modifier = Modifier
-                                        .width(107.dp)
-                                        .height(22.dp)
-                                        .background(
-                                            color = Color(0xFF2EC4B6),
-                                            shape = RoundedCornerShape(20.dp)
-                                        ),
-                                    contentAlignment = Alignment.Center
-                                )
-                                {
-                                    Text(
-                                        text = "Ролевая",
-                                        color = Color(0xFFFDFFFC),
-                                        fontFamily = caveat,
-                                        fontSize = 20.sp
-                                    )
-                                }
-                                Spacer(Modifier.height(7.dp))
+                        Column(
+                        ) {
+                            val GameID = game.id
+                            val labelsForGame = basic.filter { it.id_game == GameID }
+                            val labelIds = labelsForGame.map { it.id_label }
+                            val labels = labelIds.mapNotNull { id ->
+                                label.find { it.id == id }
+                            }
+                            for (label in labels) {
+                                Spacer(modifier = Modifier.padding(7.dp))
                                 Box(
                                     modifier = Modifier
                                         .width(107.dp)
@@ -349,7 +334,7 @@ fun MainWindow(navController: NavHostController) {
                                 )
                                 {
                                     Text(
-                                        text = "Стратегия",
+                                        "${label.label_name}",
                                         color = Color(0xFFFDFFFC),
                                         fontFamily = caveat,
                                         fontSize = 20.sp
@@ -359,77 +344,80 @@ fun MainWindow(navController: NavHostController) {
                         }
                     }
                 }
-                Column {
-                    Row {
-                        Spacer(Modifier.width(45.dp))
-                        Box(
-                            modifier = Modifier
-                                .width(130.dp)
-                                .height(30.dp)
-                                .border(
-                                    BorderStroke(2.dp, Color(0x80B0B0B0)),
-                                    shape = RoundedCornerShape(15.dp)
-                                )
-                        )
-                        {
-                            Text(
-                                text = if (game.favourites == null) {
-                                    "Избранное: 0"
-                                } else {
-                                    "Избранное: ${game.favourites}"
-                                },
-                                fontSize = 16.sp,
-                                fontFamily = playfairdisplay,
-                                color = Color(0xFFFF9F1C),
-                                modifier = Modifier.align(Alignment.Center)
+            }
+            Column {
+                Row {
+                    Spacer(Modifier.width(45.dp))
+                    Box(
+                        modifier = Modifier
+                            .width(130.dp)
+                            .height(30.dp)
+                            .border(
+                                BorderStroke(2.dp, Color(0x80B0B0B0)),
+                                shape = RoundedCornerShape(15.dp)
                             )
-                        }
-                        val size = 31.dp
+                    )
+                    {
+                        Text(
+                            text = if (game.favourites == null) {
+                                "Избранное: 0"
+                            } else {
+                                "Избранное: ${game.favourites}"
+                            },
+                            fontSize = 16.sp,
+                            fontFamily = playfairdisplay,
+                            color = Color(0xFFFF9F1C),
+                            modifier = Modifier.align(Alignment.Center)
+                        )
+                    }
+                    val size = 31.dp
 
-                        var isOrange by remember { mutableStateOf(false) }
+                    var isOrange by remember { mutableStateOf(false) }
 
-                        val buttonColor = if (isOrange) Color(0xFFFF9F1C) else Color.Gray
+                    val buttonColor = if (isOrange) Color(0xFFFF9F1C) else Color.Gray
 
-                        Canvas(
-                            modifier = Modifier
-                                .size(30.dp)
-                                .clickable(onClick = { isOrange = !isOrange })
-                        ) {
-                            drawStar(
-                                center = center,
-                                radius = size.toPx() / 2,
-                                color = buttonColor
-                            )
-                        }
-                    }
-                    Row(
-                        modifier = Modifier.fillMaxWidth(),
-                        horizontalArrangement = Arrangement.Center,
-                        verticalAlignment = Alignment.CenterVertically
+                    Canvas(
+                        modifier = Modifier
+                            .size(30.dp)
+                            .clickable(onClick = { isOrange = !isOrange })
                     ) {
-                        Text(
-                            game.name_game,
-                            fontSize = 20.sp,
-                            fontFamily = kdamFontFamily,
-                            color = Color(0xFF7F807E),
+                        drawStar(
+                            center = center,
+                            radius = size.toPx() / 2,
+                            color = buttonColor
                         )
-                        Spacer(Modifier.width(10.dp))
+                    }
+                }
+                Row(
+                    modifier = Modifier.fillMaxWidth(),
+                    horizontalArrangement = Arrangement.Center,
+                    verticalAlignment = Alignment.CenterVertically
+                ) {
+                    Text(
+                        game.name_game,
+                        fontSize = 20.sp,
+                        fontFamily = kdamFontFamily,
+                        color = Color(0xFF7F807E),
+                    )
+                    Spacer(Modifier.width(10.dp))
+                    val AgeId = game.age_rating
+                    val agee = age.find { it.id == AgeId }
+                    if (agee != null) {
                         Text(
-                            text = "16+",
+                            agee.rating,
                             fontSize = 20.sp,
                             fontFamily = kdamFontFamily,
                             color = Color(0xFFE71D36),
                         )
                     }
+                }
                     if (imageState is AsyncImagePainter.State.Success) {
-                        {
-                        }
                         Image(
                             painter = imageState.painter,
                             contentDescription = "Описание изображения",
                             modifier = Modifier
-                                .width(300.dp)
-                                .height(138.dp)
+                                .width(280.dp)
+                                .clip(RoundedCornerShape(20.dp))
                         )
                     }
                 }
@@ -523,4 +511,4 @@ fun DrawScope.drawStar(center: Offset, radius: Float, color: Color) {
     }
     path.close()
     drawPath(path, color)
-}
+}

+ 1 - 1
OscellaMobile/gradle/libs.versions.toml

@@ -1,6 +1,6 @@
 [versions]
 accompanistSystemuicontroller = "0.36.0"
-agp = "8.6.0"
+agp = "8.5.1"
 bom = "VERSION"
 bomVersion = "2.0"
 coilComposeVersion = "2.4.0"