Skip to content

Commit 1c820cb

Browse files
committed
Improved number input handling when configuring a wallet value widget.
1 parent 235d458 commit 1c820cb

File tree

9 files changed

+32
-33
lines changed

9 files changed

+32
-33
lines changed

bitcoin/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId "com.brentpanther.bitcoinwidget"
1313
minSdk 23
1414
targetSdk 33
15-
versionCode 315
16-
versionName "8.3.5"
15+
versionCode 316
16+
versionName "8.3.6"
1717

1818
javaCompileOptions {
1919
annotationProcessorOptions {
@@ -80,7 +80,7 @@ dependencies {
8080
implementation 'androidx.activity:activity-compose:1.6.1'
8181
implementation "androidx.compose.ui:ui:$compose_ui_version"
8282
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
83-
implementation 'androidx.compose.material:material:1.3.0'
83+
implementation 'androidx.compose.material:material:1.3.1'
8484
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1"
8585
implementation 'androidx.navigation:navigation-compose:2.5.3'
8686
implementation "io.coil-kt:coil-compose:2.2.2"

bitcoin/src/main/java/com/brentpanther/bitcoinwidget/exchange/Exchange.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -333,18 +333,6 @@ enum class Exchange(val exchangeName: String, shortName: String? = null) {
333333
return getJsonObject(url).getAsJsonObject(pair).get("last_trade").asString
334334
}
335335
},
336-
FTX("FTX") {
337-
override fun getValue(coin: String, currency: String): String {
338-
val url = "https://ftx.com/api/markets/$coin/$currency"
339-
return getJsonObject(url).getAsJsonObject("result").get("last").asString
340-
}
341-
},
342-
FTX_US("FTX US") {
343-
override fun getValue(coin: String, currency: String): String {
344-
val url = "https://ftx.us/api/markets/$coin/$currency"
345-
return getJsonObject(url).getAsJsonObject("result").get("last").asString
346-
}
347-
},
348336
FOXBIT("FoxBit") {
349337

350338
override fun getValue(coin: String, currency: String): String? {

bitcoin/src/main/java/com/brentpanther/bitcoinwidget/ui/settings/SettingsScreen.kt

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ import com.brentpanther.bitcoinwidget.ui.BannersViewModel
3131
import com.brentpanther.bitcoinwidget.ui.WarningBanner
3232
import com.brentpanther.bitcoinwidget.ui.WidgetPreview
3333
import java.text.DecimalFormat
34+
import java.text.DecimalFormatSymbols
3435
import java.text.ParseException
36+
import java.util.*
3537

3638
@Composable
3739
fun SettingsScreen(
@@ -171,15 +173,30 @@ fun ValueSettings(widget: Widget, settingsPriceViewModel: SettingsViewModel) {
171173
Text(numberInstance.format(widget.amountHeld))
172174
},
173175
dialogText = {
174-
Text(stringResource(R.string.dialog_amount_held, widget.coinName()))
176+
Text(stringResource(R.string.dialog_amount_held, widget.coinName(), numberInstance.format(1.23)))
175177
},
176-
value = widget.amountHeld.toString(),
178+
value = numberInstance.format(widget.amountHeld),
177179
onChange = {
178180
try {
179-
numberInstance.parse(it)?.apply {
180-
settingsPriceViewModel.setAmountHeld(this.toDouble())
181+
// do not assume numbers are being input in the current system locale.
182+
val groupingSeparator = DecimalFormatSymbols.getInstance().groupingSeparator
183+
val decimalSeparator = DecimalFormatSymbols.getInstance().decimalSeparator
184+
val parsed = if (it.contains(groupingSeparator) && it.contains(decimalSeparator)) {
185+
// parse in system locale
186+
numberInstance.parse(it)?.toDouble()
187+
} else if (it.contains(".")) {
188+
// parse in english
189+
DecimalFormat.getNumberInstance(Locale.ENGLISH).parse(it)?.toDouble()
190+
} else {
191+
// parse in system locale
192+
numberInstance.parse(it)?.toDouble()
181193
}
182-
} catch (ignored: ParseException) {}
194+
parsed?.apply {
195+
settingsPriceViewModel.setAmountHeld(this)
196+
}
197+
} catch (ignored: ParseException) {
198+
}
199+
183200
}
184201
)
185202
FormatSection(settingsPriceViewModel, widget)

bitcoin/src/main/res/raw/cryptowidgetcoins_v2.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

bitcoin/src/main/res/values-pt-rBR/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
<string name="state_error">Não foi possível atualizar o preço. Isso pode ser um problema com a exchange.</string>
8787
<string name="widget_price_name">Preço Atual</string>
8888
<string name="widget_value_name">Valor da carteiral</string>
89-
<string name="dialog_amount_held">Quanto %s você tem atualmente?</string>
89+
<string name="dialog_amount_held">Insira a quantia de %1$s mantida em sua carteira. Por exemplo, %2$s.</string>
9090
<string name="add_value_widget">Adicionar widget de valor da carteira</string>
9191
<string name="add_price_widget">Adicionar widget de valor atual</string>
9292
<string name="widget_price_summary">Mostra o preço de negociação atual do %s.</string>

bitcoin/src/main/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<string name="placeholder_price" translatable="false">$-,---</string>
125125
<string name="widget_price_name">Current Price</string>
126126
<string name="widget_value_name">Wallet Value</string>
127-
<string name="dialog_amount_held">How much %s in your wallet?</string>
127+
<string name="dialog_amount_held">Enter the amount of %1$s held in your wallet. e.g. %2$s</string>
128128
<string name="add_value_widget">Add Wallet Value Widget</string>
129129
<string name="add_price_widget">Add Current Value Widget</string>
130130
<string name="widget_price_summary">Shows the current %s trading price.</string>

bitcoin/src/test/java/com/brentpanther/bitcoinwidget/GenerateSupportedCoinsJson.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class GenerateSupportedCoinsJson {
3737
this::btcbox, this::btcmarkets, this::btcturk, this::bybit, this::cexio,
3838
this::chilebit, this::coinbase, this::coinbasepro, this::coindesk, this::coingecko,
3939
this::coinjar, this::coinmate, this::coinone, this::coinsbit, this::coinsph, this::cointree,
40-
this::cryptocom, this::deversifi, this::digifinex, this::exmo, this::ftx, this::ftx_us, this::foxbit, this::gateio, this::gemini,
40+
this::cryptocom, this::deversifi, this::digifinex, this::exmo, this::foxbit, this::gateio, this::gemini,
4141
this::hitbtc, this::huobi, this::independent_reserve, this::indodax, this::itbit, this::korbit, this::kraken, this::kucoin,
4242
this::kuna, this::lbank, this::liquid, this::luno, this::mercado, this::mexc, this::ndax,
4343
this::nexchange, this::okcoin, this::okx, this::p2pb2b, this::paribu, this::paymium, this::phemex,
@@ -251,6 +251,7 @@ class GenerateSupportedCoinsJson {
251251
return parse("https://big.one/api/v3/asset_pairs", "$.data[*].name")
252252
}
253253

254+
// no longer allows access from US
254255
private fun binance(): List<String> {
255256
return parse("https://api.binance.com/api/v3/exchangeInfo", "$.symbols[*].symbol")
256257
}
@@ -449,14 +450,6 @@ class GenerateSupportedCoinsJson {
449450
return parseKeys("https://api.exmo.com/v1.1/ticker", "$")
450451
}
451452

452-
private fun ftx(): List<String> {
453-
return parse("https://ftx.com/api/markets", "$.result[*].name")
454-
}
455-
456-
private fun ftx_us(): List<String> {
457-
return parse("https://ftx.us/api/markets", "$.result[*].name")
458-
}
459-
460453
private fun foxbit(): List<String> {
461454
return parse("https://watcher.foxbit.com.br/api/Ticker/", "$[?(@.exchange == 'Foxbit')].currency").map {
462455
it.replaceFirst("X", "_").split("_").reversed().joinToString("_")

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
buildscript {
44
ext {
5-
compose_ui_version = '1.3.0'
5+
compose_ui_version = '1.3.2'
66
compose_compiler_version = '1.3.1'
77
}
88
ext.kotlin_version = '1.7.10'
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improved number input handling when configuring a wallet value widget.

0 commit comments

Comments
 (0)