Patches transaction types name + refactoring

dev
Laurent 7 years ago
parent 9419990074
commit 369624bcfc
  1. 1
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 17
      app/src/main/java/net/pokeranalytics/android/model/migrations/Patcher.kt
  3. 14
      app/src/main/java/net/pokeranalytics/android/model/realm/TransactionType.kt
  4. 7
      app/src/main/java/net/pokeranalytics/android/model/utils/Seed.kt

@ -66,6 +66,7 @@ class PokerAnalyticsApplication : Application() {
Patcher.patchBreaks() Patcher.patchBreaks()
Patcher.patchDefaultTransactionTypes(this.applicationContext)
} }
/** /**

@ -1,12 +1,10 @@
package net.pokeranalytics.android.model.migrations package net.pokeranalytics.android.model.migrations
import android.content.Context
import io.realm.Realm import io.realm.Realm
import net.pokeranalytics.android.model.filter.Query import net.pokeranalytics.android.model.filter.Query
import net.pokeranalytics.android.model.filter.QueryCondition import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.realm.Filter import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.model.realm.Result
import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.SessionSet
class Patcher { class Patcher {
@ -34,6 +32,17 @@ class Patcher {
} }
fun patchDefaultTransactionTypes(context: Context) {
val realm = Realm.getDefaultInstance()
val tts = realm.where(TransactionType::class.java).findAll()
tts.forEach { tt ->
tt.kind?.let { kind ->
val value = TransactionType.Value.values()[kind]
tt.name = value.localizedTitle(context)
}
}
}
} }

@ -8,6 +8,7 @@ import net.pokeranalytics.android.R
import net.pokeranalytics.android.model.interfaces.DeleteValidityStatus import net.pokeranalytics.android.model.interfaces.DeleteValidityStatus
import net.pokeranalytics.android.model.interfaces.NameManageable import net.pokeranalytics.android.model.interfaces.NameManageable
import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource import net.pokeranalytics.android.ui.adapter.StaticRowRepresentableDataSource
import net.pokeranalytics.android.ui.view.Localizable
import net.pokeranalytics.android.ui.view.RowRepresentable import net.pokeranalytics.android.ui.view.RowRepresentable
import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor import net.pokeranalytics.android.ui.view.RowRepresentableEditDescriptor
import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow import net.pokeranalytics.android.ui.view.rowrepresentable.SimpleRow
@ -18,10 +19,19 @@ import kotlin.collections.ArrayList
open class TransactionType : RealmObject(), NameManageable, StaticRowRepresentableDataSource, RowRepresentable { open class TransactionType : RealmObject(), NameManageable, StaticRowRepresentableDataSource, RowRepresentable {
enum class Value(val additive: Boolean) { enum class Value(val additive: Boolean) : Localizable {
WITHDRAWAL(false), WITHDRAWAL(false),
DEPOSIT(true), DEPOSIT(true),
BONUS(true) BONUS(true);
override val resId: Int?
get() {
return when (this) {
WITHDRAWAL -> R.string.withdrawal
DEPOSIT -> R.string.deposit
BONUS -> R.string.bonus
}
}
} }
companion object { companion object {

@ -59,12 +59,7 @@ class Seed(var context:Context) : Realm.Transaction {
private fun createDefaultTransactionTypes(realm: Realm) { private fun createDefaultTransactionTypes(realm: Realm) {
TransactionType.Value.values().forEachIndexed { index, value -> TransactionType.Value.values().forEachIndexed { index, value ->
val type = TransactionType() val type = TransactionType()
val name = when(value) { type.name = value.localizedTitle(context)
TransactionType.Value.WITHDRAWAL -> context.getString(R.string.withdrawal)
TransactionType.Value.DEPOSIT -> context.getString(R.string.deposit)
TransactionType.Value.BONUS -> context.getString(R.string.bonus)
}
type.name = name
type.additive = value.additive type.additive = value.additive
type.kind = index type.kind = index
type.lock = true type.lock = true

Loading…
Cancel
Save