Flammer99
04/05/2024, 12:36 PMFlammer99
04/05/2024, 12:36 PM@SuppressLint("StateFlowValueCalledInComposition")
@Composable
fun isAddingPage(homeViewModel: homeViewModel,
FoodViewModel: FoodViewModel,
IsAddingViewModel: IsAddingViewModel,
food: FoodStatistics,
){
val isAdding by FoodViewModel.foodStatisticsLiveData.collectAsState()
if(isAdding.listSnacks.isChosen) {
Box() {
Column {
Column {
Row {
Text(text = "{${IsAddingViewModel.isAddingName.value}}")
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Search, contentDescription = "")
}
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Star, contentDescription = "P.H")
}
}
}
listFood()
}
}
}
else if(isAdding.listLunch.isChosen) {
Box(modifier = Modifier.fillMaxSize()) {
Column {
Column {
Row {
Text(text = "{${IsAddingViewModel.isAddingName.value}}")
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Search, contentDescription = "")
}
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Star, contentDescription = "P.H")
}
}
}
listFood()
}
}
}
else if(isAdding.listBreakfast.isChosen) {
Box(modifier = Modifier.fillMaxSize()) {
Column {
Column {
Row {
Text(text = "{${IsAddingViewModel.isAddingName.value}}")
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Search, contentDescription = "")
}
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Star, contentDescription = "P.H")
}
}
}
listFood()
}
}
}
else if(isAdding.listDinner.isChosen) {
Box(modifier = Modifier.fillMaxSize()) {
Column {
Column {
Row {
Text(text = "{${IsAddingViewModel.isAddingName.value}}")
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Search, contentDescription = "")
}
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Star, contentDescription = "P.H")
}
}
}
listFood()
}
}
}
}
Flammer99
04/05/2024, 12:36 PMclass FoodViewModel : ViewModel() {
private val _foodStatisticsLiveData = MutableStateFlow(
FoodStatistics(
DataClassSpecific(false, "Breakfast", 0, 0, 0, 0),
DataClassSpecific(false, "Lunch", 0, 0, 0, 0),
DataClassSpecific(false, "Dinner", 0, 0, 0, 0),
DataClassSpecific(false, "Snacks", 0, 0, 0, 0),
ObjectId(1)
)
)
val foodStatisticsLiveData: StateFlow<FoodStatistics> = _foodStatisticsLiveData
fun addFood(name: String, amount: Int, carbs: Int, prot: Int, fat: Int) {
val currentFoodStatistics = _foodStatisticsLiveData.value
val updatedFoodStatistics = when (name) {
"Breakfast" -> currentFoodStatistics.copy(listBreakfast = DataClassSpecific(false, name, amount, carbs, prot, fat))
"Lunch" -> currentFoodStatistics.copy(listLunch = DataClassSpecific(false, name, amount, carbs, prot, fat))
"Dinner" -> currentFoodStatistics.copy(listDinner = DataClassSpecific(false, name, amount, carbs, prot, fat))
"Snacks" -> currentFoodStatistics.copy(listSnacks = DataClassSpecific(false, name, amount, carbs, prot, fat))
else -> currentFoodStatistics
}
_foodStatisticsLiveData.value = updatedFoodStatistics.copy(ObjectId = ObjectId(currentFoodStatistics.ObjectId.id + 1))
}
fun removeFood(name: String) {
val currentFoodStatistics = _foodStatisticsLiveData.value
val updatedFoodStatistics = when (name) {
"Breakfast" -> currentFoodStatistics.copy(listBreakfast = DataClassSpecific(false, "", 0, 0, 0, 0))
"Lunch" -> currentFoodStatistics.copy(listLunch = DataClassSpecific(false, "", 0, 0, 0, 0))
"Dinner" -> currentFoodStatistics.copy(listDinner = DataClassSpecific(false, "", 0, 0, 0, 0))
"Snacks" -> currentFoodStatistics.copy(listSnacks = DataClassSpecific(false, "", 0, 0, 0, 0))
else -> currentFoodStatistics
}
_foodStatisticsLiveData.value = updatedFoodStatistics
}
}
Flammer99
04/05/2024, 12:37 PM@Composable
fun homeLogic(
viewModel: homeViewModel,
FoosStatistics:FoodStatistics,
FoodViewModel: FoodViewModel) {
val isAdding by FoodViewModel.foodStatisticsLiveData.collectAsState()
Column(Modifier.fillMaxSize()) {
Row() {
Column {
Button(onClick = { isAdding.listBreakfast.isChosen = true }) {
Text(text = "Add Breakfast")
}
}
Column {
Button(onClick = { isAdding.listLunch.isChosen = true }) {
Text(text = "Add Lunch")
}
}
}
Row {
Column {
Button(onClick = { isAdding.listDinner.isChosen = true }) {
Text(text = "Add Dinner")
}
}
Column {
Button(onClick = { isAdding.listSnacks.isChosen = true }) {
Text(text = "Add Snacks")
}
}
}
}}
Zach Klippenstein (he/him) [MOD]
04/05/2024, 2:46 PMFlammer99
04/05/2024, 2:48 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 2:48 PMFlammer99
04/05/2024, 2:48 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 2:49 PMFlammer99
04/05/2024, 2:49 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 2:49 PMFlammer99
04/05/2024, 2:49 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 2:50 PMpropagateMinConstraints=true
)
2. stack composables on front of each other by z order, like FrameLayout
Flammer99
04/05/2024, 2:51 PMFlammer99
04/05/2024, 2:51 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 2:53 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 2:53 PMFlammer99
04/05/2024, 2:54 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 2:57 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 2:58 PMFlammer99
04/05/2024, 2:59 PMFlammer99
04/05/2024, 3:00 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 3:11 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 3:13 PMFlammer99
04/05/2024, 3:32 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 4:06 PM@SuppressLint("StateFlowValueCalledInComposition")
@Composable
fun isAddingPage(homeViewModel: homeViewModel,
FoodViewModel: FoodViewModel,
IsAddingViewModel: IsAddingViewModel,
food: FoodStatistics,
){
val isAdding by FoodViewModel.foodStatisticsLiveData.collectAsState()
if(isAdding.listSnacks.isChosen) {
Column {
Column {
Row {
Text(text = "{${IsAddingViewModel.isAddingName.value}}")
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Search, contentDescription = "")
}
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Star, contentDescription = "P.H")
}
}
}
listFood()
}
}
else if(isAdding.listLunch.isChosen) {
Column(modifier = Modifier.fillMaxSize()) {
Column {
Row {
Text(text = "{${IsAddingViewModel.isAddingName.value}}")
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Search, contentDescription = "")
}
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Star, contentDescription = "P.H")
}
}
}
listFood()
}
}
else if(isAdding.listBreakfast.isChosen) {
Column(modifier = Modifier.fillMaxSize()) {
Column {
Row {
Text(text = "{${IsAddingViewModel.isAddingName.value}}")
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Search, contentDescription = "")
}
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Star, contentDescription = "P.H")
}
}
}
listFood()
}
}
else if(isAdding.listDinner.isChosen) {
Column(modifier = Modifier.fillMaxSize()) {
Column {
Row {
Text(text = "{${IsAddingViewModel.isAddingName.value}}")
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Search, contentDescription = "")
}
}
Row {
Button(onClick = { /*TODO*/ }) {
Icon(Icons.Default.Star, contentDescription = "P.H")
}
}
}
listFood()
}
}
}
Flammer99
04/05/2024, 4:07 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 4:07 PMFlammer99
04/05/2024, 4:07 PMFlammer99
04/05/2024, 5:16 PMFlammer99
04/05/2024, 5:16 PMFlammer99
04/05/2024, 5:23 PMZach Klippenstein (he/him) [MOD]
04/05/2024, 7:49 PMFlammer99
04/05/2024, 8:24 PMFlammer99
04/05/2024, 8:25 PMclass homeViewModel:ViewModel() {
private var _homeAdd : MutableStateFlow<Boolean> = MutableStateFlow(false)
var homeAdd: MutableStateFlow<Boolean> =_homeAdd
private var id: Int = 0
fun startEditing(id: Int) {
this.id = id
_homeAdd.value = true
}
fun endEditing() {
_homeAdd.value = false
}
fun getId(): Int {
return id
}
}
Flammer99
04/05/2024, 8:25 PMclass IsAddingViewModel(food: FoodStatistics) {
private var _isAddingName: MutableStateFlow<String> = MutableStateFlow("")
var isAddingName: MutableStateFlow<String> = _isAddingName
fun checkWhat(food: FoodStatistics) {
_isAddingName.value = when {
food.listBreakfast.isChosen -> "Breakfast"
food.listDinner.isChosen -> "Dinner"
food.listLunch.isChosen -> "Lunch"
food.listSnacks.isChosen -> "Snacks"
else -> ""
}
}
}
Flammer99
04/05/2024, 8:25 PMclass FoodViewModel : ViewModel() {
private val _foodStatisticsLiveData = MutableStateFlow(
FoodStatistics(
DataClassSpecific(false, "Breakfast", 0, 0, 0, 0),
DataClassSpecific(false, "Lunch", 0, 0, 0, 0),
DataClassSpecific(false, "Dinner", 0, 0, 0, 0),
DataClassSpecific(false, "Snacks", 0, 0, 0, 0),
ObjectId(1)
)
)
val foodStatisticsLiveData: StateFlow<FoodStatistics> = _foodStatisticsLiveData
fun addFood(name: String, amount: Int, carbs: Int, prot: Int, fat: Int) {
val currentFoodStatistics = _foodStatisticsLiveData.value
val updatedFoodStatistics = when (name) {
"Breakfast" -> currentFoodStatistics.copy(listBreakfast = DataClassSpecific(false, name, amount, carbs, prot, fat))
"Lunch" -> currentFoodStatistics.copy(listLunch = DataClassSpecific(false, name, amount, carbs, prot, fat))
"Dinner" -> currentFoodStatistics.copy(listDinner = DataClassSpecific(false, name, amount, carbs, prot, fat))
"Snacks" -> currentFoodStatistics.copy(listSnacks = DataClassSpecific(false, name, amount, carbs, prot, fat))
else -> currentFoodStatistics
}
_foodStatisticsLiveData.value = updatedFoodStatistics.copy(ObjectId = ObjectId(currentFoodStatistics.ObjectId.id + 1))
}
fun removeFood(name: String) {
val currentFoodStatistics = _foodStatisticsLiveData.value
val updatedFoodStatistics = when (name) {
"Breakfast" -> currentFoodStatistics.copy(listBreakfast = DataClassSpecific(false, "", 0, 0, 0, 0))
"Lunch" -> currentFoodStatistics.copy(listLunch = DataClassSpecific(false, "", 0, 0, 0, 0))
"Dinner" -> currentFoodStatistics.copy(listDinner = DataClassSpecific(false, "", 0, 0, 0, 0))
"Snacks" -> currentFoodStatistics.copy(listSnacks = DataClassSpecific(false, "", 0, 0, 0, 0))
else -> currentFoodStatistics
}
_foodStatisticsLiveData.value = updatedFoodStatistics
}
}
Flammer99
04/06/2024, 1:32 PMZach Klippenstein (he/him) [MOD]
04/06/2024, 6:00 PMFlammer99
04/06/2024, 6:02 PMZach Klippenstein (he/him) [MOD]
04/08/2024, 11:22 PMDataClassSpecific
?Zach Klippenstein (he/him) [MOD]
04/09/2024, 3:33 PMisAdding.listLunch.isChosen = true
won’t trigger recomposition