Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
2b0a278
WIP: integrate new code templates and except them as matches for scan…
Fabtron Dec 3, 2024
232b9fe
WIP: remove logging
Fabtron Dec 4, 2024
6e444ba
WIP: add support for new drv items
Fabtron Dec 4, 2024
f0281a4
WIP: upgrade gradle for synch
Fabtron Dec 4, 2024
f5f18ac
refactor it to insert a new item from a deposit return voucher
Fabtron Dec 4, 2024
29cf6a2
add required properties to the BackendCartItem
Fabtron Dec 4, 2024
6746977
fix type
Fabtron Dec 4, 2024
fc292c5
replace with localised message
Fabtron Dec 5, 2024
9e1be5e
move it to be part of the templates
Fabtron Dec 5, 2024
6935404
clean up code
Fabtron Dec 5, 2024
53c0d85
make setter private
Fabtron Dec 5, 2024
93b1d8e
remove obsolete itemId
Fabtron Dec 5, 2024
4261861
add additional new type
Fabtron Dec 5, 2024
51cd087
ensure that new line item from type deposit return is added
Fabtron Dec 5, 2024
2f40d8d
add type for BackendCartItem for new deposit return items
Fabtron Dec 5, 2024
8c57083
make it more readable
Fabtron Dec 5, 2024
7949215
formatting
Fabtron Dec 5, 2024
0c84196
use existing match method to stick to the existing logic
Fabtron Dec 5, 2024
cd5f312
switch order since it matters for the item type
Fabtron Dec 6, 2024
d35ed3a
update doc
Fabtron Dec 6, 2024
e7b3591
WIP: add violations messages
Fabtron Dec 10, 2024
d50e1b3
WIP: resolve violations messages
Fabtron Dec 10, 2024
9996612
WIP: handle deposit return voucher violations
Fabtron Dec 10, 2024
9498a41
WIP: logs for debug
Fabtron Dec 10, 2024
489ae45
make item nullable and add new DepositReturnItem
Fabtron Dec 11, 2024
e510f1d
add ui for new item
Fabtron Dec 11, 2024
bbf161d
integrate new ui and add required logic
Fabtron Dec 11, 2024
1e5c1b2
refactor to add an item for each deposit voucher and remove logs
Fabtron Dec 11, 2024
dc76234
refactor to make resolve method more generic and handle both new viol…
Fabtron Dec 12, 2024
62f76d4
remove logs
Fabtron Dec 12, 2024
60197f3
remove obsolete for each loop
Fabtron Dec 12, 2024
910bf51
add enum class to define ViolationType's
Fabtron Dec 12, 2024
22584c7
Merge branch 'feature-deposit-return-voucher' into apps-1642-add-scan…
Fabtron Dec 17, 2024
aabd3a9
add additional checks to make the parsing safe
Fabtron Dec 17, 2024
17297c5
Merge remote-tracking branch 'origin/apps-1642-add-scanner-support-fo…
Fabtron Dec 17, 2024
9702581
refactor handling the invalid cart item since it is broken
Fabtron Dec 17, 2024
c3ca180
revert obsolete changes
Fabtron Dec 17, 2024
cfb25e1
remove obsolete log
Fabtron Dec 17, 2024
b9709c0
update string
Fabtron Dec 17, 2024
ad526c3
remove obsolete forEach
Fabtron Dec 18, 2024
607be85
give it a better name
Fabtron Dec 19, 2024
c2e9ab9
simplify check
Fabtron Dec 19, 2024
720ee35
simplify violation check
Fabtron Dec 19, 2024
b578525
simplify violation resolve
Fabtron Dec 19, 2024
ec7b428
simplify mapping
Fabtron Dec 19, 2024
8f468db
simplify enum ViolationType
Fabtron Dec 19, 2024
4f90667
rename it
Fabtron Dec 19, 2024
0eb4ad8
simplify it
Fabtron Dec 19, 2024
92970b7
Merge branch 'apps-1642-add-scanner-support-for-deposit-voucher' into…
Fabtron Dec 19, 2024
2222483
add horizontal divider to each item
Fabtron Dec 19, 2024
a71a6c6
Merge remote-tracking branch 'origin/feature-deposit-return-voucher' …
Fabtron Dec 19, 2024
52e9898
center content vertically
Fabtron Dec 19, 2024
3909b94
delete obsolete remove function
Fabtron Dec 19, 2024
7772f64
change it to add lineitems to the referred voucher
Fabtron Dec 23, 2024
4b65adb
remove obsolete delete logic
Fabtron Dec 23, 2024
fd780bf
formatting
Fabtron Dec 23, 2024
cd00a4d
update CHANGELOG.md
Fabtron Dec 23, 2024
ea89caa
renaming for better readability
Fabtron Dec 30, 2024
4f544f7
Add names to call arguments
cmaier Jan 6, 2025
ca8513c
Remove obsolete whitespace character
cmaier Jan 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file.

