Throws exception if the currency code is wrong when setting it

od
Laurent 6 years ago
parent 374c65871c
commit 947c865e8b
  1. 12
      app/src/main/java/net/pokeranalytics/android/model/realm/Currency.kt

@ -3,6 +3,7 @@ package net.pokeranalytics.android.model.realm
import io.realm.RealmObject
import io.realm.annotations.Ignore
import io.realm.annotations.PrimaryKey
import net.pokeranalytics.android.exceptions.PAIllegalStateException
import net.pokeranalytics.android.util.UserDefaults
import java.util.*
@ -22,6 +23,17 @@ open class Currency : RealmObject() {
* The currency code of the currency, i.e. USD, EUR...
*/
var code: String? = null
set(value) {
try {
if (value != null) {
java.util.Currency.getInstance(value) // test validity of code
}
field = value
} catch (e: Exception) {
// make app crash earlier than later, possibly to show an error message to the user in the future
throw PAIllegalStateException(e.localizedMessage)
}
}
/**
* The rate of the currency with the main currency

Loading…
Cancel
Save