Fix and improve currency related stuff

realmasync
Laurent 3 years ago
parent b316d32850
commit 51bb26f331
  1. 46
      app/src/main/java/net/pokeranalytics/android/ui/fragment/CurrenciesFragment.kt
  2. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SettingsFragment.kt
  3. 2
      app/src/main/java/net/pokeranalytics/android/ui/modules/data/BankrollDataFragment.kt

@ -45,27 +45,46 @@ class CurrenciesFragment : BaseFragment(), StaticRowRepresentableDataSource, Row
) )
} }
private val availableCurrencies = this.systemCurrencies.filter { private val availableCurrencies =
!mostUsedCurrencyCodes.contains(it.currencyCode) Locale.getAvailableLocales()
}.filter { .mapNotNull {
UserDefaults.availableCurrencyLocales.filter { currencyLocale -> try {
Currency.getInstance(it)
} catch (e: Exception) {
null
}
}.toSet()
.filter { !mostUsedCurrencyCodes.contains(it.currencyCode) }
.filter {
UserDefaults.availableCurrencyLocales.any { currencyLocale ->
Currency.getInstance(currencyLocale).currencyCode == it.currencyCode Currency.getInstance(currencyLocale).currencyCode == it.currencyCode
}.isNotEmpty()
}.sortedBy {
it.displayName
}.map {
CurrencyRow(it)
} }
} }
.sortedBy { it.displayName }
.map { CurrencyRow(it) }
// private val availableCurrencies = this.systemCurrencies.filter {
// !mostUsedCurrencyCodes.contains(it.currencyCode)
// }.filter {
// UserDefaults.availableCurrencyLocales.filter { currencyLocale ->
// Currency.getInstance(currencyLocale).currencyCode == it.currencyCode
// }.isNotEmpty()
// }.sortedBy {
// it.displayName
// }.map {
// CurrencyRow(it)
// }
}
private class CurrencyRow(var currency: Currency) : RowRepresentable { private class CurrencyRow(var currency: Currency) : RowRepresentable {
override fun getDisplayName(context: Context): String { override fun getDisplayName(context: Context): String {
return currency.getDisplayName(Locale.getDefault()).capitalize() return this.currency.getDisplayName(Locale.getDefault()).capitalize()
} }
var currencyCode: String = currency.currencyCode var currencyCode: String = this.currency.currencyCode
var currencySymbol: String = currency.getSymbol(Locale.getDefault()) var currencySymbol: String = this.currency.getSymbol(Locale.getDefault())
var currencyCodeAndSymbol: String = "${this.currencyCode} (${this.currencySymbol})" var currencyCodeAndSymbol: String = "${this.currencyCode} (${this.currencySymbol})"
override val viewType: Int = RowViewType.TITLE_VALUE.ordinal override val viewType: Int = RowViewType.TITLE_VALUE.ordinal
@ -110,9 +129,6 @@ class CurrenciesFragment : BaseFragment(), StaticRowRepresentableDataSource, Row
// RowRepresentableDelegate // RowRepresentableDelegate
override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) { override fun onRowSelected(position: Int, row: RowRepresentable, tag: Int) {
val intent = Intent() val intent = Intent()
intent.putExtra(INTENT_CURRENCY_CODE, (row as CurrencyRow).currency.currencyCode) intent.putExtra(INTENT_CURRENCY_CODE, (row as CurrencyRow).currency.currencyCode)
this.activity?.setResult(Activity.RESULT_OK, intent) this.activity?.setResult(Activity.RESULT_OK, intent)

@ -156,7 +156,7 @@ class SettingsFragment : RealmFragment(), RowRepresentableDelegate, StaticRowRep
private fun updateMainCurrency(currencyCode: String) { private fun updateMainCurrency(currencyCode: String) {
Preferences.getDefaultCurrency(requireContext())?.currencyCode?.let { mainCurrencyCode -> val mainCurrencyCode = UserDefaults.currency.currencyCode
if (mainCurrencyCode == currencyCode) { if (mainCurrencyCode == currencyCode) {
return return
@ -178,7 +178,6 @@ class SettingsFragment : RealmFragment(), RowRepresentableDelegate, StaticRowRep
} }
} }
}
} }

@ -85,6 +85,8 @@ class BankrollDataFragment : EditableDataFragment(), StaticRowRepresentableDataS
onRowValueChanged(currencyCode, BankrollPropertiesRow.CURRENCY) onRowValueChanged(currencyCode, BankrollPropertiesRow.CURRENCY)
if (shouldShowCurrencyRate) { if (shouldShowCurrencyRate) {
refreshRate() refreshRate()
} else {
this.bankroll.currency?.rate = 1.0
} }
} }
} }

Loading…
Cancel
Save