-
Notifications
You must be signed in to change notification settings - Fork 130
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12972 from woocommerce/issue/12967-retry-paginati…
…on-error [WooPos][Non Simple Product types] Retry UI for pagination errors on variations screens
- Loading branch information
Showing
18 changed files
with
819 additions
and
626 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
163 changes: 163 additions & 0 deletions
163
...oocommerce/android/ui/woopos/common/composeui/component/WooPosPaginationErrorIndicator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
package com.woocommerce.android.ui.woopos.common.composeui.component | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.foundation.lazy.rememberLazyListState | ||
import androidx.compose.foundation.shape.RoundedCornerShape | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.draw.clip | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.graphics.painter.Painter | ||
import androidx.compose.ui.res.painterResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.semantics.contentDescription | ||
import androidx.compose.ui.semantics.semantics | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.unit.dp | ||
import com.woocommerce.android.R | ||
import com.woocommerce.android.ui.woopos.common.composeui.ShadowType | ||
import com.woocommerce.android.ui.woopos.common.composeui.WooPosCard | ||
import com.woocommerce.android.ui.woopos.common.composeui.WooPosPreview | ||
import com.woocommerce.android.ui.woopos.common.composeui.WooPosTheme | ||
import com.woocommerce.android.ui.woopos.common.composeui.toAdaptivePadding | ||
import com.woocommerce.android.ui.woopos.home.items.PaginationState | ||
import com.woocommerce.android.ui.woopos.home.items.WooPosItem.SimpleProduct | ||
import com.woocommerce.android.ui.woopos.home.items.WooPosItem.VariableProduct | ||
import com.woocommerce.android.ui.woopos.home.items.WooPosItemList | ||
import com.woocommerce.android.ui.woopos.home.items.WooPosItemsViewState | ||
|
||
@Composable | ||
fun WooPosPaginationErrorIndicator( | ||
modifier: Modifier = Modifier, | ||
icon: Painter = painterResource(id = R.drawable.woo_pos_ic_error), | ||
message: String, | ||
primaryButton: Button, | ||
) { | ||
WooPosPaginationErrorIndicatorContent( | ||
modifier = modifier, | ||
icon = icon, | ||
message = message, | ||
primaryButton = primaryButton | ||
) | ||
} | ||
|
||
@Composable | ||
private fun WooPosPaginationErrorIndicatorContent( | ||
modifier: Modifier, | ||
icon: Painter, | ||
message: String, | ||
primaryButton: Button | ||
) { | ||
val itemContentDescription = stringResource(id = R.string.woopos_items_pagination_error_content_description) | ||
WooPosCard( | ||
modifier = modifier | ||
.semantics { contentDescription = itemContentDescription }, | ||
shape = RoundedCornerShape(8.dp), | ||
backgroundColor = MaterialTheme.colors.surface, | ||
elevation = 6.dp, | ||
shadowType = ShadowType.Soft, | ||
) { | ||
Row( | ||
modifier = Modifier | ||
.height(112.dp) | ||
.fillMaxWidth() | ||
.padding(16.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.SpaceBetween | ||
) { | ||
Row( | ||
verticalAlignment = Alignment.CenterVertically, | ||
horizontalArrangement = Arrangement.spacedBy(8.dp), | ||
modifier = Modifier.weight(1f) | ||
) { | ||
Icon( | ||
modifier = Modifier.size(24.dp), | ||
painter = icon, | ||
contentDescription = stringResource(R.string.woopos_error_icon_content_description), | ||
tint = Color.Unspecified, | ||
) | ||
Text( | ||
text = message, | ||
style = MaterialTheme.typography.h5, | ||
fontWeight = FontWeight.SemiBold, | ||
color = MaterialTheme.colors.error, | ||
modifier = Modifier.padding(start = 24.dp.toAdaptivePadding()) | ||
) | ||
} | ||
|
||
WooPosButton( | ||
text = primaryButton.text, | ||
onClick = primaryButton.click, | ||
modifier = Modifier | ||
.weight(0.5f) | ||
.height(50.dp) | ||
.clip(RoundedCornerShape(16.dp)) | ||
) | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
@WooPosPreview | ||
fun WooPosPaginationErrorScreenPreview() { | ||
val itemsState = | ||
WooPosItemsViewState.Content( | ||
items = listOf( | ||
SimpleProduct( | ||
1, | ||
name = "Product 1, Product 1, Product 1, " + | ||
"Product 1, Product 1, Product 1, Product 1, Product 1" + | ||
"Product 1, Product 1, Product 1, Product 1, Product 1", | ||
price = "10.0$", | ||
imageUrl = null, | ||
), | ||
SimpleProduct( | ||
2, | ||
name = "Product 2", | ||
price = "2000.00$", | ||
imageUrl = null, | ||
), | ||
VariableProduct( | ||
3, | ||
name = "Product 3", | ||
price = "2000.00$", | ||
imageUrl = null, | ||
numOfVariations = 20, | ||
variationIds = listOf() | ||
), | ||
), | ||
paginationState = PaginationState.Error, | ||
reloadingProductsWithPullToRefresh = true, | ||
bannerState = WooPosItemsViewState.Content.BannerState( | ||
isBannerHiddenByUser = true, | ||
title = R.string.woopos_banner_simple_products_only_title, | ||
message = R.string.woopos_banner_simple_products_only_message, | ||
icon = R.drawable.info, | ||
), | ||
) | ||
WooPosTheme { | ||
WooPosItemList( | ||
state = itemsState, | ||
listState = rememberLazyListState(), | ||
onItemClicked = {}, | ||
onEndOfProductsListReached = {} | ||
) { | ||
WooPosPaginationErrorIndicator( | ||
message = stringResource(id = R.string.woopos_items_pagination_error), | ||
primaryButton = Button( | ||
text = stringResource(id = R.string.woopos_items_pagination_load_more_label), | ||
click = {} | ||
) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.