-
Notifications
You must be signed in to change notification settings - Fork 132
[Payment Method Improvements] Cash Payment Improvements #11414
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
97b0a24
Initial FF check
backwardstruck 5607c0d
Clean up the disorder
backwardstruck 1eddaf5
Add data class
backwardstruck 8920cc0
Start adding navigation logic
backwardstruck 4a3249e
Add placeholder UI
backwardstruck e4c2823
Merge branch 'trunk' into 10941-cash-payment-improvements
backwardstruck 3d77aa0
Add title string
backwardstruck 0face8a
No need to pop up
backwardstruck 23eb91d
Dialog fragment
backwardstruck 18f5e20
Changes to fragment and viewmodel
backwardstruck 85a6b79
Static code analysis
backwardstruck 62a5205
Add test class
backwardstruck 4ad0eb7
Update test class
backwardstruck 020cb3b
Update test class
backwardstruck c21d8a1
Update test class
backwardstruck cb30201
Update test class
backwardstruck de54aa8
Update test class
backwardstruck 8c45aa3
Detekt first pass
backwardstruck a905ee5
Detekt second pass
backwardstruck 886a518
Detekt third pass
backwardstruck 6b05cc5
Detekt fourth pass
backwardstruck 71a082d
Detekt imports
backwardstruck ec6e679
Merge remote-tracking branch 'origin/trunk' into 10941-cash-payment-i…
backwardstruck 5222b8f
Update detekt configuration
backwardstruck f676784
Move test to the module
backwardstruck 27412c1
Remove unused import
backwardstruck dcd90b0
Test simplified
backwardstruck a73d119
Address PR comments
backwardstruck cb6c05a
Use ScopedViewModel
backwardstruck 76ad3ab
Use ScopedViewModel
backwardstruck ff19eca
Don't try/catch
backwardstruck 9776bc2
It should be non-null.
backwardstruck 5acadcb
Assert TODO
backwardstruck 81fe1fc
FF as false for now
backwardstruck c919f23
Update test and method
backwardstruck 3a5645c
Detekt change
backwardstruck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...kotlin/com/woocommerce/android/ui/payments/methodselection/ChangeDueCalculatorFragment.kt
This file contains hidden or 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,71 @@ | ||
package com.woocommerce.android.ui.payments.methodselection | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.ComposeView | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import androidx.fragment.app.DialogFragment | ||
import androidx.fragment.app.viewModels | ||
import com.woocommerce.android.R | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class ChangeDueCalculatorFragment : DialogFragment() { | ||
|
||
private val viewModel: ChangeDueCalculatorViewModel by viewModels() | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View { | ||
return ComposeView(requireContext()).apply { | ||
setContent { | ||
ChangeDueCalculatorScreen() | ||
} | ||
} | ||
} | ||
|
||
@Composable | ||
fun ChangeDueCalculatorScreen() { | ||
val uiState by viewModel.uiState.collectAsState() | ||
|
||
Column( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.padding(16.dp), | ||
verticalArrangement = Arrangement.Center, | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
// Display dynamic content based on UI state | ||
when (uiState) { | ||
is ChangeDueCalculatorViewModel.UiState.Loading -> { | ||
Text(text = stringResource(R.string.loading), style = MaterialTheme.typography.h5) | ||
} | ||
|
||
is ChangeDueCalculatorViewModel.UiState.Success -> { | ||
val state = uiState as ChangeDueCalculatorViewModel.UiState.Success | ||
Text( | ||
text = stringResource(R.string.cash_payments_take_payment_title, state.amountDue), | ||
style = MaterialTheme.typography.h5, | ||
modifier = Modifier.padding(bottom = 16.dp) | ||
) | ||
} | ||
|
||
is ChangeDueCalculatorViewModel.UiState.Error -> { | ||
Text(text = stringResource(R.string.error_generic), style = MaterialTheme.typography.h5) | ||
} | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...otlin/com/woocommerce/android/ui/payments/methodselection/ChangeDueCalculatorViewModel.kt
This file contains hidden or 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,41 @@ | ||
package com.woocommerce.android.ui.payments.methodselection | ||
|
||
import androidx.lifecycle.SavedStateHandle | ||
import com.woocommerce.android.ui.orders.details.OrderDetailRepository | ||
import com.woocommerce.android.viewmodel.ScopedViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import java.math.BigDecimal | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class ChangeDueCalculatorViewModel @Inject constructor( | ||
savedStateHandle: SavedStateHandle, | ||
private val orderDetailRepository: OrderDetailRepository | ||
) : ScopedViewModel(savedStateHandle) { | ||
|
||
private val orderId: Long = savedStateHandle.get<Long>("orderId") | ||
?: throw IllegalArgumentException("OrderId is required") | ||
|
||
sealed class UiState { | ||
data object Loading : UiState() | ||
data class Success(val amountDue: BigDecimal, val change: BigDecimal) : UiState() | ||
data object Error : UiState() | ||
} | ||
|
||
private val _uiState = MutableStateFlow<UiState>(UiState.Loading) | ||
val uiState: StateFlow<UiState> = _uiState | ||
|
||
init { | ||
loadOrderDetails() | ||
} | ||
|
||
private fun loadOrderDetails() { | ||
launch { | ||
val order = orderDetailRepository.getOrderById(orderId)!! | ||
_uiState.value = UiState.Success(amountDue = order.total, 0.00.toBigDecimal()) | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
33 changes: 33 additions & 0 deletions
33
...n/com/woocommerce/android/ui/payments/methodselection/ChangeDueCalculatorViewModelTest.kt
This file contains hidden or 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,33 @@ | ||
package com.woocommerce.android.ui.payments.methodselection | ||
|
||
import com.woocommerce.android.viewmodel.BaseUnitTest | ||
import kotlinx.coroutines.ExperimentalCoroutinesApi | ||
import org.junit.Test | ||
|
||
@ExperimentalCoroutinesApi | ||
class ChangeDueCalculatorViewModelTest : BaseUnitTest() { | ||
@Test | ||
fun `given valid order id, when order details are requested, then success state is emitted`() = testBlocking { | ||
// GIVEN | ||
// TODO val viewModel: ChangeDueCalculatorViewModel = mock() | ||
// TODO | ||
|
||
// WHEN | ||
// TODO | ||
|
||
// THEN | ||
// TODO | ||
} | ||
|
||
@Test | ||
fun `given order details retrieval failure, when order details are loaded, then error state is emitted`() = testBlocking { | ||
// GIVEN | ||
// TODO val viewModel: ChangeDueCalculatorViewModel = mock() | ||
|
||
// WHEN | ||
// TODO | ||
|
||
// THEN | ||
// TODO assertThat(viewModel.uiState.value).isEqualTo(ChangeDueCalculatorViewModel.UiState.Error) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.