Implemented displaying currency of amount of money

This commit is contained in:
dankito 2020-09-24 23:23:03 +02:00
parent 415a3297bb
commit f03480945e
15 changed files with 357 additions and 16 deletions

View File

@ -42,7 +42,7 @@ open class AccountTransactionAdapter(protected val presenter: BankingPresenter)
viewHolder.txtvwReference.text = item.reference viewHolder.txtvwReference.text = item.reference
viewHolder.txtvwAmount.showAmount(presenter, item.amount) viewHolder.txtvwAmount.showAmount(presenter, item.amount, item.currency)
val iconUrl = item.account.bank.iconUrl val iconUrl = item.account.bank.iconUrl
if (iconUrl != null && presenter.areAllAccountSelected) { if (iconUrl != null && presenter.areAllAccountSelected) {

View File

@ -18,6 +18,7 @@ import net.dankito.banking.bankfinder.LuceneBankFinder
import net.dankito.banking.persistence.RoomBankingPersistence import net.dankito.banking.persistence.RoomBankingPersistence
import net.dankito.banking.persistence.model.RoomModelCreator import net.dankito.banking.persistence.model.RoomModelCreator
import net.dankito.banking.ui.model.mapper.IModelCreator import net.dankito.banking.ui.model.mapper.IModelCreator
import net.dankito.banking.ui.util.CurrencyInfoProvider
import net.dankito.utils.multiplatform.toFile import net.dankito.utils.multiplatform.toFile
import net.dankito.banking.util.* import net.dankito.banking.util.*
import net.dankito.banking.util.extraction.* import net.dankito.banking.util.extraction.*
@ -91,7 +92,7 @@ class BankingModule(private val applicationContext: Context) {
textExtractorRegistry: ITextExtractorRegistry, router: IRouter, invoiceDataExtractor: IInvoiceDataExtractor, textExtractorRegistry: ITextExtractorRegistry, router: IRouter, invoiceDataExtractor: IInvoiceDataExtractor,
modelCreator: IModelCreator, serializer: ISerializer, asyncRunner: IAsyncRunner) : BankingPresenter { modelCreator: IModelCreator, serializer: ISerializer, asyncRunner: IAsyncRunner) : BankingPresenter {
return BankingPresenter(bankingClientCreator, bankFinder, dataFolder, persister, router, modelCreator, return BankingPresenter(bankingClientCreator, bankFinder, dataFolder, persister, router, modelCreator,
transactionPartySearcher, bankIconFinder, textExtractorRegistry, invoiceDataExtractor, serializer, asyncRunner) transactionPartySearcher, bankIconFinder, textExtractorRegistry, invoiceDataExtractor, CurrencyInfoProvider(), serializer, asyncRunner)
} }
@Provides @Provides

View File

@ -7,8 +7,8 @@ import net.dankito.utils.android.extensions.setTextColorToColorResource
import net.dankito.utils.multiplatform.BigDecimal import net.dankito.utils.multiplatform.BigDecimal
fun TextView.showAmount(presenter: BankingPresenter, amount: BigDecimal) { fun TextView.showAmount(presenter: BankingPresenter, amount: BigDecimal, currencyIsoCode: String? = null) {
text = presenter.formatAmount(amount) text = presenter.formatAmount(amount, currencyIsoCode)
setTextColorForAmount(amount) setTextColorForAmount(amount)
} }

View File

@ -105,7 +105,7 @@ open class AccountTransactionsTable @JvmOverloads constructor(
cellValueFactory = Callback { object : ObjectBinding<String>() { cellValueFactory = Callback { object : ObjectBinding<String>() {
override fun computeValue(): String { override fun computeValue(): String {
return presenter.formatAmount(it.value.amount) + " " + it.value.currency return presenter.formatAmount(it.value.amount, it.value.currency)
} }
} } } }

View File

@ -22,6 +22,9 @@ import net.dankito.banking.ui.model.moneytransfer.ExtractTransferMoneyDataFromPd
import net.dankito.banking.ui.model.parameters.GetTransactionsParameter import net.dankito.banking.ui.model.parameters.GetTransactionsParameter
import net.dankito.banking.ui.model.settings.AppSettings import net.dankito.banking.ui.model.settings.AppSettings
import net.dankito.banking.ui.model.tan.* import net.dankito.banking.ui.model.tan.*
import net.dankito.banking.ui.util.CurrencyInfo
import net.dankito.banking.ui.util.CurrencyInfoProvider
import net.dankito.banking.ui.util.ICurrencyInfoProvider
import net.dankito.banking.util.* import net.dankito.banking.util.*
import net.dankito.banking.util.extraction.IInvoiceDataExtractor import net.dankito.banking.util.extraction.IInvoiceDataExtractor
import net.dankito.banking.util.extraction.ITextExtractorRegistry import net.dankito.banking.util.extraction.ITextExtractorRegistry
@ -30,6 +33,7 @@ import net.dankito.banking.util.extraction.NoOpTextExtractorRegistry
import net.dankito.utils.multiplatform.* import net.dankito.utils.multiplatform.*
import net.dankito.utils.multiplatform.log.LoggerFactory import net.dankito.utils.multiplatform.log.LoggerFactory
import kotlin.collections.ArrayList import kotlin.collections.ArrayList
import kotlin.jvm.JvmOverloads
open class BankingPresenter( open class BankingPresenter(
@ -43,6 +47,7 @@ open class BankingPresenter(
protected val bankIconFinder: IBankIconFinder = NoOpBankIconFinder(), protected val bankIconFinder: IBankIconFinder = NoOpBankIconFinder(),
protected val textExtractorRegistry: ITextExtractorRegistry = NoOpTextExtractorRegistry(), protected val textExtractorRegistry: ITextExtractorRegistry = NoOpTextExtractorRegistry(),
protected val invoiceDataExtractor: IInvoiceDataExtractor = NoOpInvoiceDataExtractor(), protected val invoiceDataExtractor: IInvoiceDataExtractor = NoOpInvoiceDataExtractor(),
protected val currencyInfoProvider: ICurrencyInfoProvider = CurrencyInfoProvider(),
protected val serializer: ISerializer = NoOpSerializer(), protected val serializer: ISerializer = NoOpSerializer(),
protected val asyncRunner: IAsyncRunner = CoroutinesAsyncRunner() protected val asyncRunner: IAsyncRunner = CoroutinesAsyncRunner()
) { ) {
@ -412,8 +417,15 @@ open class BankingPresenter(
} }
open fun formatAmount(amount: BigDecimal): String { @JvmOverloads
return amount.format(2) open fun formatAmount(amount: BigDecimal, currencyIsoCode: String? = null): String {
val isoCode = currencyIsoCode ?: currencyIsoCodeOfSelectedAccounts
return formatAmount(amount, currencyInfoProvider.getInfoForIsoCode(isoCode) ?: currencyInfoProvider.userDefaultCurrencyInfo)
}
open fun formatAmount(amount: BigDecimal, currencyInfo: CurrencyInfo): String {
return amount.format(currencyInfo.defaultFractionDigits) + " " + currencyInfo.symbol
} }
@ -642,6 +654,12 @@ open class BankingPresenter(
open val balanceOfSelectedAccounts: BigDecimal open val balanceOfSelectedAccounts: BigDecimal
get() = sumBalance(selectedAccounts.map { it.balance }) get() = sumBalance(selectedAccounts.map { it.balance })
open val currencyIsoCodeOfSelectedAccounts: String
get() = currencyIsoCodeOfAccounts(selectedAccounts)
open val currencySymbolOfSelectedAccounts: String
get() = currencyInfoProvider.getCurrencySymbolForIsoCodeOrEuro(currencyIsoCodeOfSelectedAccounts)
open val selectedAccountsForWhichNotAllTransactionsHaveBeenFetched: List<TypedBankAccount> open val selectedAccountsForWhichNotAllTransactionsHaveBeenFetched: List<TypedBankAccount>
get() = selectedAccounts.filter { it.haveAllTransactionsBeenRetrieved == false } get() = selectedAccounts.filter { it.haveAllTransactionsBeenRetrieved == false }
@ -745,6 +763,11 @@ open class BankingPresenter(
protected open fun getTransactionsForAccounts(accounts: Collection<TypedBankAccount>): List<IAccountTransaction> { protected open fun getTransactionsForAccounts(accounts: Collection<TypedBankAccount>): List<IAccountTransaction> {
return accounts.flatMap { it.bookedTransactions }.sortedByDescending { it.valueDate.millisSinceEpoch } // TODO: someday add unbooked transactions return accounts.flatMap { it.bookedTransactions }.sortedByDescending { it.valueDate.millisSinceEpoch } // TODO: someday add unbooked transactions
} }
open fun currencyIsoCodeOfAccounts(accounts: List<TypedBankAccount>): String {
// TODO: this is of course not right, it assumes that all accounts have the same currency. But we don't support e.g. calculating the balance of accounts with different currencies anyway
// at start up list with selectedAccounts is empty
return accounts.firstOrNull()?.currency ?: currencyInfoProvider.userDefaultCurrencyInfo.isoCode
}
protected open fun getAccountsTransactionRetrievalState(accounts: List<TypedBankAccount>): TransactionsRetrievalState { protected open fun getAccountsTransactionRetrievalState(accounts: List<TypedBankAccount>): TransactionsRetrievalState {
val states = accounts.map { getAccountTransactionRetrievalState(it) } val states = accounts.map { getAccountTransactionRetrievalState(it) }

View File

@ -0,0 +1,16 @@
package net.dankito.banking.ui.util
open class CurrencyInfo(
open val displayName: String,
open val isoCode: String,
open val numericCode: Int,
open val symbol: String,
open val defaultFractionDigits: Int
) {
override fun toString(): String {
return "$isoCode $displayName"
}
}

View File

@ -0,0 +1,270 @@
package net.dankito.banking.ui.util
open class CurrencyInfoProvider : ICurrencyInfoProvider {
companion object {
// extracted from JVM 8 // TODO: may use the list from Joda Money
val infos = listOf(
CurrencyInfo("Luxembourgian Franc", "LUF", 442, "LUF", 0),
CurrencyInfo("Serbian Dinar (20022006)", "CSD", 891, "CSD", 2),
CurrencyInfo("French Franc", "FRF", 250, "FRF", 2),
CurrencyInfo("Albanian Lek", "ALL", 8, "ALL", 2),
CurrencyInfo("Iraqi Dinar", "IQD", 368, "IQD", 3),
CurrencyInfo("Bulgarian Hard Lev", "BGL", 100, "BGL", 2),
CurrencyInfo("Sierra Leonean Leone", "SLL", 694, "SLL", 2),
CurrencyInfo("Guinea-Bissau Peso", "GWP", 624, "GWP", 2),
CurrencyInfo("Turkish Lira", "TRY", 949, "TRY", 2),
CurrencyInfo("Belgian Franc", "BEF", 56, "BEF", 0),
CurrencyInfo("Haitian Gourde", "HTG", 332, "HTG", 2),
CurrencyInfo("Thai Baht", "THB", 764, "THB", 2),
CurrencyInfo("Bahraini Dinar", "BHD", 48, "BHD", 3),
CurrencyInfo("Sudanese Pound", "SDG", 938, "SDG", 2),
CurrencyInfo("Chinese Yuan", "CNY", 156, "CN¥", 2),
CurrencyInfo("Mozambican Metical (19802006)", "MZM", 508, "MZM", 2),
CurrencyInfo("Maldivian Rufiyaa", "MVR", 462, "MVR", 2),
CurrencyInfo("Austrian Schilling", "ATS", 40, "ATS", 2),
CurrencyInfo("Bosnia-Herzegovina Convertible Mark", "BAM", 977, "BAM", 2),
CurrencyInfo("Afghan Afghani", "AFN", 971, "AFN", 2),
CurrencyInfo("Sucre", "XSU", 994, "XSU", -1),
CurrencyInfo("East Caribbean Dollar", "XCD", 951, "EC$", 2),
CurrencyInfo("Finnish Markka", "FIM", 246, "FIM", 2),
CurrencyInfo("Platinum", "XPT", 962, "XPT", -1),
CurrencyInfo("Cuban Convertible Peso", "CUC", 931, "CUC", 2),
CurrencyInfo("Zambian Kwacha", "ZMW", 967, "ZMW", 2),
CurrencyInfo("Norwegian Krone", "NOK", 578, "NOK", 2),
CurrencyInfo("Mozambican Metical", "MZN", 943, "MZN", 2),
CurrencyInfo("Swedish Krona", "SEK", 752, "SEK", 2),
CurrencyInfo("Paraguayan Guarani", "PYG", 600, "PYG", 0),
CurrencyInfo("United Arab Emirates Dirham", "AED", 784, "AED", 2),
CurrencyInfo("Nepalese Rupee", "NPR", 524, "NPR", 2),
CurrencyInfo("Nigerian Naira", "NGN", 566, "NGN", 2),
CurrencyInfo("Congolese Franc", "CDF", 976, "CDF", 2),
CurrencyInfo("Laotian Kip", "LAK", 418, "LAK", 2),
CurrencyInfo("Cape Verdean Escudo", "CVE", 132, "CVE", 2),
CurrencyInfo("French Gold Franc", "XFO", 0, "XFO", -1),
CurrencyInfo("Timorese Escudo", "TPE", 626, "TPE", 0),
CurrencyInfo("Zimbabwean Dollar (2008)", "ZWR", 935, "ZWR", 2),
CurrencyInfo("Palladium", "XPD", 964, "XPD", -1),
CurrencyInfo("Mexican Investment Unit", "MXV", 979, "MXV", 2),
CurrencyInfo("West African CFA Franc", "XOF", 952, "CFA", 0),
CurrencyInfo("Testing Currency Code", "XTS", 963, "XTS", -1),
CurrencyInfo("Maltese Lira", "MTL", 470, "MTL", 2),
CurrencyInfo("Mauritian Rupee", "MUR", 480, "MUR", 2),
CurrencyInfo("Yugoslavian New Dinar (19942002)", "YUM", 891, "YUM", 2),
CurrencyInfo("Djiboutian Franc", "DJF", 262, "DJF", 0),
CurrencyInfo("Vietnamese Dong", "VND", 704, "", 0),
CurrencyInfo("Russian Rouble (19911998)", "RUR", 810, "RUR", 2),
CurrencyInfo("Indian Rupee", "INR", 356, "", 2),
CurrencyInfo("Turkmenistani Manat (19932009)", "TMM", 795, "TMM", 2),
CurrencyInfo("Philippine Piso", "PHP", 608, "PHP", 2),
CurrencyInfo("Panamanian Balboa", "PAB", 590, "PAB", 2),
CurrencyInfo("Lithuanian Litas", "LTL", 440, "LTL", 2),
CurrencyInfo("Chilean Peso", "CLP", 152, "CLP", 0),
CurrencyInfo("Ugandan Shilling", "UGX", 800, "UGX", 0),
CurrencyInfo("Fijian Dollar", "FJD", 242, "FJD", 2),
CurrencyInfo("Iranian Rial", "IRR", 364, "IRR", 2),
CurrencyInfo("Bhutanese Ngultrum", "BTN", 64, "BTN", 2),
CurrencyInfo("Jamaican Dollar", "JMD", 388, "JMD", 2),
CurrencyInfo("Venezuelan Bolívar (18712008)", "VEB", 862, "VEB", 2),
CurrencyInfo("Romanian Leu (19522006)", "ROL", 946, "ROL", 2),
CurrencyInfo("Belize Dollar", "BZD", 84, "BZD", 2),
CurrencyInfo("Malawian Kwacha", "MWK", 454, "MWK", 2),
CurrencyInfo("Eritrean Nakfa", "ERN", 232, "ERN", 2),
CurrencyInfo("Salvadoran Colón", "SVC", 222, "SVC", 2),
CurrencyInfo("British Pound", "GBP", 826, "£", 2),
CurrencyInfo("Swiss Franc", "CHF", 756, "CHF", 2),
CurrencyInfo("Guinean Franc", "GNF", 324, "GNF", 0),
CurrencyInfo("Kazakhstani Tenge", "KZT", 398, "KZT", 2),
CurrencyInfo("Greek Drachma", "GRD", 300, "GRD", 0),
CurrencyInfo("Italian Lira", "ITL", 380, "ITL", 0),
CurrencyInfo("Portuguese Escudo", "PTE", 620, "PTE", 0),
CurrencyInfo("Israeli New Shekel", "ILS", 376, "", 2),
CurrencyInfo("South Sudanese Pound", "SSP", 728, "SSP", 2),
CurrencyInfo("Samoan Tala", "WST", 882, "WST", 2),
CurrencyInfo("Tunisian Dinar", "TND", 788, "TND", 3),
CurrencyInfo("South African Rand", "ZAR", 710, "ZAR", 2),
CurrencyInfo("Guatemalan Quetzal", "GTQ", 320, "GTQ", 2),
CurrencyInfo("Mongolian Tugrik", "MNT", 496, "MNT", 2),
CurrencyInfo("Bulgarian Lev", "BGN", 975, "BGN", 2),
CurrencyInfo("Colombian Peso", "COP", 170, "COP", 2),
CurrencyInfo("Algerian Dinar", "DZD", 12, "DZD", 2),
CurrencyInfo("Brazilian Real", "BRL", 986, "R$", 2),
CurrencyInfo("CFP Franc", "XPF", 953, "CFPF", 0),
CurrencyInfo("Surinamese Dollar", "SRD", 968, "SRD", 2),
CurrencyInfo("Swazi Lilangeni", "SZL", 748, "SZL", 2),
CurrencyInfo("European Monetary Unit", "XBB", 956, "XBB", -1),
CurrencyInfo("Azerbaijani Manat", "AZN", 944, "AZN", 2),
CurrencyInfo("Kyrgystani Som", "KGS", 417, "KGS", 2),
CurrencyInfo("Bolivian Boliviano", "BOB", 68, "BOB", 2),
CurrencyInfo("Uzbekistani Som", "UZS", 860, "UZS", 2),
CurrencyInfo("São Tomé & Príncipe Dobra (19772017)", "STD", 678, "STD", 2),
CurrencyInfo("Euro", "EUR", 978, "", 2),
CurrencyInfo("Kuwaiti Dinar", "KWD", 414, "KWD", 3),
CurrencyInfo("St Helena Pound", "SHP", 654, "SHP", 2),
CurrencyInfo("Andorran Peseta", "ADP", 20, "ADP", 0),
CurrencyInfo("Belarusian New Rouble (19941999)", "BYB", 112, "BYB", 0),
CurrencyInfo("French UIC-Franc", "XFU", 0, "XFU", -1),
CurrencyInfo("Mexican Peso", "MXN", 484, "MX$", 2),
CurrencyInfo("Central African CFA Franc", "XAF", 950, "FCFA", 0),
CurrencyInfo("Cayman Islands Dollar", "KYD", 136, "KYD", 2),
CurrencyInfo("Danish Krone", "DKK", 208, "DKK", 2),
CurrencyInfo("Russian Rouble", "RUB", 643, "RUB", 2),
CurrencyInfo("Bolivian Mvdol", "BOV", 984, "BOV", 2),
CurrencyInfo("Nicaraguan Córdoba", "NIO", 558, "NIO", 2),
CurrencyInfo("US Dollar", "USD", 840, "US$", 2),
CurrencyInfo("Hong Kong Dollar", "HKD", 344, "HK$", 2),
CurrencyInfo("Botswanan Pula", "BWP", 72, "BWP", 2),
CurrencyInfo("Tajikistani Somoni", "TJS", 972, "TJS", 2),
CurrencyInfo("Peruvian Sol", "PEN", 604, "PEN", 2),
CurrencyInfo("Colombian Real Value Unit", "COU", 970, "COU", 2),
CurrencyInfo("Malaysian Ringgit", "MYR", 458, "MYR", 2),
CurrencyInfo("Dutch Guilder", "NLG", 528, "NLG", 2),
CurrencyInfo("Serbian Dinar", "RSD", 941, "RSD", 2),
CurrencyInfo("Armenian Dram", "AMD", 51, "AMD", 2),
CurrencyInfo("Guyanaese Dollar", "GYD", 328, "GYD", 2),
CurrencyInfo("Barbadian Dollar", "BBD", 52, "BBD", 2),
CurrencyInfo("Gambian Dalasi", "GMD", 270, "GMD", 2),
CurrencyInfo("US Dollar (Next day)", "USN", 997, "USN", 2),
CurrencyInfo("Zimbabwean Dollar (2009)", "ZWL", 932, "ZWL", 2),
CurrencyInfo("US Dollar (Same day)", "USS", 998, "USS", 2),
CurrencyInfo("Turkish Lira (19222005)", "TRL", 792, "TRL", 0),
CurrencyInfo("Tongan Paʻanga", "TOP", 776, "TOP", 2),
CurrencyInfo("Special Drawing Rights", "XDR", 960, "XDR", -1),
CurrencyInfo("Angolan Kwanza", "AOA", 973, "AOA", 2),
CurrencyInfo("Bahamian Dollar", "BSD", 44, "BSD", 2),
CurrencyInfo("Vanuatu Vatu", "VUV", 548, "VUV", 0),
CurrencyInfo("Icelandic Króna", "ISK", 352, "ISK", 0),
CurrencyInfo("German Mark", "DEM", 276, "DEM", 2),
CurrencyInfo("Gold", "XAU", 959, "XAU", -1),
CurrencyInfo("Australian Dollar", "AUD", 36, "A$", 2),
CurrencyInfo("Turkmenistani Manat", "TMT", 934, "TMT", 2),
CurrencyInfo("Liberian Dollar", "LRD", 430, "LRD", 2),
CurrencyInfo("Croatian Kuna", "HRK", 191, "HRK", 2),
CurrencyInfo("Trinidad & Tobago Dollar", "TTD", 780, "TTD", 2),
CurrencyInfo("WIR Franc", "CHW", 948, "CHW", 2),
CurrencyInfo("Yemeni Rial", "YER", 886, "YER", 2),
CurrencyInfo("Somali Shilling", "SOS", 706, "SOS", 2),
CurrencyInfo("Moldovan Leu", "MDL", 498, "MDL", 2),
CurrencyInfo("Georgian Lari", "GEL", 981, "GEL", 2),
CurrencyInfo("Rwandan Franc", "RWF", 646, "RWF", 0),
CurrencyInfo("Afghan Afghani (19272002)", "AFA", 4, "AFA", 2),
CurrencyInfo("Honduran Lempira", "HNL", 340, "HNL", 2),
CurrencyInfo("Venezuelan Bolívar Soberano", "VES", 928, "VES", 2),
CurrencyInfo("Cambodian Riel", "KHR", 116, "KHR", 2),
CurrencyInfo("South Korean Won", "KRW", 410, "", 0),
CurrencyInfo("Sudanese Dinar (19922007)", "SDD", 736, "SDD", 2),
CurrencyInfo("Venezuelan Bolívar", "VEF", 937, "VEF", 2),
CurrencyInfo("Costa Rican Colón", "CRC", 188, "CRC", 2),
CurrencyInfo("Singapore Dollar", "SGD", 702, "SGD", 2),
CurrencyInfo("Jordanian Dinar", "JOD", 400, "JOD", 3),
CurrencyInfo("Saudi Riyal", "SAR", 682, "SAR", 2),
CurrencyInfo("Irish Pound", "IEP", 372, "IEP", 2),
CurrencyInfo("Zambian Kwacha (19682012)", "ZMK", 894, "ZMK", 2),
CurrencyInfo("Omani Rial", "OMR", 512, "OMR", 3),
CurrencyInfo("Canadian Dollar", "CAD", 124, "CA$", 2),
CurrencyInfo("European Composite Unit", "XBA", 955, "XBA", -1),
CurrencyInfo("Slovenian Tolar", "SIT", 705, "SIT", 2),
CurrencyInfo("WIR Euro", "CHE", 947, "CHE", 2),
CurrencyInfo("Egyptian Pound", "EGP", 818, "EGP", 2),
CurrencyInfo("Argentine Peso", "ARS", 32, "ARS", 2),
CurrencyInfo("Silver", "XAG", 961, "XAG", -1),
CurrencyInfo("ZWN", "ZWN", 942, "ZWN", 2),
CurrencyInfo("São Tomé & Príncipe Dobra", "STN", 930, "STN", 2),
CurrencyInfo("Mauritanian Ouguiya", "MRU", 929, "MRU", 2),
CurrencyInfo("Hungarian Forint", "HUF", 348, "HUF", 2),
CurrencyInfo("Chilean Unit of Account (UF)", "CLF", 990, "CLF", 4),
CurrencyInfo("Mauritanian Ouguiya (19732017)", "MRO", 478, "MRO", 2),
CurrencyInfo("Ghanaian Cedi (19792007)", "GHC", 288, "GHC", 2),
CurrencyInfo("New Zealand Dollar", "NZD", 554, "NZ$", 2),
CurrencyInfo("Sri Lankan Rupee", "LKR", 144, "LKR", 2),
CurrencyInfo("Papua New Guinean Kina", "PGK", 598, "PGK", 2),
CurrencyInfo("Cypriot Pound", "CYP", 196, "CYP", 2),
CurrencyInfo("Macanese Pataca", "MOP", 446, "MOP", 2),
CurrencyInfo("Bermudan Dollar", "BMD", 60, "BMD", 2),
CurrencyInfo("Cuban Peso", "CUP", 192, "CUP", 2),
CurrencyInfo("Solomon Islands Dollar", "SBD", 90, "SBD", 2),
CurrencyInfo("Unknown Currency", "XXX", 999, "XXX", -1),
CurrencyInfo("Ethiopian Birr", "ETB", 230, "ETB", 2),
CurrencyInfo("Libyan Dinar", "LYD", 434, "LYD", 3),
CurrencyInfo("Syrian Pound", "SYP", 760, "SYP", 2),
CurrencyInfo("Latvian Lats", "LVL", 428, "LVL", 2),
CurrencyInfo("Bangladeshi Taka", "BDT", 50, "BDT", 2),
CurrencyInfo("Moroccan Dirham", "MAD", 504, "MAD", 2),
CurrencyInfo("Lesotho Loti", "LSL", 426, "LSL", 2),
CurrencyInfo("Malagasy Ariary", "MGA", 969, "MGA", 2),
CurrencyInfo("Qatari Rial", "QAR", 634, "QAR", 2),
CurrencyInfo("Ukrainian Hryvnia", "UAH", 980, "UAH", 2),
CurrencyInfo("Comorian Franc", "KMF", 174, "KMF", 0),
CurrencyInfo("Aruban Florin", "AWG", 533, "AWG", 2),
CurrencyInfo("Namibian Dollar", "NAD", 516, "NAD", 2),
CurrencyInfo("Myanmar Kyat", "MMK", 104, "MMK", 2),
CurrencyInfo("Spanish Peseta", "ESP", 724, "ESP", 0),
CurrencyInfo("Japanese Yen", "JPY", 392, "JP¥", 0),
CurrencyInfo("Indonesian Rupiah", "IDR", 360, "IDR", 2),
CurrencyInfo("North Korean Won", "KPW", 408, "KPW", 2),
CurrencyInfo("European Unit of Account (XBD)", "XBD", 958, "XBD", -1),
CurrencyInfo("Brunei Dollar", "BND", 96, "BND", 2),
CurrencyInfo("Falkland Islands Pound", "FKP", 238, "FKP", 2),
CurrencyInfo("Uruguayan Peso", "UYU", 858, "UYU", 2),
CurrencyInfo("Azerbaijani Manat (19932006)", "AZM", 31, "AZM", 2),
CurrencyInfo("Burundian Franc", "BIF", 108, "BIF", 0),
CurrencyInfo("Dominican Peso", "DOP", 214, "DOP", 2),
CurrencyInfo("Belarusian Rouble", "BYN", 933, "BYN", 2),
CurrencyInfo("Malagasy Franc", "MGF", 450, "MGF", 0),
CurrencyInfo("Slovak Koruna", "SKK", 703, "SKK", 2),
CurrencyInfo("Gibraltar Pound", "GIP", 292, "GIP", 2),
CurrencyInfo("New Taiwan Dollar", "TWD", 901, "NT$", 2),
CurrencyInfo("Romanian Leu", "RON", 946, "RON", 2),
CurrencyInfo("European Unit of Account (XBC)", "XBC", 957, "XBC", -1),
CurrencyInfo("Netherlands Antillean Guilder", "ANG", 532, "ANG", 2),
CurrencyInfo("Polish Zloty", "PLN", 985, "PLN", 2),
CurrencyInfo("Ghanaian Cedi", "GHS", 936, "GHS", 2),
CurrencyInfo("Lebanese Pound", "LBP", 422, "LBP", 2),
CurrencyInfo("AYM", "AYM", 945, "AYM", 2),
CurrencyInfo("Uruguayan Peso (Indexed Units)", "UYI", 940, "UYI", 0),
CurrencyInfo("Czech Koruna", "CZK", 203, "CZK", 2),
CurrencyInfo("Tanzanian Shilling", "TZS", 834, "TZS", 2),
CurrencyInfo("Seychellois Rupee", "SCR", 690, "SCR", 2),
CurrencyInfo("Zimbabwean Dollar (19802008)", "ZWD", 716, "ZWD", 2),
CurrencyInfo("Estonian Kroon", "EEK", 233, "EEK", 2),
CurrencyInfo("Pakistani Rupee", "PKR", 586, "PKR", 2),
CurrencyInfo("Surinamese Guilder", "SRG", 740, "SRG", 2),
CurrencyInfo("ADB Unit of Account", "XUA", 965, "XUA", -1),
CurrencyInfo("Macedonian Denar", "MKD", 807, "MKD", 2),
CurrencyInfo("Kenyan Shilling", "KES", 404, "KES", 2),
CurrencyInfo("Belarusian Rouble (20002016)", "BYR", 974, "BYR", 0)
)
val symbolsForIsoCode = infos.map { it.isoCode to it.symbol }.toMap()
val Euro = infos.first { it.isoCode == "EUR" }
}
override val userDefaultCurrencyInfo: CurrencyInfo
get() = Euro // TODO: implement real lookup by current Locale
override val currencyInfos: List<CurrencyInfo>
get() = ArrayList(infos)
override fun getInfoForIsoCode(isoCode: String): CurrencyInfo? {
return infos.firstOrNull { it.isoCode == isoCode }
}
override fun getCurrencySymbolForIsoCode(isoCode: String): String? {
return symbolsForIsoCode[isoCode]
}
override fun getCurrencySymbolForIsoCodeOr(isoCode: String, defaultValue: String): String {
return getCurrencySymbolForIsoCode(isoCode) ?: defaultValue
}
override fun getCurrencySymbolForIsoCodeOrEuro(isoCode: String): String {
return getCurrencySymbolForIsoCodeOr(isoCode, "")
}
}

View File

@ -0,0 +1,19 @@
package net.dankito.banking.ui.util
interface ICurrencyInfoProvider {
val userDefaultCurrencyInfo: CurrencyInfo
val currencyInfos: List<CurrencyInfo>
fun getInfoForIsoCode(isoCode: String): CurrencyInfo?
fun getCurrencySymbolForIsoCode(isoCode: String): String?
fun getCurrencySymbolForIsoCodeOr(isoCode: String, defaultValue: String): String
fun getCurrencySymbolForIsoCodeOrEuro(isoCode: String): String
}

View File

@ -7,6 +7,7 @@ import net.dankito.banking.search.ITransactionPartySearcher
import net.dankito.banking.ui.IRouter import net.dankito.banking.ui.IRouter
import net.dankito.banking.ui.model.mapper.DefaultModelCreator import net.dankito.banking.ui.model.mapper.DefaultModelCreator
import net.dankito.banking.ui.presenter.BankingPresenter import net.dankito.banking.ui.presenter.BankingPresenter
import net.dankito.banking.ui.util.CurrencyInfoProvider
import net.dankito.banking.util.* import net.dankito.banking.util.*
import net.dankito.banking.util.extraction.NoOpInvoiceDataExtractor import net.dankito.banking.util.extraction.NoOpInvoiceDataExtractor
import net.dankito.banking.util.extraction.NoOpTextExtractorRegistry import net.dankito.banking.util.extraction.NoOpTextExtractorRegistry
@ -16,6 +17,6 @@ import net.dankito.utils.multiplatform.File
class BankingPresenterSwift(dataFolder: File, router: IRouter, webClient: IWebClient, persistence: IBankingPersistence, class BankingPresenterSwift(dataFolder: File, router: IRouter, webClient: IWebClient, persistence: IBankingPersistence,
transactionPartySearcher: ITransactionPartySearcher, bankIconFinder: IBankIconFinder, serializer: ISerializer, asyncRunner: IAsyncRunner) transactionPartySearcher: ITransactionPartySearcher, bankIconFinder: IBankIconFinder, serializer: ISerializer, asyncRunner: IAsyncRunner)
: BankingPresenter(fints4kBankingClientCreator(DefaultModelCreator(), serializer, webClient), InMemoryBankFinder(), dataFolder, persistence, router, DefaultModelCreator(), : BankingPresenter(fints4kBankingClientCreator(DefaultModelCreator(), serializer, webClient), InMemoryBankFinder(), dataFolder, persistence, router, DefaultModelCreator(),
transactionPartySearcher, bankIconFinder, NoOpTextExtractorRegistry(), NoOpInvoiceDataExtractor(), serializer, asyncRunner) { transactionPartySearcher, bankIconFinder, NoOpTextExtractorRegistry(), NoOpInvoiceDataExtractor(), CurrencyInfoProvider(), serializer, asyncRunner) {
} }

View File

@ -85,7 +85,7 @@ struct AccountTransactionsDialog: View {
Spacer() Spacer()
AmountLabel(amount: self.balanceOfFilteredTransactions) AmountLabel(self.balanceOfFilteredTransactions)
} }
} }
} }

View File

@ -4,13 +4,21 @@ import BankingUiSwift
struct AmountLabel: View { struct AmountLabel: View {
let amount: CommonBigDecimal private let amount: CommonBigDecimal
private let currencyIsoCode: String?
@Inject private var presenter: BankingPresenterSwift @Inject private var presenter: BankingPresenterSwift
init(_ amount: CommonBigDecimal, _ currencyIsoCode: String? = nil) {
self.amount = amount
self.currencyIsoCode = currencyIsoCode
}
var body: some View { var body: some View {
Text(presenter.formatAmount(amount: amount)) Text(presenter.formatAmount(amount: amount, currencyIsoCode: currencyIsoCode))
.styleAmount(amount: amount) .styleAmount(amount: amount)
} }
} }
@ -18,6 +26,6 @@ struct AmountLabel: View {
struct AmountLabel_Previews: PreviewProvider { struct AmountLabel_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
AmountLabel(amount: CommonBigDecimal(double: 84.12)) AmountLabel(CommonBigDecimal(double: 84.12))
} }
} }

View File

@ -52,7 +52,7 @@ struct AccountTransactionListItem: View {
Spacer() Spacer()
} }
AmountLabel(amount: transaction.amount) AmountLabel(transaction.amount, transaction.currency)
Spacer() Spacer()

View File

@ -9,6 +9,9 @@ struct AllBanksListItem: View {
@State private var navigateToAccountTransactionsDialog = false @State private var navigateToAccountTransactionsDialog = false
@Inject private var presenter: BankingPresenterSwift
var body: some View { var body: some View {
Section { Section {
NavigationLink(destination: EmptyView(), isActive: .constant(false)) { // NavigationLink navigated to AccountTransactionsDialog twice. So i disabled NavigationLink and implemented manual navigation NavigationLink(destination: EmptyView(), isActive: .constant(false)) { // NavigationLink navigated to AccountTransactionsDialog twice. So i disabled NavigationLink and implemented manual navigation
@ -17,7 +20,7 @@ struct AllBanksListItem: View {
Spacer() Spacer()
AmountLabel(amount: banks.sumBalances()) AmountLabel(banks.sumBalances(), presenter.currencyIsoCodeOfAccounts(accounts: presenter.allAccounts))
} }
.frame(height: 35) .frame(height: 35)
.background(Color.systemBackground) // make background tapable .background(Color.systemBackground) // make background tapable

View File

@ -16,7 +16,7 @@ struct BankAccountListItem : View {
Spacer() Spacer()
AmountLabel(amount: account.balance) AmountLabel(account.balance, account.currency)
}.frame(height: 35) }.frame(height: 35)
} }
.disabled( !account.isAccountTypeSupportedByApplication) .disabled( !account.isAccountTypeSupportedByApplication)

View File

@ -20,7 +20,7 @@ struct BankListItem : View {
Spacer() Spacer()
AmountLabel(amount: bank.balance) AmountLabel(bank.balance, presenter.currencyIsoCodeOfAccounts(accounts: bank.accounts))
} }
.frame(height: 35) .frame(height: 35)
.background(Color.systemBackground) // make background tapable .background(Color.systemBackground) // make background tapable