-
Notifications
You must be signed in to change notification settings - Fork 132
[Payment Method Improvements] Create the "Record transaction details in order note" section #11569
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
1d30d09
Add a checkbox
backwardstruck a18e3c4
Padding and string
backwardstruck 1f05fc9
Correctly style checkbox
backwardstruck dc1ecf6
Detekt
backwardstruck 10cd940
Make the text larger
backwardstruck 50307f8
Change to Switch
backwardstruck 8b64381
Detekt
backwardstruck 84b6ac4
Add string
backwardstruck ea1b9ea
Mark order as complete
backwardstruck 81c807a
Mark order as complete button
backwardstruck cc675bc
Request keyboard
backwardstruck 1dd1a7e
It doesn't crash
backwardstruck 88129a9
Debug ff enabled
backwardstruck 0249d67
Merge branch 'trunk' into 11525-change-due-calculator-ui-part-3
backwardstruck 551fe3e
We don't want too toolbars
backwardstruck 431a90c
Should not appear to be editable
backwardstruck d0884d2
Padding and whatnot
backwardstruck 3886f6d
Restore change due label
backwardstruck 4a993c1
Doesn't need to be bold
backwardstruck 73f2a26
Use WCMaterialOutlinedCurrencyEditTextView
backwardstruck 46bdccf
Style WCMaterialOutlinedCurrencyEditTextView
backwardstruck 2afb4b7
Don't center the toggle
backwardstruck 47d0c7c
Update navigation pattern
backwardstruck 8cb793f
Detekt
backwardstruck 959bbc7
Detekt
backwardstruck 3dafe68
Detekt
backwardstruck a3d162d
Fix unit test
backwardstruck 7bb9e96
Merge branch '11525-change-due-calculator-ui-part-3' into 11525-chang…
backwardstruck 6af62c6
Restore the button
backwardstruck 448e714
Detekt
backwardstruck 605b295
Leave this false for now
backwardstruck d6768bd
Merge branch 'trunk' into 11525-change-due-calculator-ui-part-3
backwardstruck 958cadc
Merge branch '11525-change-due-calculator-ui-part-3' into 11525-chang…
backwardstruck f99dc1d
Pop the keyboard
backwardstruck e4f14b7
Merge pull request #11570 from woocommerce/11525-change-due-calculato…
backwardstruck 484b8d7
Merge branch 'trunk' into 11525-change-due-calculator-ui-part-3
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
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
27 changes: 15 additions & 12 deletions
27
...n/com/woocommerce/android/ui/payments/changeduecalculator/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 |
---|---|---|
@@ -1,52 +1,55 @@ | ||
package com.woocommerce.android.ui.payments.changeduecalculator | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import androidx.lifecycle.SavedStateHandle | ||
import com.woocommerce.android.tools.SelectedSite | ||
import com.woocommerce.android.ui.orders.details.OrderDetailRepository | ||
import com.woocommerce.android.util.CurrencyFormatter | ||
import com.woocommerce.android.viewmodel.ScopedViewModel | ||
import com.woocommerce.android.viewmodel.navArgs | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.StateFlow | ||
import kotlinx.coroutines.launch | ||
import org.wordpress.android.fluxc.store.WooCommerceStore | ||
import java.math.BigDecimal | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class ChangeDueCalculatorViewModel @Inject constructor( | ||
private val selectedSite: SelectedSite, | ||
private val currencyFormatter: CurrencyFormatter, | ||
savedStateHandle: SavedStateHandle, | ||
private val wooCommerceStore: WooCommerceStore, | ||
private val orderDetailRepository: OrderDetailRepository | ||
) : ScopedViewModel(savedStateHandle) { | ||
|
||
val navArgs: ChangeDueCalculatorFragmentArgs by savedStateHandle.navArgs() | ||
private val orderId: Long = navArgs.orderId | ||
|
||
sealed class UiState { | ||
data object Loading : UiState() | ||
data class Success(val amountDue: String, val change: BigDecimal) : 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 | ||
|
||
private val _navigationEvent = MutableLiveData<Unit>() | ||
val navigationEvent: LiveData<Unit> = _navigationEvent | ||
|
||
init { | ||
loadOrderDetails() | ||
} | ||
|
||
private fun loadOrderDetails() { | ||
launch { | ||
val order = orderDetailRepository.getOrderById(orderId)!! | ||
_uiState.value = UiState.Success(amountDue = formatOrderTotal(order.total), 0.00.toBigDecimal()) | ||
val order = orderDetailRepository.getOrderById(orderId) | ||
order?.let { | ||
_uiState.value = UiState.Success(amountDue = order.total, change = BigDecimal.ZERO) | ||
} ?: run { | ||
_uiState.value = UiState.Error | ||
} | ||
} | ||
} | ||
|
||
private fun formatOrderTotal(total: BigDecimal): String { | ||
val currencyCode = wooCommerceStore.getSiteSettings(selectedSite.get())?.currencyCode ?: "" | ||
return currencyFormatter.formatCurrency(total, currencyCode) | ||
fun onBackPressed() { | ||
_navigationEvent.value = Unit | ||
} | ||
} |
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
Oops, something went wrong.
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.