## UNRELEASED
### Added
* ui: Add UI for deposit return vouchers (APPS-1643)
### Changed
### Removed
* ui/core: Remove everything related to the old deposit return voucher feature
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ internal class ShoppingCartUpdater(

addLineItemsAsCartItems(filter { it.type == LineItemType.COUPON })
addLineItemsAsCartItems(filter { it.type == LineItemType.DEPOSIT })
addLineItemsAsCartItems(filter { it.type == LineItemType.DEPOSIT_RETURN })
addDepositReturnsToVoucher(filter { it.type == LineItemType.DEPOSIT_RETURN })
}

setOnlinePrice(price)
Expand All @@ -166,6 +166,15 @@ internal class ShoppingCartUpdater(
}
}

private fun addDepositReturnsToVoucher(depositReturnItems: List<LineItem>) {
depositReturnItems
.groupBy { it.refersTo }
.forEach { (refersTo, items) ->
val drv = cart.getByItemId(refersTo)
drv?.depositReturnVoucher = drv?.depositReturnVoucher?.copy(lineItems = items)
}
}

private fun addCartDiscounts(cartDiscountItems: List<LineItem>) {
val totalCartDiscount = cartDiscountItems.sumOf { it.totalPrice }
val cartDiscounts = cartDiscountItems.mapNotNull { it.name }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package io.snabble.sdk.shoppingcart.data.item

import io.snabble.sdk.checkout.LineItem

data class DepositReturnVoucher(
val itemId: String,
val scannedCode: String,
val amount: Int = 1,
val type: ItemType = ItemType.DEPOSIT_RETURN_VOUCHER,
val lineItems: List<LineItem> = emptyList()
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.snabble.sdk.ui.cart.shoppingcart

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
Expand All @@ -16,8 +16,10 @@ import io.snabble.sdk.checkout.LineItem
import io.snabble.sdk.shoppingcart.ShoppingCart
import io.snabble.sdk.ui.cart.shoppingcart.cartdiscount.CartDiscount
import io.snabble.sdk.ui.cart.shoppingcart.cartdiscount.model.CartDiscountItem
import io.snabble.sdk.ui.cart.shoppingcart.depositreturn.DepositReturn
import io.snabble.sdk.ui.cart.shoppingcart.product.DeletableProduct
import io.snabble.sdk.ui.cart.shoppingcart.product.model.DepositItem
import io.snabble.sdk.ui.cart.shoppingcart.product.model.DepositReturnItem
import io.snabble.sdk.ui.cart.shoppingcart.product.model.DiscountItem
import io.snabble.sdk.ui.cart.shoppingcart.product.model.ProductItem
import io.snabble.sdk.ui.utils.ThemeWrapper
Expand Down Expand Up @@ -61,7 +63,7 @@ private fun ShoppingCartScreen(
LazyColumn(
modifier = modifier.nestedScroll(rememberNestedScrollInteropConnection())
) {
items(items = uiState.items, key = { it.hashCode() }) { cartItem ->
itemsIndexed(items = uiState.items, key = { _, item -> item.hashCode() }) { index, cartItem ->
when (cartItem) {
is ProductItem -> {
DeletableProduct(
Expand All @@ -72,17 +74,21 @@ private fun ShoppingCartScreen(
onQuantityChanged(cartItem.item, quantity)
}
)
HorizontalDivider()
}

is DepositReturnItem -> {
val showHint = uiState.totalCartPrice != null && uiState.totalCartPrice < 0
DepositReturn(item = cartItem, showHint = showHint, onDeleteClick = onItemDeleted)
}

is CartDiscountItem -> {
CartDiscount(
modifier = Modifier.fillMaxWidth(),
item = cartItem
)
HorizontalDivider()
}
}
if (index != uiState.items.lastIndex) HorizontalDivider()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import io.snabble.sdk.shoppingcart.data.item.ItemType
import io.snabble.sdk.shoppingcart.data.listener.SimpleShoppingCartListener
import io.snabble.sdk.ui.cart.shoppingcart.cartdiscount.model.CartDiscountItem
import io.snabble.sdk.ui.cart.shoppingcart.product.model.DepositItem
import io.snabble.sdk.ui.cart.shoppingcart.product.model.DepositReturnItem
import io.snabble.sdk.ui.cart.shoppingcart.product.model.DiscountItem
import io.snabble.sdk.ui.cart.shoppingcart.product.model.ProductItem
import io.snabble.sdk.ui.telemetry.Telemetry
Expand All @@ -30,6 +31,7 @@ class ShoppingCartViewModel : ViewModel() {
}
}

// used to update the cart remote -> do not delete it
fun updateCart() {
updateUiState(cachedCart)
}
Expand Down Expand Up @@ -68,12 +70,11 @@ class ShoppingCartViewModel : ViewModel() {
private fun updateUiState(cart: ShoppingCart) {
cachedCart = cart

val filteredCart = cart.filterNotNull()

val cartItems: MutableList<CartItem> = mutableListOf()

with(filteredCart) {
with(cart.filterNotNull()) {
filter { it.type == ItemType.PRODUCT }.let { cartItems.addProducts(it) }
filter { it.lineItem?.type == LineItemType.DEPOSIT_RETURN_VOUCHER }
.let { cartItems.addDepositReturnItems(it) }

filter { it.lineItem?.type == LineItemType.DEPOSIT }.let { cartItems.addDepositsToProducts(it) }

Expand All @@ -85,7 +86,21 @@ class ShoppingCartViewModel : ViewModel() {
cartItems.updatePrices()
cartItems.sortCartDiscountsToBottom()

_uiState.update { it.copy(items = cartItems) }
_uiState.update { it.copy(items = cartItems, totalCartPrice = cachedCart.totalPrice) }
}

private fun MutableList<CartItem>.addDepositReturnItems(items: List<ShoppingCart.Item>) {
items.forEach { item ->
val totalDepositReturnPrice =
item.depositReturnVoucher?.lineItems?.sumOf { it.totalPrice } ?: return@forEach

add(
DepositReturnItem(
item = item,
totalDeposit = priceFormatter?.format(totalDepositReturnPrice).orEmpty()
)
)
}
}

private fun MutableList<CartItem>.sortCartDiscountsToBottom() {
Expand Down Expand Up @@ -230,6 +245,7 @@ class ShoppingCartViewModel : ViewModel() {
}

sealed interface Event

internal data class RemoveItem(
val item: ShoppingCart.Item,
val onSuccess: (index: Int) -> Unit
Expand All @@ -242,4 +258,5 @@ internal data class UpdateQuantity(

data class UiState(
val items: List<CartItem> = emptyList(),
val totalCartPrice: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package io.snabble.sdk.ui.cart.shoppingcart.cartdiscount
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Surface
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
Expand All @@ -13,7 +15,10 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import io.snabble.sdk.checkout.LineItem
import io.snabble.sdk.shoppingcart.ShoppingCart
import io.snabble.sdk.ui.cart.shoppingcart.cartdiscount.model.CartDiscountItem
import io.snabble.sdk.ui.cart.shoppingcart.cartdiscount.widget.DiscountDescription

Expand Down Expand Up @@ -41,3 +46,18 @@ internal fun CartDiscount(
)
}
}

@PreviewLightDark
@Composable
private fun Preview() {
Surface {
CartDiscount(
modifier = Modifier.fillMaxWidth(),
item = CartDiscountItem(
item = ShoppingCart.Item(ShoppingCart(), LineItem(id = "", amount = 1)),
discount = "7.00",
name = "SUPER DUPER RABATT"
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package io.snabble.sdk.ui.cart.shoppingcart.depositreturn

import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.heightIn
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedIconButton
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight.Companion.Bold
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.unit.dp
import io.snabble.sdk.shoppingcart.ShoppingCart
import io.snabble.sdk.shoppingcart.data.item.DepositReturnVoucher
import io.snabble.sdk.shoppingcart.data.item.ItemType
import io.snabble.sdk.ui.R
import io.snabble.sdk.ui.cart.shoppingcart.product.model.DepositReturnItem

@Composable
fun DepositReturn(
modifier: Modifier = Modifier,
item: DepositReturnItem,
showHint: Boolean = false,
onDeleteClick: (ShoppingCart.Item) -> Unit
) {
Column(
modifier = modifier
.fillMaxWidth()
.padding(vertical = 16.dp, horizontal = 16.dp)
.heightIn(min = 48.dp),
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically)
) {

Row(
modifier = Modifier
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.spacedBy(16.dp)
) {
Column(
modifier = Modifier
.fillMaxWidth()
.weight(1f),
verticalArrangement = Arrangement.spacedBy(4.dp),
) {
Text(
text = stringResource(R.string.Snabble_ShoppingCart_DepositReturn_title),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onSurface
)
Text(
text = item.totalDeposit,
style = MaterialTheme.typography.bodySmall,
fontWeight = Bold,
color = MaterialTheme.colorScheme.onSurface
)
}
OutlinedIconButton(
modifier = Modifier.size(36.dp),
border = BorderStroke(
width = 1.dp,
color = MaterialTheme.colorScheme.onSurface.copy(alpha = 0.33f)
),
onClick = { onDeleteClick(item.item) }
) {
Icon(
painter = painterResource(R.drawable.snabble_ic_delete),
contentDescription = stringResource(
id = R.string.Snabble_Shoppingcart_Accessibility_actionDelete
),
tint = MaterialTheme.colorScheme.onSurface
)
}

}
if (showHint) {
Text(
modifier = Modifier.fillMaxWidth(),
text = stringResource(R.string.Snabble_ShoppingCart_DepositReturn_message),
style = MaterialTheme.typography.bodySmall,
fontWeight = Bold,
color = MaterialTheme.colorScheme.error,
textAlign = TextAlign.Center
)
}

}
}

@PreviewLightDark
@Composable
private fun PreviewWithHint() {
Surface {
DepositReturn(
item = DepositReturnItem(
item = ShoppingCart.Item(
ShoppingCart(),
DepositReturnVoucher("", "", 1, ItemType.DEPOSIT_RETURN_VOUCHER)
),
totalDeposit = "-0.75€"
),
showHint = true,
onDeleteClick = {}
)
}
}

@PreviewLightDark
@Composable
private fun PreviewWithoutHint() {
Surface {
DepositReturn(
item = DepositReturnItem(
item = ShoppingCart.Item(
ShoppingCart(),
DepositReturnVoucher("", "", 1, ItemType.DEPOSIT_RETURN_VOUCHER)
),
totalDeposit = "-0.75€"
),
showHint = false,
onDeleteClick = {}
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.snabble.sdk.ui.cart.shoppingcart.product.model

import io.snabble.sdk.shoppingcart.ShoppingCart
import io.snabble.sdk.ui.cart.shoppingcart.CartItem

data class DepositReturnItem(
override val item: ShoppingCart.Item,
val totalDeposit: String
) : CartItem
2 changes: 2 additions & 0 deletions ui/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@
<string name="Snabble.Shop.List.Expand.accessibility">aufklappen</string>
<string name="Snabble.Shop.List.ShowDetails.accessibility">Shop-Details anzeigen</string>
<string name="Snabble.Shopping.title">Einkaufen</string>
<string name="Snabble.ShoppingCart.DepositReturn.message">Damit der Leergutbon eingelöst werden kann, fülle deinen Warenkorb mit deinen Wunschprodukten.</string>
<string name="Snabble.ShoppingCart.DepositReturn.title">Leergutbon</string>
<string name="Snabble.ShoppingCart.title">Warenkorb</string>
<string name="Snabble.ShoppingList.AddItem.viaScan">Produkte scannen</string>
<string name="Snabble.ShoppingList.AddItem.viaVoice">Produkte diktieren</string>
Expand Down
2 changes: 2 additions & 0 deletions ui/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@
<string name="Snabble.Shop.List.Expand.accessibility">expand</string>
<string name="Snabble.Shop.List.ShowDetails.accessibility">Show shop details</string>
<string name="Snabble.Shopping.title">Shopping</string>
<string name="Snabble.ShoppingCart.DepositReturn.message">To redeem your voucher, fill your shopping basket with the products you wish to purchase.</string>
<string name="Snabble.ShoppingCart.DepositReturn.title">Deposit voucher</string>
<string name="Snabble.ShoppingCart.title">Shopping Cart</string>
<string name="Snabble.ShoppingList.AddItem.viaScan">Scan products</string>
<string name="Snabble.ShoppingList.AddItem.viaVoice">Tell products</string>
Expand Down
Loading