Using now String as data type for amount
This commit is contained in:
parent
93c3b915bf
commit
d668c61c3d
|
@ -58,7 +58,7 @@ open class EpcQrCode(
|
||||||
* Optional amount.
|
* Optional amount.
|
||||||
* Max. 12 bytes.
|
* Max. 12 bytes.
|
||||||
*/
|
*/
|
||||||
open val amount: Double?, // TODO: use BigDecimal
|
open val amount: String?,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optional purpose code.
|
* Optional purpose code.
|
||||||
|
|
|
@ -9,7 +9,7 @@ open class EpcQrCodeConfig(
|
||||||
|
|
||||||
var bic: String? = null,
|
var bic: String? = null,
|
||||||
|
|
||||||
var amount: Double? = null,
|
amount: String? = null,
|
||||||
|
|
||||||
var reference: String? = null,
|
var reference: String? = null,
|
||||||
|
|
||||||
|
@ -17,4 +17,17 @@ open class EpcQrCodeConfig(
|
||||||
|
|
||||||
var encoding: EpcQrCodeCharacterSet = EpcQrCodeCharacterSet.UTF_8
|
var encoding: EpcQrCodeCharacterSet = EpcQrCodeCharacterSet.UTF_8
|
||||||
|
|
||||||
)
|
) {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
|
||||||
|
fun ensureAmountFormat(amount: String?): String? {
|
||||||
|
return amount?.replace(',', '.')
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
open val amount: String? = ensureAmountFormat(amount)
|
||||||
|
|
||||||
|
}
|
|
@ -38,7 +38,7 @@ open class EpcQrCodeCreator {
|
||||||
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.bic))
|
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.bic))
|
||||||
epcQrCodeBuilder.appendLine(epcQrCode.receiverName)
|
epcQrCodeBuilder.appendLine(epcQrCode.receiverName)
|
||||||
epcQrCodeBuilder.appendLine(epcQrCode.iban)
|
epcQrCodeBuilder.appendLine(epcQrCode.iban)
|
||||||
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.amount?.let { (epcQrCode.currencyCode ?: EpcQrCode.CurrencyCodeDefaultValue) + convert(it) }))
|
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.amount?.let { (epcQrCode.currencyCode ?: EpcQrCode.CurrencyCodeDefaultValue) + it })) // TODO: ensure that amount is converted to the correct format
|
||||||
epcQrCodeBuilder.appendLine(epcQrCode.purposeCode)
|
epcQrCodeBuilder.appendLine(epcQrCode.purposeCode)
|
||||||
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.remittanceReference))
|
epcQrCodeBuilder.appendLine(mapNullable(epcQrCode.remittanceReference))
|
||||||
|
|
||||||
|
@ -54,10 +54,6 @@ open class EpcQrCodeCreator {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected open fun convert(amount: Double): String {
|
|
||||||
return amount.toString() // TODO: ensure that it's converted to the correct format
|
|
||||||
}
|
|
||||||
|
|
||||||
protected open fun mapNullable(value: String?): String {
|
protected open fun mapNullable(value: String?): String {
|
||||||
return value ?: ""
|
return value ?: ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class MainActivity : AppCompatActivity() {
|
||||||
private fun generateQrCode() {
|
private fun generateQrCode() {
|
||||||
hideKeyboard(edtxtReference)
|
hideKeyboard(edtxtReference)
|
||||||
|
|
||||||
val param = EpcQrCodeConfig(edtxtReceiver.string, edtxtIban.string, edtxtBic.string, map(edtxtAmount.string), edtxtReference.string)
|
val param = EpcQrCodeConfig(edtxtReceiver.string, edtxtIban.string, edtxtBic.string, edtxtAmount.string, edtxtReference.string)
|
||||||
|
|
||||||
generateQrCodeAsync(param) { createdQrCode ->
|
generateQrCodeAsync(param) { createdQrCode ->
|
||||||
imgGeneratedQrCode.setImageBitmap(createdQrCode)
|
imgGeneratedQrCode.setImageBitmap(createdQrCode)
|
||||||
|
@ -43,8 +43,4 @@ class MainActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun map(amount: String): Double? {
|
|
||||||
return amount.replace(',', '.').toDoubleOrNull()
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ open class AppSettings(
|
||||||
open var receiver: String = "",
|
open var receiver: String = "",
|
||||||
open var iban: String = "",
|
open var iban: String = "",
|
||||||
open var bic: String = "",
|
open var bic: String = "",
|
||||||
open var amount: Double? = null,
|
open var amount: String? = null,
|
||||||
open var reference: String = "",
|
open var reference: String = "",
|
||||||
open var destinationFile: String = ""
|
open var destinationFile: String = ""
|
||||||
)
|
)
|
|
@ -267,7 +267,7 @@ class MainWindow : View(FX.messages["application.title"]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateQrCode() {
|
private fun generateQrCode() {
|
||||||
val param = EpcQrCodeConfig(receiver.value, iban.value, bic.value, map(amount.value), reference.value)
|
val param = EpcQrCodeConfig(receiver.value, iban.value, bic.value, amount.value, reference.value)
|
||||||
val qrCodeContent = EpcQrCodeCreator().generateAsString(param)
|
val qrCodeContent = EpcQrCodeCreator().generateAsString(param)
|
||||||
|
|
||||||
generatedQrCodeImage.value = generateQrCode(qrCodeContent)
|
generatedQrCodeImage.value = generateQrCode(qrCodeContent)
|
||||||
|
@ -277,10 +277,6 @@ class MainWindow : View(FX.messages["application.title"]) {
|
||||||
saveSettings() // TODO: actually a side effect
|
saveSettings() // TODO: actually a side effect
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun map(amount: String): Double? {
|
|
||||||
return DecimalFormat.parse(amount, ParsePosition(0))?.toDouble()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun generateQrCode(informationToEncode: String): Image? {
|
private fun generateQrCode(informationToEncode: String): Image? {
|
||||||
try {
|
try {
|
||||||
generatedQrCodeBytes = qrCodeGenerator.generateQrCode(informationToEncode)
|
generatedQrCodeBytes = qrCodeGenerator.generateQrCode(informationToEncode)
|
||||||
|
@ -296,7 +292,7 @@ class MainWindow : View(FX.messages["application.title"]) {
|
||||||
|
|
||||||
private fun saveSettings() {
|
private fun saveSettings() {
|
||||||
try {
|
try {
|
||||||
val appSettings = AppSettings(receiver.value, iban.value, bic.value, map(amount.value), reference.value,
|
val appSettings = AppSettings(receiver.value, iban.value, bic.value, amount.value, reference.value,
|
||||||
selectedDestinationFile.value)
|
selectedDestinationFile.value)
|
||||||
|
|
||||||
serializer.serializeObject(appSettings, AppSettingsFile)
|
serializer.serializeObject(appSettings, AppSettingsFile)
|
||||||
|
|
|
@ -12,7 +12,7 @@ class GenerateEpcQrCodeRequestDto {
|
||||||
|
|
||||||
var iban: String = ""
|
var iban: String = ""
|
||||||
|
|
||||||
var amount: Double? = null
|
var amount: String? = null
|
||||||
|
|
||||||
var reference: String? = null
|
var reference: String? = null
|
||||||
|
|
||||||
|
|
|
@ -82,21 +82,13 @@ struct ContentView: View {
|
||||||
|
|
||||||
private func generateQRCode() {
|
private func generateQRCode() {
|
||||||
let creator = EpcQrCodeCreator()
|
let creator = EpcQrCodeCreator()
|
||||||
let param = EpcQrCodeConfig(receiverName: receiver, iban: iban, bic: bic, amount: map(amount), reference: reference, noteToUser: nil, encoding: .utf8)
|
let param = EpcQrCodeConfig(receiverName: receiver, iban: iban, bic: bic, amount: amount, reference: reference, noteToUser: nil, encoding: .utf8)
|
||||||
|
|
||||||
let qrCodeContent = creator.generateAsString(param: param)
|
let qrCodeContent = creator.generateAsString(param: param)
|
||||||
|
|
||||||
self.generatedQrCode = generateQRCode(qrCodeContent)
|
self.generatedQrCode = generateQRCode(qrCodeContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func map(_ amount: String) -> KotlinDouble? {
|
|
||||||
if let double = Double(amount.replacingOccurrences(of: ",", with: ".")) {
|
|
||||||
return KotlinDouble(double: double)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
private func generateQRCode(_ informationToEncode: String) -> UIImage? {
|
private func generateQRCode(_ informationToEncode: String) -> UIImage? {
|
||||||
let writer = ZXQRCodeWriter()
|
let writer = ZXQRCodeWriter()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue