Nikhil Parab
06/26/2025, 11:44 AMSergey Dmitriev
06/26/2025, 11:49 AMNikhil Parab
06/26/2025, 11:58 AMLazyColumn(
...
) {
items(
items = selectedItems,
key = { item -> item.id },
contentType = { _ -> "SelectedItem" }
) { item ->
val condition = !(item.inCertainCategory && item.part_desc?.contains("xyz", ignoreCase = true) == false) &&
selectedItems.count {
it.inCertainCategory && it.part_desc?.contains("xyz", ignoreCase = true) == true
} > 1
SelectedPartItem(
modifier = Modifier.animateItem(),
item = item,
isEditEnabled = condition,
onAdd = { onAddMinusItem(true, item) },
onMinus = { onAddMinusItem(false, item) },
onRemove = { onRemoveItem(item) }
)
}
}
fun removeItem(...) {
viewModelScope.launch {
...
}
}
Sergey Dmitriev
06/26/2025, 12:02 PMwhich disables the remove icon when last part is remaining in the listWhat “when last part is remaining in the list” means?
when I click on the remove button on 2 of the last cards, both the items gets removed.That sounds correct, if remove button is available when you click on it the item gets removed 🤔
Sergey Dmitriev
06/26/2025, 12:14 PMselectedItems
• Check the condition
try to break it down and make more readableNikhil Parab
06/26/2025, 12:18 PMSergey Dmitriev
06/26/2025, 12:18 PMNikhil Parab
06/26/2025, 12:19 PMSergey Dmitriev
06/26/2025, 12:19 PMNikhil Parab
06/26/2025, 12:21 PMSergey Dmitriev
06/26/2025, 12:23 PMNikhil Parab
06/26/2025, 12:23 PMSergey Dmitriev
06/26/2025, 12:24 PMfun removeItem(...) {
viewModelScope.launch {
...
}
}
And how you apply Mutex in particularNikhil Parab
06/26/2025, 12:25 PMprivate val estimateMutex = Mutex()
fun removeItem(...) {
if (quantity < 0) return
viewModelScope.launch {
estimateMutex.withLock {
}
}
}
Sergey Dmitriev
06/26/2025, 12:26 PMwithLock
because now it passes for both clicksSergey Dmitriev
06/26/2025, 12:27 PMquantity
means 😅Sergey Dmitriev
06/26/2025, 12:29 PMfun removeItem(...) {
viewModelScope.launch {
estimateMutex.withLock {
if (quantity < 0) return
// do something
quantity = x
}
}
}
Sergey Dmitriev
06/26/2025, 12:30 PMquantity
outside of MutexNikhil Parab
06/26/2025, 1:27 PMSergey Dmitriev
06/26/2025, 1:29 PMfun removeItem(...) {
viewModelScope.launch {
estimateMutex.withLock {
// Check if the item can be removed
}
}
}
Sergey Dmitriev
06/26/2025, 2:46 PMif (mutex.isLocked) return
Jonathan
06/26/2025, 3:27 PMif (quantity <= 0) return
or if (quantity < 1) return
Jonathan
06/26/2025, 3:28 PMremoveItem(…)
always executes and never returns early.Sergey Dmitriev
06/27/2025, 7:41 AMit unrelated to the logic or removing the item, just a check for minus qtysIt’s unrelated I think the problem here is that no logic guards the execution of removal 2 clicks schedule 2 coroutines to execute, and wrapping them with Mutex is not enough — doing so will only guarantee their execution in sequence, one after another, no racing conditions — however still both will be executed Since UI can send remove requests “uncontrollably” (using two, three, fours… fingers) there should be something that will check the validity of every new request
Nikhil Parab
06/27/2025, 8:43 AM