Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/trunk' into issue/12281-creating…
Browse files Browse the repository at this point in the history
…-shipping-label-landscape-support
  • Loading branch information
Alejo committed Oct 29, 2024
2 parents 4ca8182 + 01623fe commit c959014
Show file tree
Hide file tree
Showing 8 changed files with 67 additions and 18 deletions.
4 changes: 2 additions & 2 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*** For entries which are touching the Android Wear app's, start entry with `[WEAR]` too.
21.0
-----

- [*] Fixed text formatting in the "Collect Payment has moved" rationale bottom sheet [https://github.com/woocommerce/woocommerce-android/pull/12815]

20.9
-----

- [*][Payments]Fixed UI glitch in change due calculation screen [https://github.com/woocommerce/woocommerce-android/pull/12808]

20.8
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.res.vectorResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.PreviewScreenSizes
import com.woocommerce.android.R
import com.woocommerce.android.ui.compose.component.BottomSheetHandle
import com.woocommerce.android.ui.compose.component.WCColoredButton
Expand All @@ -43,7 +44,7 @@ fun OrderCreateEditSimplePaymentsMigrationBottomSheetScreen(
Column(
modifier = Modifier
.verticalScroll(rememberScrollState())
.padding(dimensionResource(id = R.dimen.minor_100))
.padding(dimensionResource(id = R.dimen.major_100))
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
) {
Expand Down Expand Up @@ -94,6 +95,7 @@ fun OrderCreateEditSimplePaymentsMigrationBottomSheetScreen(
}

@LightDarkThemePreviews
@PreviewScreenSizes
@Composable
fun PreviewOrderCreateEditSimplePaymentsMigrationBottomSheetScreen() {
WooTheme {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.input.KeyboardType
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.PreviewLightDark
import androidx.compose.ui.tooling.preview.PreviewScreenSizes
import androidx.compose.ui.unit.dp
import com.woocommerce.android.R
import com.woocommerce.android.ui.compose.component.NullableCurrencyTextFieldValueMapper
Expand Down Expand Up @@ -178,10 +179,10 @@ fun RecordTransactionDetailsNote(
modifier = modifier
.fillMaxWidth()
.clickable { onCheckedChange(!checked) },
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
Text(
modifier = Modifier.weight(1f),
text = stringResource(R.string.cash_payments_record_transaction_details),
style = MaterialTheme.typography.body1
)
Expand Down Expand Up @@ -217,6 +218,7 @@ fun MarkOrderAsCompleteButton(

@Composable
@PreviewLightDark
@PreviewScreenSizes
fun ChangeDueCalculatorScreenSuccessPreviewUnchecked() {
ChangeDueCalculatorScreen(
uiState = ChangeDueCalculatorViewModel.UiState(
Expand All @@ -240,6 +242,7 @@ fun ChangeDueCalculatorScreenSuccessPreviewUnchecked() {

@Composable
@PreviewLightDark
@PreviewScreenSizes
fun ChangeDueCalculatorScreenSuccessPreviewChecked() {
ChangeDueCalculatorScreen(
uiState = ChangeDueCalculatorViewModel.UiState(
Expand All @@ -263,6 +266,7 @@ fun ChangeDueCalculatorScreenSuccessPreviewChecked() {

@Composable
@PreviewLightDark
@PreviewScreenSizes
fun ChangeDueCalculatorScreenSuccessPreviewDisabled() {
ChangeDueCalculatorScreen(
uiState = ChangeDueCalculatorViewModel.UiState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,13 +562,15 @@ class ProductListFragment :

// reload the product list without this product
productListViewModel.reloadProductsFromDb(excludeProductId = remoteProductId)
enableProductsRefresh(false)

val actionListener = View.OnClickListener {
trashProductCancelled = true
}

val callback = object : Snackbar.Callback() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {
enableProductsRefresh(true)
pendingTrashProductId = null
if (trashProductCancelled) {
productListViewModel.reloadProductsFromDb()
Expand All @@ -579,13 +581,12 @@ class ProductListFragment :
}

trashProductUndoSnack = uiMessageResolver.getUndoSnack(
R.string.product_trash_undo_snackbar_message,
stringResId = R.string.product_trash_undo_snackbar_message,
actionListener = actionListener
)
.also {
it.addCallback(callback)
it.show()
}
).apply {
addCallback(callback)
show()
}
}

override fun scrollToTop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ class ProductListViewModel @Inject constructor(
get() = savedState[KEY_PRODUCT_SELECTED_ON_BIG_SCREEN]
set(value) = savedState.set(KEY_PRODUCT_SELECTED_ON_BIG_SCREEN, value)

private val isLoading
get() = viewState.isLoading == true

private val isTrashing
get() = viewState.isTrashing == true

init {
EventBus.getDefault().register(this)
if (_productList.value == null) {
Expand Down Expand Up @@ -120,8 +126,6 @@ class ProductListViewModel @Inject constructor(

fun isSkuSearch() = isSearching() && viewState.isSkuSearch

private fun isLoading() = viewState.isLoading == true

fun getSearchQuery() = viewState.query

fun onSearchQueryChanged(
Expand Down Expand Up @@ -299,7 +303,7 @@ class ProductListViewModel @Inject constructor(
scrollToTop: Boolean = false,
isRefreshing: Boolean = false
) {
if (isLoading()) {
if (isLoading) {
WooLog.d(WooLog.T.PRODUCTS, "already loading products")
return
}
Expand Down Expand Up @@ -342,7 +346,7 @@ class ProductListViewModel @Inject constructor(

loadJob = launch {
val showSkeleton: Boolean
if (loadMore) {
if (loadMore || isTrashing) {
showSkeleton = false
} else {
// if this is the initial load, first get the products from the db and show them immediately
Expand Down Expand Up @@ -590,8 +594,13 @@ class ProductListViewModel @Inject constructor(

fun trashProduct(remoteProductId: Long) {
if (checkConnection()) {
launch {
if (!productRepository.trashProduct(remoteProductId)) {
loadJob = launch {
viewState = viewState.copy(isTrashing = true)
val successfullyTrashed = productRepository.trashProduct(remoteProductId)
if (successfullyTrashed) {
fetchProductList(loadMore = false, scrollToTop = false)
viewState = viewState.copy(isTrashing = false)
} else {
triggerEvent(MultiLiveEvent.Event.ShowSnackbar(R.string.product_trash_error))
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class ProductListViewState(
val isLoadingMore: Boolean? = null,
val canLoadMore: Boolean? = null,
val isRefreshing: Boolean? = null,
val isTrashing: Boolean? = null,
val query: String? = null,
val isSkuSearch: Boolean = false,
val filterCount: Int? = null,
Expand Down
4 changes: 2 additions & 2 deletions WooCommerce/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,8 @@
<string name="order_creation_expand_collapse_order_totals">Expand collapse order totals</string>
<string name="order_creation_payment_shipping_tax_label">Shipping Tax</string>
<string name="order_creation_simple_payment_migration_title">Collect Payment \nhas moved</string>
<string name="order_creation_simple_payment_migration_message_one">We’ve combined payment collection with\norder creation, making it more accessible\nand more powerful.</string>
<string name="order_creation_simple_payment_migration_message_two">To set a payment amount, add\na custom amount to your new order.</string>
<string name="order_creation_simple_payment_migration_message_one">We’ve combined payment collection with order creation, making it more accessible and more powerful.</string>
<string name="order_creation_simple_payment_migration_message_two">To set a payment amount, add a custom amount to your new order.</string>
<string name="order_creation_simple_payment_migration_button">Add a Custom Amount</string>
<string name="customer_picker_guest_customer_not_allowed_message">This user is a guest, and guests can\'t be used for filtering orders.</string>
<string name="customer_picker_guest">Guest</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,38 @@ class ProductListViewModelTest : BaseUnitTest() {
assertThat(snackbar).isEqualTo(MultiLiveEvent.Event.ShowSnackbar(R.string.product_trash_error))
}

@Test
fun `trashProduct trigger products refresh`() = testBlocking {
val productId = 1L
whenever(networkStatus.isConnected()).thenReturn(true)
whenever(productRepository.trashProduct(productId)).thenReturn(true)

createViewModel()

viewModel.trashProduct(productId)

verify(productRepository).trashProduct(productId)
verify(productRepository, times(2)).fetchProductList()
}

@Test
fun `trashProduct updates the viewState as expected`() = testBlocking {
val productId = 1L
val isTrashingEvents: MutableList<Boolean?> = mutableListOf()
whenever(networkStatus.isConnected()).thenReturn(true)
whenever(productRepository.trashProduct(productId)).thenReturn(true)

createViewModel()

viewModel.viewStateLiveData.observeForever { old, new ->
if (old?.isTrashing == new.isTrashing) return@observeForever
isTrashingEvents.add(new.isTrashing)
}

viewModel.trashProduct(productId)
assertThat(isTrashingEvents).containsExactly(true, false)
}

@Test
fun `Test Filters button tap`() {
createViewModel()
Expand Down

0 comments on commit c959014

Please sign in to comment.