Skip to content

Commit

Permalink
Improved number input handling when configuring a wallet value widget.
Browse files Browse the repository at this point in the history
  • Loading branch information
hwki committed Nov 3, 2022
1 parent 87ec758 commit 235d458
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 13 deletions.
8 changes: 2 additions & 6 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,17 @@ android {
applicationId "com.brentpanther.bitcoinwidget"
minSdk 23
targetSdk 33
versionCode 314
versionName "8.3.4"
versionCode 315
versionName "8.3.5"

javaCompileOptions {
annotationProcessorOptions {
arguments += ["room.schemaLocation": "$projectDir/schemas".toString()]
}
}
vectorDrawables {
useSupportLibrary true
}
}

buildFeatures {
viewBinding true
compose true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SolidValueWidgetDisplayStrategy(context: Context, widget: Widget, widgetPr
amount = try {
DecimalFormat.getNumberInstance(Locale.getDefault()).run {
minimumFractionDigits = 0
maximumFractionDigits = 4
maximumFractionDigits = 8
format(widget.amountHeld)
}
} catch (e : Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import com.brentpanther.bitcoinwidget.exchange.Exchange
import com.brentpanther.bitcoinwidget.ui.BannersViewModel
import com.brentpanther.bitcoinwidget.ui.WarningBanner
import com.brentpanther.bitcoinwidget.ui.WidgetPreview
import java.text.DecimalFormat
import java.text.ParseException

@Composable
fun SettingsScreen(
Expand Down Expand Up @@ -156,6 +158,8 @@ fun BaseSettingsScreen(
@Composable
fun ValueSettings(widget: Widget, settingsPriceViewModel: SettingsViewModel) {
DataSection(settingsPriceViewModel, widget)
val numberInstance = DecimalFormat.getNumberInstance()
numberInstance.maximumFractionDigits = 40
SettingsEditText(
icon = {
Icon(painterResource(R.drawable.ic_outline_account_balance_wallet_24), null)
Expand All @@ -164,16 +168,18 @@ fun ValueSettings(widget: Widget, settingsPriceViewModel: SettingsViewModel) {
Text(stringResource(id = R.string.title_amount_held))
},
subtitle = {
Text(widget.amountHeld.toString())
Text(numberInstance.format(widget.amountHeld))
},
dialogText = {
Text(stringResource(R.string.dialog_amount_held, widget.coinName()))
},
value = widget.amountHeld.toString(),
onChange = {
it.toDoubleOrNull()?.apply {
settingsPriceViewModel.setAmountHeld(this)
}
try {
numberInstance.parse(it)?.apply {
settingsPriceViewModel.setAmountHeld(this.toDouble())
}
} catch (ignored: ParseException) {}
}
)
FormatSection(settingsPriceViewModel, widget)
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/src/main/res/raw/cryptowidgetcoins_v2.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bitcoin/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
<item>ISO</item>
<item>NONE</item>
</string-array>
<string name="json_last_modified" translatable="false">Sat, 17 Sep 2022 18:42:47 GMT</string>
<string name="json_last_modified" translatable="false">Thu, 03 Nov 2022 11:11:24 GMT</string>
<string name="json_url" translatable="false">https://www.brentpanther.com/cryptowidgetcoins_v2.json</string>

<string name="error_restricted_battery_saver">Unable to refresh, Battery Saver is on</string>
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/315.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improved number input handling when configuring a wallet value widget.

0 comments on commit 235d458

Please sign in to comment.