This commit is contained in:
movavi 2023-12-22 05:21:24 +03:00
parent 41e2ff3ce6
commit 9b89031eba
11 changed files with 273 additions and 251 deletions

3
.idea/.gitignore vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -2,6 +2,22 @@
<project version="4">
<component name="deploymentTargetDropDown">
<value>
<entry key="MainActivity">
<State>
<runningDeviceTargetSelectedWithDropDown>
<Target>
<type value="RUNNING_DEVICE_TARGET" />
<deviceKey>
<Key>
<type value="SERIAL_NUMBER" />
<value value="192.168.0.108:5555" />
</Key>
</deviceKey>
</Target>
</runningDeviceTargetSelectedWithDropDown>
<timeTargetWasSelectedWithDropDown value="2023-12-22T01:40:07.771334500Z" />
</State>
</entry>
<entry key="app">
<State />
</entry>

View File

@ -58,13 +58,13 @@ dependencies {
implementation("io.coil-kt:coil-compose:2.5.0")
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2")
implementation("androidx.activity:activity-compose:1.8.0") // Обновлено до 1.9.0
implementation("androidx.activity:activity-compose:1.8.2") // Обновлено до 1.9.0
implementation(platform("androidx.compose:compose-bom:2023.10.01"))
implementation("androidx.navigation:navigation-compose:2.7.4")
implementation("androidx.navigation:navigation-compose:2.7.6")
implementation("androidx.compose.ui:ui")
implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview")
implementation("androidx.compose.material:material:1.4.3") // Замена material3
implementation("androidx.compose.material:material:1.5.4") // Замена material3
implementation("androidx.compose.material3:material3:1.1.2")
implementation("com.google.android.engage:engage-core:1.3.1")
implementation("androidx.appcompat:appcompat:1.6.1")
@ -83,9 +83,9 @@ dependencies {
// Retrofit
val retrofitVersion = "2.9.0"
implementation("com.squareup.retrofit2:retrofit:$retrofitVersion")
implementation("com.squareup.okhttp3:logging-interceptor:4.11.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
implementation("androidx.paging:paging-compose:3.2.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.2")
implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0")
}

View File

@ -132,7 +132,7 @@ interface MyServerService {
)
companion object {
private const val BASE_URL = "http://10.0.2.2:8079/"
private const val BASE_URL = "http://192.168.0.102:8079/"
@Volatile
private var INSTANCE: MyServerService? = null

View File

@ -102,7 +102,7 @@ fun BouquetCatalog(
@Composable
fun BouquetCard(bouquet: Bouquet) {
var heart by remember { mutableStateOf(FavoriteModel.containsBouquet(bouquet)) }
var heart by remember { mutableStateOf(FavoriteModel.instance.containsBouquet(bouquet)) }
var cart by remember { mutableStateOf(CartModel.containsBouquet(bouquet)) }
Card(
modifier = Modifier
@ -125,7 +125,7 @@ fun BouquetCard(bouquet: Bouquet) {
bitmap = imageBitmap,
contentDescription = null,
modifier = Modifier
.height(180.dp)
.height(190.dp)
.clip(shape = RoundedCornerShape(10.dp)),
contentScale = ContentScale.Crop
)
@ -160,7 +160,7 @@ fun BouquetCard(bouquet: Bouquet) {
.size(30.dp)
.clip(shape = RoundedCornerShape(5.dp))
.clickable {
heart = FavoriteModel.addBouquet(bouquet)
heart = FavoriteModel.instance.addBouquet(bouquet)
}
)
}
@ -172,7 +172,7 @@ fun BouquetCard(bouquet: Bouquet) {
//Spacer(modifier = Modifier.height(8.dp))
Text(text = "${bouquet.price}", fontFamily = FontFamily.Serif, fontSize = 15.sp)
Spacer(modifier = Modifier.height(5.dp))
Row(horizontalArrangement = Arrangement.Center) {
Row(horizontalArrangement = Arrangement.Center, verticalAlignment = Alignment.Bottom) {
Button(modifier = Modifier
.fillMaxWidth(),
shape = RoundedCornerShape(bottomEnd = 10.dp, bottomStart = 10.dp), onClick = { },
@ -181,14 +181,6 @@ fun BouquetCard(bouquet: Bouquet) {
)) {
Text("Купить")
}
// Spacer(modifier = Modifier.width(8.dp))
// Button(modifier = Modifier
// .width(115.dp), shape = RoundedCornerShape(8.dp), onClick = { CartModel.addBouquet(bouquet) },
// colors = ButtonDefaults.buttonColors(
// containerColor = colorResource(id = R.color.button)
// )) {
// Text("В корзину")
// }
}
}
}

View File

@ -26,6 +26,7 @@ import androidx.compose.material3.Icon
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
@ -44,6 +45,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavController
import com.example.flowershopapp.Entities.Model.Bouquet
import com.example.flowershopapp.Entities.Model.CartModel
@ -52,14 +54,16 @@ import com.example.flowershopapp.R
@Composable
fun Favorite(navController: NavController) {
val bouquets = remember { mutableStateOf<List<Bouquet>>(emptyList()) }
val favoriteModel: FavoriteModel = viewModel()
//val bouquets = remember { mutableStateOf<List<Bouquet>>(emptyList()) }
val bouquets by FavoriteModel.instance.bouquets.collectAsState()
LaunchedEffect(CartModel.bouquets) {
snapshotFlow { CartModel.bouquets.value }
.collect { list ->
bouquets.value = list!!
}
}
// LaunchedEffect(FavoriteModel.instance.bouquets) {
// snapshotFlow { FavoriteModel.bouquets.value }
// .collect { list ->
// bouquets.value = list!!
// }
// }
// val removeBouquet: (List<Bouquet>) -> Unit = { bouquetsNew ->
// bouquets = bouquetsNew
@ -70,7 +74,7 @@ fun Favorite(navController: NavController) {
columns = GridCells.Fixed(2),
modifier = Modifier.fillMaxSize(),
) {
items(items = bouquets.value, key = { it.hashCode() }) { bouquet->
items(bouquets) { bouquet->
//bouquets.chunked(2).forEach { bouquetPair ->
//LazyRow(modifier = Modifier
//.padding(top = 20.dp, bottom = 20.dp)
@ -90,90 +94,90 @@ fun Favorite(navController: NavController) {
}
@Composable
fun BouquetCardUpgrade(bouquet: Bouquet, onRemove: (List<Bouquet>) -> Unit) {
var heart by remember { mutableStateOf(FavoriteModel.containsBouquet(bouquet)) }
var expandedName by remember { mutableStateOf(false) }
Card(
elevation = CardDefaults.cardElevation(
defaultElevation = 10.dp
),
colors = CardDefaults.cardColors(
containerColor = Color.White
)
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Box(contentAlignment = Alignment.TopEnd) {
if (bouquet.image != null) {
val decodedBitmap =
BitmapFactory.decodeByteArray(bouquet.image, 0, bouquet.image!!.size)
val imageBitmap = decodedBitmap.asImageBitmap()
Image(
bitmap = imageBitmap,
contentDescription = null,
modifier = Modifier
.width(180.dp)
.height(180.dp)
.clip(shape = RoundedCornerShape(10.dp)),
contentScale = ContentScale.Crop
)
}
Box(Modifier.clip(RoundedCornerShape(10.dp)).clickable { }) {
Icon(
painter = painterResource(id = heart),
contentDescription = null,
modifier = Modifier
.size(40.dp)
.clip(shape = RoundedCornerShape(10.dp))
.clickable {
//onRemove(FavoriteModel.removeBouquets(bouquet))
heart = R.drawable.heart_black
}
)
}
}
Spacer(modifier = Modifier.height(8.dp))
if (expandedName) {
AlertDialog(
onDismissRequest = { expandedName = false },
title = {
Text(text = bouquet.name, fontFamily = FontFamily.Serif, fontSize = 25.sp)
},
confirmButton = {
Button(
onClick = { expandedName = false }
) {
Text("Закрыть")
}
}
)
}
Text(text = bouquet.name,
fontFamily = FontFamily.Serif,
fontSize = 20.sp,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier
.padding(start = 5.dp, end = 5.dp)
.clickable { expandedName = true })
//Spacer(modifier = Modifier.height(1.dp))
Text(text = "${bouquet.quantityOfFlowers} цветов", fontFamily = FontFamily.Serif, fontSize = 19.sp)
//Spacer(modifier = Modifier.height(8.dp))
Text(text = "${bouquet.price}", fontFamily = FontFamily.Serif, fontSize = 19.sp)
Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
Button(modifier = Modifier.width(115.dp), shape = RoundedCornerShape(5.dp), onClick = { },
colors = ButtonDefaults.buttonColors(
containerColor = colorResource(id = R.color.button)
)) {
Text("Купить")
}
Button(modifier = Modifier.width(115.dp), shape = RoundedCornerShape(5.dp), onClick = { CartModel.addBouquet(bouquet) },
colors = ButtonDefaults.buttonColors(
containerColor = colorResource(id = R.color.button)
)) {
Text("В корзину")
}
}
}
}
}
//@Composable
//fun BouquetCardUpgrade(bouquet: Bouquet, onRemove: (List<Bouquet>) -> Unit) {
// var heart by remember { mutableStateOf(FavoriteModel.containsBouquet(bouquet)) }
// var expandedName by remember { mutableStateOf(false) }
// Card(
// elevation = CardDefaults.cardElevation(
// defaultElevation = 10.dp
// ),
// colors = CardDefaults.cardColors(
// containerColor = Color.White
// )
// ) {
// Column(horizontalAlignment = Alignment.CenterHorizontally) {
// Box(contentAlignment = Alignment.TopEnd) {
// if (bouquet.image != null) {
// val decodedBitmap =
// BitmapFactory.decodeByteArray(bouquet.image, 0, bouquet.image!!.size)
// val imageBitmap = decodedBitmap.asImageBitmap()
// Image(
// bitmap = imageBitmap,
// contentDescription = null,
// modifier = Modifier
// .width(180.dp)
// .height(180.dp)
// .clip(shape = RoundedCornerShape(10.dp)),
// contentScale = ContentScale.Crop
// )
// }
// Box(Modifier.clip(RoundedCornerShape(10.dp)).clickable { }) {
// Icon(
// painter = painterResource(id = heart),
// contentDescription = null,
// modifier = Modifier
// .size(40.dp)
// .clip(shape = RoundedCornerShape(10.dp))
// .clickable {
// //onRemove(FavoriteModel.removeBouquets(bouquet))
// heart = R.drawable.heart_black
// }
// )
// }
// }
// Spacer(modifier = Modifier.height(8.dp))
// if (expandedName) {
// AlertDialog(
// onDismissRequest = { expandedName = false },
// title = {
// Text(text = bouquet.name, fontFamily = FontFamily.Serif, fontSize = 25.sp)
// },
// confirmButton = {
// Button(
// onClick = { expandedName = false }
// ) {
// Text("Закрыть")
// }
// }
// )
// }
// Text(text = bouquet.name,
// fontFamily = FontFamily.Serif,
// fontSize = 20.sp,
// maxLines = 1,
// overflow = TextOverflow.Ellipsis,
// modifier = Modifier
// .padding(start = 5.dp, end = 5.dp)
// .clickable { expandedName = true })
// //Spacer(modifier = Modifier.height(1.dp))
// Text(text = "${bouquet.quantityOfFlowers} цветов", fontFamily = FontFamily.Serif, fontSize = 19.sp)
// //Spacer(modifier = Modifier.height(8.dp))
// Text(text = "${bouquet.price}", fontFamily = FontFamily.Serif, fontSize = 19.sp)
// Column(horizontalAlignment = Alignment.CenterHorizontally, verticalArrangement = Arrangement.Center) {
// Button(modifier = Modifier.width(115.dp), shape = RoundedCornerShape(5.dp), onClick = { },
// colors = ButtonDefaults.buttonColors(
// containerColor = colorResource(id = R.color.button)
// )) {
// Text("Купить")
// }
// Button(modifier = Modifier.width(115.dp), shape = RoundedCornerShape(5.dp), onClick = { CartModel.addBouquet(bouquet) },
// colors = ButtonDefaults.buttonColors(
// containerColor = colorResource(id = R.color.button)
// )) {
// Text("В корзину")
// }
// }
// }
// }
//}

View File

@ -81,91 +81,91 @@ fun ShoppingCart(navController: NavController) {
// }
}
@Composable
fun CartBouquetCard(bouquet: Bouquet, onPriceChanged: (Int) -> Unit, onRemove: (List<Bouquet>) -> Unit){
var heart by remember { mutableStateOf(FavoriteModel.containsBouquet(bouquet)) }
var quantity by remember { mutableStateOf(1) }
Card(
modifier = Modifier
.padding(16.dp),
//.fillMaxWidth(),
elevation = CardDefaults.cardElevation(
defaultElevation = 10.dp
),
colors = CardDefaults.cardColors(
containerColor = Color.White
)
//modifier = Modifier.padding(start = 5.dp, end = 5.dp),
//horizontalAlignment = Alignment.CenterHorizontally
) {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Box(contentAlignment = Alignment.TopEnd) {
if (bouquet.image != null){
val decodedBitmap = BitmapFactory.decodeByteArray(bouquet.image, 0, bouquet.image!!.size)
val imageBitmap = decodedBitmap.asImageBitmap()
Image(
bitmap = imageBitmap,
contentDescription = null,
modifier = Modifier
.width(250.dp)
.height(250.dp)
.clip(shape = RoundedCornerShape(10.dp)),
contentScale = ContentScale.Crop
)
}
Box(
Modifier
.clip(RoundedCornerShape(10.dp))
.clickable { }) {
Icon(
painter = painterResource(id = heart),
contentDescription = null,
modifier = Modifier
.size(40.dp)
.clip(shape = RoundedCornerShape(10.dp))
.clickable { heart = FavoriteModel.addBouquet(bouquet) }
)
}
}
Spacer(modifier = Modifier.height(8.dp))
Text(text = bouquet.name, fontFamily = FontFamily.Serif, fontSize = 25.sp)
//Spacer(modifier = Modifier.height(1.dp))
Text(text = "${bouquet.quantityOfFlowers} цветов", fontFamily = FontFamily.Serif, fontSize = 19.sp)
//Spacer(modifier = Modifier.height(8.dp))
Text(text = "${bouquet.price}", fontFamily = FontFamily.Serif, fontSize = 19.sp)
Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceAround, modifier = Modifier.height(50.dp)) {
Box(modifier = Modifier.fillMaxHeight(0.5f)){
Icon(
painter = painterResource(id = R.drawable.icon_minus_cirlce),
contentDescription = "",
modifier = Modifier.clickable {
if (quantity >= 1) {
quantity--
onPriceChanged(-bouquet.price)
}
if (quantity == 0){
//onRemove(CartModel.removeBouquets(bouquet))
}
}
)
}
Box(){
Text(text = "$quantity")
}
Box(modifier = Modifier.fillMaxHeight(0.5f)){
Icon(
painter = painterResource(id = R.drawable.icon_add_circle),
contentDescription = "",
modifier = Modifier.clickable {
quantity++
onPriceChanged(bouquet.price)
}
)
}
}
}
}
}
//@Composable
//fun CartBouquetCard(bouquet: Bouquet, onPriceChanged: (Int) -> Unit, onRemove: (List<Bouquet>) -> Unit){
// var heart by remember { mutableStateOf(FavoriteModel.containsBouquet(bouquet)) }
// var quantity by remember { mutableStateOf(1) }
// Card(
// modifier = Modifier
// .padding(16.dp),
// //.fillMaxWidth(),
// elevation = CardDefaults.cardElevation(
// defaultElevation = 10.dp
// ),
// colors = CardDefaults.cardColors(
// containerColor = Color.White
// )
// //modifier = Modifier.padding(start = 5.dp, end = 5.dp),
// //horizontalAlignment = Alignment.CenterHorizontally
// ) {
// Column(horizontalAlignment = Alignment.CenterHorizontally) {
// Box(contentAlignment = Alignment.TopEnd) {
// if (bouquet.image != null){
// val decodedBitmap = BitmapFactory.decodeByteArray(bouquet.image, 0, bouquet.image!!.size)
// val imageBitmap = decodedBitmap.asImageBitmap()
// Image(
// bitmap = imageBitmap,
// contentDescription = null,
// modifier = Modifier
// .width(250.dp)
// .height(250.dp)
// .clip(shape = RoundedCornerShape(10.dp)),
// contentScale = ContentScale.Crop
// )
// }
// Box(
// Modifier
// .clip(RoundedCornerShape(10.dp))
// .clickable { }) {
// Icon(
// painter = painterResource(id = heart),
// contentDescription = null,
// modifier = Modifier
// .size(40.dp)
// .clip(shape = RoundedCornerShape(10.dp))
// .clickable { heart = FavoriteModel.addBouquet(bouquet) }
// )
// }
// }
// Spacer(modifier = Modifier.height(8.dp))
// Text(text = bouquet.name, fontFamily = FontFamily.Serif, fontSize = 25.sp)
// //Spacer(modifier = Modifier.height(1.dp))
// Text(text = "${bouquet.quantityOfFlowers} цветов", fontFamily = FontFamily.Serif, fontSize = 19.sp)
// //Spacer(modifier = Modifier.height(8.dp))
// Text(text = "${bouquet.price}", fontFamily = FontFamily.Serif, fontSize = 19.sp)
// Row(verticalAlignment = Alignment.CenterVertically, horizontalArrangement = Arrangement.SpaceAround, modifier = Modifier.height(50.dp)) {
// Box(modifier = Modifier.fillMaxHeight(0.5f)){
// Icon(
// painter = painterResource(id = R.drawable.icon_minus_cirlce),
// contentDescription = "",
// modifier = Modifier.clickable {
// if (quantity >= 1) {
// quantity--
// onPriceChanged(-bouquet.price)
// }
// if (quantity == 0){
// //onRemove(CartModel.removeBouquets(bouquet))
// }
// }
// )
// }
// Box(){
// Text(text = "$quantity")
// }
// Box(modifier = Modifier.fillMaxHeight(0.5f)){
// Icon(
// painter = painterResource(id = R.drawable.icon_add_circle),
// contentDescription = "",
// modifier = Modifier.clickable {
// quantity++
// onPriceChanged(bouquet.price)
// }
// )
// }
// }
// }
// }
//}
fun getTotalCostOfItemsInCart(): Int {
val bouquetsInCart = CartModel.bouquets
var totalCost = 0

View File

@ -2,6 +2,7 @@ package com.example.flowershopapp.ComposeUI.Navigation
import android.annotation.SuppressLint
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.Crossfade
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
@ -9,6 +10,7 @@ import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
@ -156,7 +158,7 @@ fun Navbar(
Row(
modifier = Modifier
.fillMaxWidth()
.height(75.dp),
.height(95.dp),
horizontalArrangement = Arrangement.SpaceEvenly, verticalAlignment = Alignment.CenterVertically
) {
Screen.bottomBarItems.forEach { screen ->
@ -166,8 +168,8 @@ fun Navbar(
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.weight(1f)
.clip(RoundedCornerShape(15.dp))
.wrapContentHeight()
//.background(colorResource(id = R.color.backgroundNavBarColor))
.clickable(onClick = {
navController.navigate(screen.route) {
@ -182,28 +184,33 @@ fun Navbar(
) {
Column(
modifier = Modifier
.padding(12.dp)
.wrapContentWidth(),//.background(Color.Red),
.padding(12.dp),
//.wrapContentWidth(),//.background(Color.Red),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
screen.icon?.let {
Icon(
modifier = Modifier.size(20.dp),
modifier = Modifier.size(25.dp),
painter = painterResource(screen.icon),
contentDescription = null,
tint = contentColor
)
}
AnimatedVisibility(
visible = isSelected
) {
Text(
text = stringResource(screen.resourceId),
color = contentColor,
fontSize = 12.sp
)
}
// Text(
// text = stringResource(screen.resourceId),
// color = contentColor,
// fontSize = 12.sp
// )
// Crossfade(targetState = isSelected, label = "") { selected ->
// if (selected) {
// Text(
// text = stringResource(screen.resourceId),
// color = contentColor,
// fontSize = 10.sp
// )
// }
// }
}
}
}

View File

@ -20,7 +20,7 @@ interface AppContainer {
companion object {
const val TIMEOUT = 5000L
const val LIMIT = 8
const val LIMIT = 5
}
}
class AppDataContainer(private val context: Context) : AppContainer {

View File

@ -4,45 +4,51 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.example.flowershopapp.R
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
class FavoriteModel : ViewModel() {
companion object {
private val _favoriteList = MutableLiveData<List<Bouquet>>(emptyList())
val bouquets: LiveData<List<Bouquet>> = _favoriteList
//companion object {
private val _favoriteList = MutableStateFlow<List<Bouquet>>(emptyList())
val bouquets: StateFlow<List<Bouquet>> = _favoriteList.asStateFlow()
fun addBouquet(bouquet: Bouquet): Int {
val currentList = _favoriteList.value.orEmpty().toMutableList()
return if (currentList.contains(bouquet)) {
currentList.remove(bouquet)
_favoriteList.value = currentList
R.drawable.heart_black
} else {
currentList.add(bouquet)
_favoriteList.value = currentList
R.drawable.heart_red
}
}
fun addBouquets(vararg bouquets: Bouquet) {
val currentList = _favoriteList.value.orEmpty().toMutableList()
currentList.addAll(bouquets)
fun addBouquet(bouquet: Bouquet): Int {
val currentList = _favoriteList.value.toMutableList()
return if (currentList.contains(bouquet)) {
currentList.remove(bouquet)
_favoriteList.value = currentList
}
fun removeBouquets(bouquetRemove: Bouquet) {
val currentList = _favoriteList.value.orEmpty().toMutableList()
currentList.removeAll { it.bouquetId == bouquetRemove.bouquetId }
R.drawable.heart_black
} else {
currentList.add(bouquet)
_favoriteList.value = currentList
}
fun containsBouquet(bouquet: Bouquet): Int {
val currentList = _favoriteList.value.orEmpty()
return if (currentList.contains(bouquet)) R.drawable.heart_red
else R.drawable.heart_black
}
fun clearBouquets() {
_favoriteList.value = emptyList()
R.drawable.heart_red
}
}
fun addBouquets(vararg bouquets: Bouquet) {
val currentList = _favoriteList.value.toMutableList()
currentList.addAll(bouquets)
_favoriteList.value = currentList
}
fun removeBouquets(bouquetRemove: Bouquet) {
val currentList = _favoriteList.value.toMutableList()
currentList.removeAll { it.bouquetId == bouquetRemove.bouquetId }
_favoriteList.value = currentList
}
fun containsBouquet(bouquet: Bouquet): Int {
val currentList = _favoriteList.value
return if (currentList.contains(bouquet)) R.drawable.heart_red
else R.drawable.heart_black
}
fun clearBouquets() {
_favoriteList.value = emptyList()
}
companion object {
val instance: FavoriteModel by lazy { FavoriteModel() }
}
//}
}

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain>
<domain includeSubdomains="true">192.168.0.102</domain>
</domain-config>
</network-security-config>