Added single execution system + use for patches

dev
Laurent 7 years ago
parent 298723bb29
commit 6e4e03d9c7
  1. 7
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 16
      app/src/main/java/net/pokeranalytics/android/model/migrations/Patcher.kt
  3. 13
      app/src/main/java/net/pokeranalytics/android/util/Preferences.kt

@ -20,12 +20,11 @@ import net.pokeranalytics.android.util.billing.AppGuard
import timber.log.Timber import timber.log.Timber
class PokerAnalyticsApplication : Application() { class PokerAnalyticsApplication : Application() {
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
UserDefaults.init(this) UserDefaults.init(this)
// AppGuard / Billing services // AppGuard / Billing services
AppGuard.load(this.applicationContext) AppGuard.load(this.applicationContext)
@ -64,9 +63,7 @@ class PokerAnalyticsApplication : Application() {
this.createFakeSessions() this.createFakeSessions()
} }
Patcher.patchAll(this.applicationContext)
Patcher.patchBreaks()
Patcher.patchDefaultTransactionTypes(this.applicationContext)
} }
/** /**

@ -5,12 +5,24 @@ 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.* import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.util.Preferences
class Patcher { class Patcher {
companion object { companion object {
fun patchBreaks() { fun patchAll(context: Context) {
Preferences.executeOnce(Preferences.Keys.PATCH_BREAK, context) {
patchBreaks()
}
Preferences.executeOnce(Preferences.Keys.PATCH_TRANSACTION_TYPES_NAMES, context) {
patchDefaultTransactionTypes(context)
}
}
private fun patchBreaks() {
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
val sets = realm.where(SessionSet::class.java).findAll() val sets = realm.where(SessionSet::class.java).findAll()
@ -32,7 +44,7 @@ class Patcher {
} }
fun patchDefaultTransactionTypes(context: Context) { private fun patchDefaultTransactionTypes(context: Context) {
val realm = Realm.getDefaultInstance() val realm = Realm.getDefaultInstance()
realm.executeTransaction { realm.executeTransaction {
val tts = realm.where(TransactionType::class.java).findAll() val tts = realm.where(TransactionType::class.java).findAll()

@ -6,13 +6,17 @@ import java.util.*
class Preferences { class Preferences {
private val ONCE_PREFIX = "singleExecution_"
enum class Keys(var identifier: String) { enum class Keys(var identifier: String) {
CURRENCY_CODE("CurrencyCode"), CURRENCY_CODE("CurrencyCode"),
LOCALE_CODE("LocaleCode"), LOCALE_CODE("LocaleCode"),
FIRST_LAUNCH("firstLaunch"), FIRST_LAUNCH("firstLaunch"),
STOP_SHOWING_DISCLAIMER("stopShowingDisclaimer"), STOP_SHOWING_DISCLAIMER("stopShowingDisclaimer"),
ACTIVE_FILTER_ID("ActiveFilterId"), ACTIVE_FILTER_ID("ActiveFilterId"),
LATEST_PURCHASE("latestPurchase") LATEST_PURCHASE("latestPurchase"),
PATCH_BREAK("patchBreaks"),
PATCH_TRANSACTION_TYPES_NAMES("patchTransactionTypesNames")
} }
companion object { companion object {
@ -99,6 +103,13 @@ class Preferences {
return !getBoolean(Keys.STOP_SHOWING_DISCLAIMER, context) return !getBoolean(Keys.STOP_SHOWING_DISCLAIMER, context)
} }
fun executeOnce(key: Keys, context: Context, executable: () -> Unit) {
if (!getBoolean(key, context)) {
executable.invoke()
setBoolean(key, true, context)
}
}
} }
} }

Loading…
Cancel
Save