287 lines
9.0 KiB
Kotlin
287 lines
9.0 KiB
Kotlin
package com.example.libary
|
|
|
|
import androidx.compose.foundation.BorderStroke
|
|
import androidx.compose.foundation.Image
|
|
import androidx.compose.foundation.background
|
|
import androidx.compose.foundation.clickable
|
|
import androidx.compose.foundation.layout.Arrangement
|
|
import androidx.compose.foundation.layout.Box
|
|
import androidx.compose.foundation.layout.Column
|
|
import androidx.compose.foundation.layout.ColumnScope
|
|
import androidx.compose.foundation.layout.Row
|
|
import androidx.compose.foundation.layout.Spacer
|
|
import androidx.compose.foundation.layout.fillMaxWidth
|
|
import androidx.compose.foundation.layout.height
|
|
import androidx.compose.foundation.layout.padding
|
|
import androidx.compose.foundation.layout.width
|
|
import androidx.compose.foundation.shape.AbsoluteRoundedCornerShape
|
|
import androidx.compose.material3.Card
|
|
import androidx.compose.material3.CardDefaults
|
|
import androidx.compose.material3.Text
|
|
import androidx.compose.material3.VerticalDivider
|
|
import androidx.compose.runtime.Composable
|
|
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.res.painterResource
|
|
import androidx.compose.ui.text.font.FontWeight
|
|
import androidx.compose.ui.tooling.preview.Preview
|
|
import androidx.compose.ui.unit.dp
|
|
import androidx.compose.ui.unit.sp
|
|
import com.example.libary.theme.Black1Color
|
|
import com.example.libary.theme.CaptionColor
|
|
import com.example.libary.theme.CartShadowColor
|
|
import com.example.libary.theme.DividerColor
|
|
import com.example.libary.theme.InputBGColor
|
|
import com.example.libary.theme.White1Color
|
|
|
|
// базовая карта
|
|
// modifier - модификаторы
|
|
// content - контент который будет внктри карточки
|
|
@Composable
|
|
fun BaseCard(
|
|
modifier: Modifier = Modifier,
|
|
content: @Composable ColumnScope.() -> Unit
|
|
) {
|
|
Card(
|
|
modifier = modifier
|
|
.shadow(10.dp, AbsoluteRoundedCornerShape(12.dp),
|
|
ambientColor = CartShadowColor, spotColor = CartShadowColor
|
|
),
|
|
shape = AbsoluteRoundedCornerShape(12.dp),
|
|
colors = CardDefaults.cardColors(
|
|
containerColor = White1Color
|
|
),
|
|
border = BorderStroke(1.dp, DividerColor)
|
|
) {
|
|
Column(
|
|
modifier = Modifier.padding(16.dp)
|
|
) {
|
|
content()
|
|
}
|
|
}
|
|
}
|
|
|
|
// карточка продукции
|
|
// modifier - модификаторы
|
|
// name - название продукции
|
|
// category - категория продукции
|
|
// price - цена продукуии
|
|
// isAdd - если равен true тогда отображаеться кнопка "Добавить" иначе "Убрать"
|
|
// onClick - вызываеться при нажатии на кнопку Добавить" или "Убрать"
|
|
@Composable
|
|
fun PrimaryCard(
|
|
modifier: Modifier = Modifier,
|
|
name: String,
|
|
category: String,
|
|
price: String,
|
|
isAdd: Boolean,
|
|
onClick: () -> Unit = {}
|
|
) {
|
|
BaseCard(
|
|
modifier = modifier
|
|
) {
|
|
Text(
|
|
text = name,
|
|
color = Black1Color,
|
|
fontWeight = FontWeight.W500,
|
|
fontSize = 16.sp
|
|
)
|
|
|
|
Spacer(Modifier.height(16.dp))
|
|
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
horizontalArrangement = Arrangement.SpaceBetween,
|
|
verticalAlignment = Alignment.CenterVertically
|
|
) {
|
|
Column {
|
|
Text(
|
|
text = category,
|
|
color = CaptionColor,
|
|
fontWeight = FontWeight.W600,
|
|
fontSize = 14.sp
|
|
)
|
|
|
|
Spacer(Modifier.height(4.dp))
|
|
|
|
Text(
|
|
text = "$price ₽",
|
|
color = Black1Color,
|
|
fontWeight = FontWeight.W600,
|
|
fontSize = 17.sp
|
|
)
|
|
}
|
|
|
|
SmallButton(
|
|
state = if (isAdd) SmallButtonState.Property else SmallButtonState.Secondary,
|
|
text = if (isAdd) "Добавить" else "Убрать",
|
|
onClick = onClick
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
// карточка продукции для корзины
|
|
// modifier - модификаторы
|
|
// name - название продукции
|
|
// price - цена продукуии
|
|
// count - количество продукции в корине
|
|
// onClose - вызываеться при нажатии на крестик
|
|
// onPlus - вызываеться при нажатии на плюс
|
|
// onMinus - вызываеться при нажатии на минус
|
|
@Composable
|
|
fun CartCard(
|
|
modifier: Modifier = Modifier,
|
|
name: String,
|
|
price: String,
|
|
count: String,
|
|
onClose: () -> Unit = {},
|
|
onPlus: () -> Unit = {},
|
|
onMinus: () -> Unit = {}
|
|
) {
|
|
BaseCard(
|
|
modifier = modifier
|
|
) {
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
horizontalArrangement = Arrangement.SpaceBetween
|
|
) {
|
|
Text(
|
|
text = name,
|
|
fontWeight = FontWeight.W500,
|
|
fontSize = 16.sp,
|
|
color = Black1Color,
|
|
modifier = Modifier.weight(1.0f)
|
|
)
|
|
|
|
Image(
|
|
painter = painterResource(R.drawable.delete),
|
|
contentDescription = null,
|
|
modifier = Modifier.clickable {
|
|
onClose()
|
|
}
|
|
)
|
|
}
|
|
|
|
Spacer(Modifier.height(34.dp))
|
|
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
horizontalArrangement = Arrangement.SpaceBetween,
|
|
verticalAlignment = Alignment.CenterVertically
|
|
) {
|
|
Text(
|
|
text = "$price ₽",
|
|
color = Black1Color,
|
|
fontWeight = FontWeight.W500,
|
|
fontSize = 17.sp
|
|
)
|
|
|
|
Row(
|
|
verticalAlignment = Alignment.CenterVertically
|
|
) {
|
|
Text(
|
|
text = "$count штук",
|
|
fontWeight = FontWeight.W400,
|
|
fontSize = 15.sp,
|
|
color = Black1Color
|
|
)
|
|
|
|
Spacer(Modifier.width(42.dp))
|
|
|
|
Box(
|
|
modifier = Modifier
|
|
.width(64.dp)
|
|
.height(32.dp)
|
|
.background(InputBGColor, AbsoluteRoundedCornerShape(8.dp))
|
|
.clip(AbsoluteRoundedCornerShape(8.dp)),
|
|
contentAlignment = Alignment.Center
|
|
) {
|
|
Row(
|
|
modifier = Modifier.padding(6.dp)
|
|
) {
|
|
Image(
|
|
painter = painterResource(R.drawable.minus),
|
|
contentDescription = null,
|
|
modifier = Modifier.clickable {
|
|
onMinus()
|
|
}
|
|
)
|
|
|
|
Spacer(Modifier.width(6.dp))
|
|
|
|
VerticalDivider()
|
|
|
|
Spacer(Modifier.width(6.dp))
|
|
|
|
Image(
|
|
painter = painterResource(R.drawable.plus),
|
|
contentDescription = null,
|
|
modifier = Modifier.clickable {
|
|
onPlus()
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// карточка проекта
|
|
// modifier - модификаторы
|
|
// name - название проекта
|
|
// date - дата проекта
|
|
// open - вызываеться при нажатии на кнопку "Открыть"
|
|
@Composable
|
|
fun ProjectCard(
|
|
modifier: Modifier = Modifier,
|
|
name: String,
|
|
date: String,
|
|
open: () -> Unit = {}
|
|
) {
|
|
BaseCard(
|
|
modifier = modifier,
|
|
content = {
|
|
Text(
|
|
text = name,
|
|
fontWeight = FontWeight.W500,
|
|
fontSize = 16.sp,
|
|
color = Black1Color
|
|
)
|
|
|
|
Spacer(Modifier.height(44.dp))
|
|
|
|
Row(
|
|
modifier = Modifier.fillMaxWidth(),
|
|
horizontalArrangement = Arrangement.SpaceBetween,
|
|
verticalAlignment = Alignment.CenterVertically
|
|
) {
|
|
Text(
|
|
text = date,
|
|
color = CaptionColor,
|
|
fontWeight = FontWeight.W600,
|
|
fontSize = 14.sp
|
|
)
|
|
|
|
SmallButton(
|
|
state = SmallButtonState.Property,
|
|
text = "Открыть",
|
|
onClick = open
|
|
)
|
|
}
|
|
}
|
|
)
|
|
}
|
|
|
|
@Preview
|
|
@Composable
|
|
private fun PrimaryCardPrev() {
|
|
ProjectCard(
|
|
modifier = Modifier.padding(horizontal = 20.dp),
|
|
name = "Рубашка Воскресенье для машинного вязания",
|
|
date = "Прошло 2 дня"
|
|
)
|
|
} |