From f151ccd599b01fa9ff49e993fba5cbcd3a25f040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B0=D1=88=D0=B8=D0=BD=20=D0=9C=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D0=BC?= Date: Fri, 27 Oct 2023 00:44:20 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D1=87?= =?UTF-8?q?=D1=82=D0=BE=20=D1=82=D0=BE=20=D1=82=D0=B8=D0=BF=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=BE=D1=80=D0=BC=D0=B0=D0=BB=D1=8C=D0=BD=D0=BE=20=D1=81=D0=BF?= =?UTF-8?q?=D0=B8=D1=81=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../labwork/button_navigation/Screens.kt | 33 +++++++++++++++---- .../com/example/labwork/pages/ItemProduct.kt | 7 ++++ .../com/example/labwork/pages/ListProduct.kt | 8 ++--- 3 files changed, 37 insertions(+), 11 deletions(-) create mode 100644 app/src/main/java/com/example/labwork/pages/ItemProduct.kt diff --git a/app/src/main/java/com/example/labwork/button_navigation/Screens.kt b/app/src/main/java/com/example/labwork/button_navigation/Screens.kt index afe2a67..b54b300 100644 --- a/app/src/main/java/com/example/labwork/button_navigation/Screens.kt +++ b/app/src/main/java/com/example/labwork/button_navigation/Screens.kt @@ -6,6 +6,7 @@ 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.fillMaxHeight import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding @@ -13,6 +14,8 @@ import androidx.compose.foundation.layout.requiredHeight import androidx.compose.foundation.layout.requiredSize import androidx.compose.foundation.layout.requiredWidth import androidx.compose.foundation.layout.wrapContentHeight +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.material.Text import androidx.compose.runtime.Composable @@ -29,6 +32,7 @@ import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.em import androidx.compose.ui.unit.sp import com.example.labwork.R +import com.example.labwork.pages.ItemProduct import com.example.labwork.pages.ListProduct @Composable @@ -54,13 +58,28 @@ fun ScreenProfile() { @Composable fun ScreenListProduct() { - Column { - ListProduct("Максим", "Тест") - ListProduct("Максим", "Тест") - ListProduct("Максим", "Тест") - ListProduct("Максим", "Тест") - ListProduct("Максим", "Тест") - ListProduct("Максим", "Тест") + LazyColumn( + modifier = Modifier.fillMaxHeight() + ) { + itemsIndexed( + listOf( + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка"), + ItemProduct(R.drawable.baseline_menu_book,"Золотая рыбка","Сказка") + ) + ) + { + _, item -> + ListProduct(item = item) + } } } diff --git a/app/src/main/java/com/example/labwork/pages/ItemProduct.kt b/app/src/main/java/com/example/labwork/pages/ItemProduct.kt new file mode 100644 index 0000000..028c9eb --- /dev/null +++ b/app/src/main/java/com/example/labwork/pages/ItemProduct.kt @@ -0,0 +1,7 @@ +package com.example.labwork.pages + +data class ItemProduct( + val imageId: Int, + val name: String, + val about: String +) diff --git a/app/src/main/java/com/example/labwork/pages/ListProduct.kt b/app/src/main/java/com/example/labwork/pages/ListProduct.kt index 165df3f..b1e5cd7 100644 --- a/app/src/main/java/com/example/labwork/pages/ListProduct.kt +++ b/app/src/main/java/com/example/labwork/pages/ListProduct.kt @@ -22,7 +22,7 @@ import androidx.compose.ui.unit.dp import com.example.labwork.R @Composable -fun ListProduct(name: String, about: String) { +fun ListProduct(item: ItemProduct) { Card(modifier = Modifier .fillMaxWidth() .padding(10.dp), @@ -31,7 +31,7 @@ fun ListProduct(name: String, about: String) { ) { Box { Row(verticalAlignment = Alignment.CenterVertically) { - Image(painter = painterResource(id = R.drawable.baseline_menu_book), + Image(painter = painterResource(id = item.imageId), contentDescription = "book", contentScale = ContentScale.Crop, modifier = Modifier @@ -40,8 +40,8 @@ fun ListProduct(name: String, about: String) { .shadow(2.dp) ) Column { - Text(text = name) - Text(text = about) + Text(text = item.name) + Text(text = item.about) } } }