currency
Laurent 3 years ago
parent d852d62c93
commit 5a0d86e533
  1. 2
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 15
      app/src/main/java/net/pokeranalytics/android/model/migrations/Patcher.kt
  3. 6
      app/src/main/java/net/pokeranalytics/android/model/migrations/PokerAnalyticsMigration.kt
  4. 8
      app/src/main/java/net/pokeranalytics/android/model/realm/Transaction.kt
  5. 25
      app/src/main/java/net/pokeranalytics/android/util/Preferences.kt

@ -39,7 +39,9 @@ class PokerAnalyticsApplication : Application() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
if (!BuildConfig.DEBUG) {
FirebaseApp.initializeApp(this) FirebaseApp.initializeApp(this)
}
UserDefaults.init(this) UserDefaults.init(this)

@ -57,6 +57,10 @@ class Patcher {
patchZeroTable() patchZeroTable()
} }
Preferences.executeOnce(Preferences.Keys.PATCH_RATED_AMOUNT, context) {
patchRatedAmounts()
}
patchPerformances(application) patchPerformances(application)
} }
@ -215,5 +219,16 @@ class Patcher {
realm.close() realm.close()
} }
private fun patchRatedAmounts() {
val realm = Realm.getDefaultInstance()
val transactions = realm.where<Transaction>().findAll()
realm.executeTransaction {
transactions.forEach { t ->
t.computeRatedAmount()
}
}
realm.close()
}
} }
} }

@ -326,6 +326,12 @@ class PokerAnalyticsMigration : RealmMigration {
ucs.addField("transactionTypeIds", String::class.java).setRequired("transactionTypeIds", true) ucs.addField("transactionTypeIds", String::class.java).setRequired("transactionTypeIds", true)
} ?: throw PAIllegalStateException("UserConfig schema not found") } ?: throw PAIllegalStateException("UserConfig schema not found")
schema.get("Performance")?.let { ps ->
if (!ps.isPrimaryKey("id")) {
ps.addPrimaryKey("id")
}
}
currentVersion++ currentVersion++
} }

@ -75,8 +75,7 @@ open class Transaction : RealmObject(), RowRepresentable, RowUpdatable, Manageab
override var amount: Double = 0.0 override var amount: Double = 0.0
set(value) { set(value) {
field = value field = value
val rate = this.bankroll?.currency?.rate ?: 1.0 computeRatedAmount()
this.ratedAmount = rate * value
} }
// The amount of the transaction // The amount of the transaction
@ -114,6 +113,11 @@ open class Transaction : RealmObject(), RowRepresentable, RowUpdatable, Manageab
RATED_AMOUNT("ratedAmount") RATED_AMOUNT("ratedAmount")
} }
fun computeRatedAmount() {
val rate = this.bankroll?.currency?.rate ?: 1.0
this.ratedAmount = rate * this.amount
}
val displayAmount: Double val displayAmount: Double
get() { // for transfers we want to show a positive value (in the feed for instance) get() { // for transfers we want to show a positive value (in the feed for instance)
return if (this.destination == null) { this.amount } else { abs(this.amount) } return if (this.destination == null) { this.amount } else { abs(this.amount) }

@ -48,7 +48,8 @@ class Preferences {
PATCH_STAKES("patchStakes"), PATCH_STAKES("patchStakes"),
CLEAN_BLINDS_FILTERS("deleteBlindsFilters"), CLEAN_BLINDS_FILTERS("deleteBlindsFilters"),
SHOW_IN_APP_BADGES("showInAppBadges"), SHOW_IN_APP_BADGES("showInAppBadges"),
LAST_CALENDAR_BADGE_DATE("lastCalendarBadgeDate") LAST_CALENDAR_BADGE_DATE("lastCalendarBadgeDate"),
PATCH_RATED_AMOUNT("patchRatedAmount[new field]")
} }
enum class FeedMessage { enum class FeedMessage {
@ -101,17 +102,17 @@ class Preferences {
companion object { companion object {
fun setStringSet(key: PreferenceKey, value: MutableSet<String>, context: Context) { // fun setStringSet(key: PreferenceKey, value: MutableSet<String>, context: Context) {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) // val preferences = PreferenceManager.getDefaultSharedPreferences(context)
val editor = preferences.edit() // val editor = preferences.edit()
editor.putStringSet(key.identifier, value) // editor.putStringSet(key.identifier, value)
editor.apply() // editor.apply()
} // }
//
fun getStringSet(key: Keys, context: Context): MutableSet<String>? { // fun getStringSet(key: Keys, context: Context): MutableSet<String>? {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) // val preferences = PreferenceManager.getDefaultSharedPreferences(context)
return preferences.getStringSet(key.identifier, null) // return preferences.getStringSet(key.identifier, null)
} // }
fun setString(key: PreferenceKey, value: String, context: Context) { fun setString(key: PreferenceKey, value: String, context: Context) {
val preferences = PreferenceManager.getDefaultSharedPreferences(context) val preferences = PreferenceManager.getDefaultSharedPreferences(context)

Loading…
Cancel
Save