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 Dec 11, 2022
1 parent 235d458 commit 1c820cb
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 33 deletions.
6 changes: 3 additions & 3 deletions bitcoin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId "com.brentpanther.bitcoinwidget"
minSdk 23
targetSdk 33
versionCode 315
versionName "8.3.5"
versionCode 316
versionName "8.3.6"

javaCompileOptions {
annotationProcessorOptions {
Expand Down Expand Up @@ -80,7 +80,7 @@ dependencies {
implementation 'androidx.activity:activity-compose:1.6.1'
implementation "androidx.compose.ui:ui:$compose_ui_version"
implementation "androidx.compose.ui:ui-tooling-preview:$compose_ui_version"
implementation 'androidx.compose.material:material:1.3.0'
implementation 'androidx.compose.material:material:1.3.1'
implementation "androidx.lifecycle:lifecycle-viewmodel-compose:2.5.1"
implementation 'androidx.navigation:navigation-compose:2.5.3'
implementation "io.coil-kt:coil-compose:2.2.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,18 +333,6 @@ enum class Exchange(val exchangeName: String, shortName: String? = null) {
return getJsonObject(url).getAsJsonObject(pair).get("last_trade").asString
}
},
FTX("FTX") {
override fun getValue(coin: String, currency: String): String {
val url = "https://ftx.com/api/markets/$coin/$currency"
return getJsonObject(url).getAsJsonObject("result").get("last").asString
}
},
FTX_US("FTX US") {
override fun getValue(coin: String, currency: String): String {
val url = "https://ftx.us/api/markets/$coin/$currency"
return getJsonObject(url).getAsJsonObject("result").get("last").asString
}
},
FOXBIT("FoxBit") {

override fun getValue(coin: String, currency: String): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ 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.DecimalFormatSymbols
import java.text.ParseException
import java.util.*

@Composable
fun SettingsScreen(
Expand Down Expand Up @@ -171,15 +173,30 @@ fun ValueSettings(widget: Widget, settingsPriceViewModel: SettingsViewModel) {
Text(numberInstance.format(widget.amountHeld))
},
dialogText = {
Text(stringResource(R.string.dialog_amount_held, widget.coinName()))
Text(stringResource(R.string.dialog_amount_held, widget.coinName(), numberInstance.format(1.23)))
},
value = widget.amountHeld.toString(),
value = numberInstance.format(widget.amountHeld),
onChange = {
try {
numberInstance.parse(it)?.apply {
settingsPriceViewModel.setAmountHeld(this.toDouble())
// do not assume numbers are being input in the current system locale.
val groupingSeparator = DecimalFormatSymbols.getInstance().groupingSeparator
val decimalSeparator = DecimalFormatSymbols.getInstance().decimalSeparator
val parsed = if (it.contains(groupingSeparator) && it.contains(decimalSeparator)) {
// parse in system locale
numberInstance.parse(it)?.toDouble()
} else if (it.contains(".")) {
// parse in english
DecimalFormat.getNumberInstance(Locale.ENGLISH).parse(it)?.toDouble()
} else {
// parse in system locale
numberInstance.parse(it)?.toDouble()
}
} catch (ignored: ParseException) {}
parsed?.apply {
settingsPriceViewModel.setAmountHeld(this)
}
} 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-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
<string name="state_error">Não foi possível atualizar o preço. Isso pode ser um problema com a exchange.</string>
<string name="widget_price_name">Preço Atual</string>
<string name="widget_value_name">Valor da carteiral</string>
<string name="dialog_amount_held">Quanto %s você tem atualmente?</string>
<string name="dialog_amount_held">Insira a quantia de %1$s mantida em sua carteira. Por exemplo, %2$s.</string>
<string name="add_value_widget">Adicionar widget de valor da carteira</string>
<string name="add_price_widget">Adicionar widget de valor atual</string>
<string name="widget_price_summary">Mostra o preço de negociação atual do %s.</string>
Expand Down
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 @@ -124,7 +124,7 @@
<string name="placeholder_price" translatable="false">$-,---</string>
<string name="widget_price_name">Current Price</string>
<string name="widget_value_name">Wallet Value</string>
<string name="dialog_amount_held">How much %s in your wallet?</string>
<string name="dialog_amount_held">Enter the amount of %1$s held in your wallet. e.g. %2$s</string>
<string name="add_value_widget">Add Wallet Value Widget</string>
<string name="add_price_widget">Add Current Value Widget</string>
<string name="widget_price_summary">Shows the current %s trading price.</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GenerateSupportedCoinsJson {
this::btcbox, this::btcmarkets, this::btcturk, this::bybit, this::cexio,
this::chilebit, this::coinbase, this::coinbasepro, this::coindesk, this::coingecko,
this::coinjar, this::coinmate, this::coinone, this::coinsbit, this::coinsph, this::cointree,
this::cryptocom, this::deversifi, this::digifinex, this::exmo, this::ftx, this::ftx_us, this::foxbit, this::gateio, this::gemini,
this::cryptocom, this::deversifi, this::digifinex, this::exmo, this::foxbit, this::gateio, this::gemini,
this::hitbtc, this::huobi, this::independent_reserve, this::indodax, this::itbit, this::korbit, this::kraken, this::kucoin,
this::kuna, this::lbank, this::liquid, this::luno, this::mercado, this::mexc, this::ndax,
this::nexchange, this::okcoin, this::okx, this::p2pb2b, this::paribu, this::paymium, this::phemex,
Expand Down Expand Up @@ -251,6 +251,7 @@ class GenerateSupportedCoinsJson {
return parse("https://big.one/api/v3/asset_pairs", "$.data[*].name")
}

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

private fun ftx(): List<String> {
return parse("https://ftx.com/api/markets", "$.result[*].name")
}

private fun ftx_us(): List<String> {
return parse("https://ftx.us/api/markets", "$.result[*].name")
}

private fun foxbit(): List<String> {
return parse("https://watcher.foxbit.com.br/api/Ticker/", "$[?(@.exchange == 'Foxbit')].currency").map {
it.replaceFirst("X", "_").split("_").reversed().joinToString("_")
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

buildscript {
ext {
compose_ui_version = '1.3.0'
compose_ui_version = '1.3.2'
compose_compiler_version = '1.3.1'
}
ext.kotlin_version = '1.7.10'
Expand Down
1 change: 1 addition & 0 deletions fastlane/metadata/android/en-US/changelogs/316.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 1c820cb

Please sign in to comment.