-
Notifications
You must be signed in to change notification settings - Fork 3
fix: align currency and calc widget with ios #884
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
29 commits
Select commit
Hold shift + click to select a range
0b79d78
fix: align currency and calc widget with ios
piotr-iohk 64e4eed
doc: changelog entry
piotr-iohk 902e3f0
fix: sanitize calculator keyboard input
piotr-iohk 1c9e0ee
Merge branch 'master' into fix/currency-widget-consistency-881
piotr-iohk c4d651e
fix: stabilize calculator widget input
piotr-iohk e57d0e8
Update app/src/main/java/to/bitkit/ui/screens/widgets/calculator/comp…
piotr-iohk ab7f801
Merge branch 'master' into fix/currency-widget-consistency-881
piotr-iohk d365996
Merge branch 'master' into fix/currency-widget-consistency-881
piotr-iohk 044cd74
Merge branch 'master' into fix/currency-widget-consistency-881
jvsena42 6172c82
chore: lint
jvsena42 43eba3a
fix: use raw text for offset mapping wile still formatting from the s…
jvsena42 33eb984
fix: update fiat value on currency change
jvsena42 837ccf4
fix: remove duplicated changelog entry
jvsena42 3410fad
fix: clear cached input values on widget delete
jvsena42 0cdbc47
fix: add a guard for empty inputs
jvsena42 6cc693e
Merge branch 'master' into fix/currency-widget-consistency-881
jvsena42 230097e
Merge branch 'master' into fix/currency-widget-consistency-881
jvsena42 95f0beb
dix: fix changelog entry
jvsena42 a632a4e
Merge branch 'master' into fix/currency-widget-consistency-881
jvsena42 4efd824
Merge branch 'master' into fix/currency-widget-consistency-881
jvsena42 9805949
doc: migrate changelog entry to fragment changelog pattern
jvsena42 dc4e55d
Merge branch 'master' into fix/currency-widget-consistency-881
jvsena42 e1e9f52
test: update tests with locale
jvsena42 71ddf06
fix: sanitize calc widget input across locales
jvsena42 365ffec
fix: locale parameter
jvsena42 d36222f
fix: leading zeros logic and update tests
jvsena42 8ad326f
Merge branch 'master' into fix/currency-widget-consistency-881
jvsena42 ad709ef
Merge branch 'master' into fix/currency-widget-consistency-881
ovitrif fa9474a
Merge branch 'master' into fix/currency-widget-consistency-881
ovitrif 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,8 @@ import to.bitkit.ui.components.TextInput | |
| import to.bitkit.ui.theme.AppTextFieldDefaults | ||
| import to.bitkit.ui.theme.AppThemeSurface | ||
| import to.bitkit.ui.theme.Colors | ||
| import java.text.DecimalFormatSymbols | ||
| import java.util.Locale | ||
|
|
||
| @Composable | ||
| fun CalculatorInput( | ||
|
|
@@ -31,8 +33,11 @@ fun CalculatorInput( | |
| currencySymbol: String, | ||
| currencyName: String, | ||
| modifier: Modifier = Modifier, | ||
| keyboardType: KeyboardType = KeyboardType.Number, | ||
| visualTransformation: VisualTransformation = VisualTransformation.None, | ||
| ) { | ||
| val displayCurrencySymbol = currencySymbol.toCalculatorDisplaySymbol() | ||
|
|
||
| TextInput( | ||
| value = value, | ||
| singleLine = true, | ||
|
|
@@ -44,11 +49,11 @@ fun CalculatorInput( | |
| .background(color = Colors.Gray6, shape = CircleShape) | ||
| .size(32.dp) | ||
| ) { | ||
| BodyMSB(currencySymbol, color = Colors.Brand) | ||
| BodyMSB(displayCurrencySymbol, color = Colors.Brand) | ||
| } | ||
| }, | ||
| keyboardOptions = KeyboardOptions( | ||
| keyboardType = KeyboardType.Number | ||
| keyboardType = keyboardType, | ||
| ), | ||
| suffix = { CaptionB(currencyName.uppercase(), color = Colors.Gray1) }, | ||
| colors = AppTextFieldDefaults.noIndicatorColors.copy( | ||
|
|
@@ -60,6 +65,44 @@ fun CalculatorInput( | |
| ) | ||
| } | ||
|
|
||
| internal fun sanitizeIntegerInput(raw: String): String { | ||
| val digits = raw.filter { it.isDigit() } | ||
| if (digits.isEmpty()) return digits | ||
| return digits.trimStart('0').ifEmpty { "0" } | ||
| } | ||
|
|
||
| internal fun sanitizeDecimalInput( | ||
| raw: String, | ||
| locale: Locale = Locale.getDefault(), | ||
| maxDecimalPlaces: Int? = null, | ||
| ): String { | ||
| val localDecimal = DecimalFormatSymbols.getInstance(locale).decimalSeparator | ||
| val normalized = if (localDecimal == ',') raw.replace(',', '.') else raw | ||
| val filtered = normalized.filter { it.isDigit() || it == '.' } | ||
| val dotIndex = filtered.indexOf('.') | ||
| val singleDot = if (dotIndex == -1) { | ||
| filtered | ||
| } else { | ||
| filtered.substring(0, dotIndex + 1) + | ||
| filtered.substring(dotIndex + 1).replace(".", "") | ||
| } | ||
| if (maxDecimalPlaces == null) return singleDot | ||
| val cappedDot = singleDot.indexOf('.') | ||
| if (cappedDot == -1) return singleDot | ||
| val fraction = singleDot.substring(cappedDot + 1) | ||
| if (fraction.length <= maxDecimalPlaces) return singleDot | ||
| return singleDot.substring(0, cappedDot + 1) + fraction.take(maxDecimalPlaces) | ||
| } | ||
|
Comment on lines
+74
to
+95
Collaborator
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. nit: would've been nice to add unit tests, even if it's low complexity, it's still logic. |
||
|
|
||
| internal fun String.toCalculatorDisplaySymbol(): String { | ||
| val symbol = trim() | ||
| return if (symbol.length >= 3) { | ||
| symbol.take(1) | ||
| } else { | ||
| symbol | ||
| } | ||
| } | ||
|
|
||
| @Preview(showBackground = true) | ||
| @Composable | ||
| private fun Preview() { | ||
|
|
||
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.