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"> <project version="4">
<component name="deploymentTargetDropDown"> <component name="deploymentTargetDropDown">
<value> <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"> <entry key="app">
<State /> <State />
</entry> </entry>

View File

@ -58,13 +58,13 @@ dependencies {
implementation("io.coil-kt:coil-compose:2.5.0") implementation("io.coil-kt:coil-compose:2.5.0")
implementation("androidx.core:core-ktx:1.12.0") implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.2") 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(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")
implementation("androidx.compose.ui:ui-graphics") implementation("androidx.compose.ui:ui-graphics")
implementation("androidx.compose.ui:ui-tooling-preview") 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("androidx.compose.material3:material3:1.1.2")
implementation("com.google.android.engage:engage-core:1.3.1") implementation("com.google.android.engage:engage-core:1.3.1")
implementation("androidx.appcompat:appcompat:1.6.1") implementation("androidx.appcompat:appcompat:1.6.1")
@ -83,9 +83,9 @@ dependencies {
// Retrofit // Retrofit
val retrofitVersion = "2.9.0" val retrofitVersion = "2.9.0"
implementation("com.squareup.retrofit2:retrofit:$retrofitVersion") 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("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") implementation("com.jakewharton.retrofit:retrofit2-kotlinx-serialization-converter:1.0.0")
} }

View File

@ -132,7 +132,7 @@ interface MyServerService {
) )
companion object { 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 @Volatile
private var INSTANCE: MyServerService? = null private var INSTANCE: MyServerService? = null

View File

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

View File

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

View File

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

View File

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

View File

@ -4,45 +4,51 @@ import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import com.example.flowershopapp.R import com.example.flowershopapp.R
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
class FavoriteModel : ViewModel() { class FavoriteModel : ViewModel() {
companion object { //companion object {
private val _favoriteList = MutableLiveData<List<Bouquet>>(emptyList()) private val _favoriteList = MutableStateFlow<List<Bouquet>>(emptyList())
val bouquets: LiveData<List<Bouquet>> = _favoriteList val bouquets: StateFlow<List<Bouquet>> = _favoriteList.asStateFlow()
fun addBouquet(bouquet: Bouquet): Int { fun addBouquet(bouquet: Bouquet): Int {
val currentList = _favoriteList.value.orEmpty().toMutableList() val currentList = _favoriteList.value.toMutableList()
return if (currentList.contains(bouquet)) { return if (currentList.contains(bouquet)) {
currentList.remove(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)
_favoriteList.value = currentList _favoriteList.value = currentList
} R.drawable.heart_black
} else {
fun removeBouquets(bouquetRemove: Bouquet) { currentList.add(bouquet)
val currentList = _favoriteList.value.orEmpty().toMutableList()
currentList.removeAll { it.bouquetId == bouquetRemove.bouquetId }
_favoriteList.value = currentList _favoriteList.value = currentList
} R.drawable.heart_red
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()
} }
} }
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"?> <?xml version="1.0" encoding="utf-8"?>
<network-security-config> <network-security-config>
<domain-config cleartextTrafficPermitted="true"> <domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">10.0.2.2</domain> <domain includeSubdomains="true">192.168.0.102</domain>
</domain-config> </domain-config>
</network-security-config> </network-security-config>