-
Notifications
You must be signed in to change notification settings - Fork 133
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
[Payment Method Improvements] Create the "Mark Order as Complete" Button #11570
Merged
backwardstruck
merged 10 commits into
11525-change-due-calculator-ui-part-3
from
11525-change-due-calculator-ui-part-4
May 27, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
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 7bb9e96
Merge branch '11525-change-due-calculator-ui-part-3' into 11525-chang…
backwardstruck 6af62c6
Restore the button
backwardstruck 448e714
Detekt
backwardstruck 958cadc
Merge branch '11525-change-due-calculator-ui-part-3' into 11525-chang…
backwardstruck f99dc1d
Pop the keyboard
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package com.woocommerce.android.ui.payments.changeduecalculator | ||
|
||
import android.view.ViewGroup | ||
import android.view.inputmethod.InputMethodManager | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.Row | ||
|
@@ -9,6 +10,7 @@ import androidx.compose.foundation.layout.fillMaxSize | |
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.material.Button | ||
import androidx.compose.material.Icon | ||
import androidx.compose.material.IconButton | ||
import androidx.compose.material.LocalTextStyle | ||
|
@@ -20,8 +22,14 @@ import androidx.compose.material.TopAppBar | |
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.automirrored.filled.ArrowBack | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.colorResource | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.font.FontWeight | ||
|
@@ -38,8 +46,11 @@ import java.math.BigDecimal | |
@Composable | ||
fun ChangeDueCalculatorScreen( | ||
uiState: ChangeDueCalculatorViewModel.UiState, | ||
onNavigateUp: () -> Unit | ||
onNavigateUp: () -> Unit, | ||
onCompleteOrderClick: () -> Unit | ||
) { | ||
val context = LocalContext.current | ||
|
||
WooThemeWithBackground { | ||
Scaffold( | ||
topBar = { | ||
|
@@ -73,6 +84,17 @@ fun ChangeDueCalculatorScreen( | |
|
||
is ChangeDueCalculatorViewModel.UiState.Success -> { | ||
val hintString = stringResource(R.string.cash_payments_cash_received) | ||
var view: WCMaterialOutlinedCurrencyEditTextView? by remember { mutableStateOf(null) } | ||
|
||
LaunchedEffect(view) { | ||
view?.let { | ||
it.requestFocus() | ||
context.getSystemService( | ||
InputMethodManager::class.java | ||
).showSoftInput(it, InputMethodManager.SHOW_IMPLICIT) | ||
} | ||
} | ||
|
||
AndroidView( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In case you still would want to steak with AndroidView reuse here, I'd suggest to export that into a separate composable function for code simplification |
||
factory = { ctx -> | ||
WCMaterialOutlinedCurrencyEditTextView(ctx).apply { | ||
|
@@ -87,6 +109,7 @@ fun ChangeDueCalculatorScreen( | |
supportsNegativeValues = false | ||
hint = hintString | ||
setValueIfDifferent(uiState.amountDue) | ||
view = this | ||
} | ||
}, | ||
modifier = Modifier | ||
|
@@ -121,6 +144,11 @@ fun ChangeDueCalculatorScreen( | |
.padding(top = 16.dp, bottom = 16.dp, start = 16.dp) | ||
.fillMaxWidth() | ||
) | ||
|
||
MarkOrderAsCompleteButton( | ||
onClick = onCompleteOrderClick, | ||
modifier = Modifier.padding(top = 16.dp) | ||
) | ||
} | ||
|
||
is ChangeDueCalculatorViewModel.UiState.Error -> { | ||
|
@@ -137,9 +165,9 @@ fun ChangeDueCalculatorScreen( | |
|
||
@Composable | ||
fun RecordTransactionDetailsNote( | ||
modifier: Modifier = Modifier, | ||
checked: Boolean = false, | ||
onCheckedChange: (Boolean) -> Unit = {}, | ||
modifier: Modifier = Modifier | ||
) { | ||
Row( | ||
modifier = modifier.fillMaxWidth(), | ||
|
@@ -159,6 +187,18 @@ fun RecordTransactionDetailsNote( | |
} | ||
} | ||
|
||
@Composable | ||
fun MarkOrderAsCompleteButton(onClick: () -> Unit, modifier: Modifier = Modifier) { | ||
Button( | ||
kidinov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
onClick = onClick, | ||
modifier = modifier | ||
.fillMaxWidth() | ||
.padding(start = 16.dp, top = 8.dp, end = 16.dp) | ||
) { | ||
Text(text = stringResource(R.string.cash_payments_mark_order_as_complete)) | ||
} | ||
} | ||
|
||
@Composable | ||
private fun getTitleText(uiState: ChangeDueCalculatorViewModel.UiState): String { | ||
return when (uiState) { | ||
|
@@ -179,6 +219,7 @@ fun ChangeDueCalculatorScreenSuccessPreview() { | |
amountDue = BigDecimal("666.00"), | ||
change = BigDecimal("0.00") | ||
), | ||
onNavigateUp = {} | ||
onNavigateUp = {}, | ||
onCompleteOrderClick = {} | ||
) | ||
} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like this to work the same as
CustomAmountsFragment
and pop the num pad but for some reason I'm seeing the full keyboard.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered using
WCOutlinedTypedTextField
the same as they do inOrderCreateEditProductDiscountScreen
? There are quite a few advantages of not using "XML" views in compose, including that now preview doesn't workThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great suggestion. Indeed it broke the preview and I would prefer to use proper Compose views. I will change this today in this draft PR:
#11587