Added single execution system + use for patches

dev
Laurent 7 years ago
parent 298723bb29
commit 6e4e03d9c7
  1. 5
      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,7 +20,6 @@ import net.pokeranalytics.android.util.billing.AppGuard
import timber.log.Timber
class PokerAnalyticsApplication : Application() {
override fun onCreate() {
@ -64,9 +63,7 @@ class PokerAnalyticsApplication : Application() {
this.createFakeSessions()
}
Patcher.patchBreaks()
Patcher.patchDefaultTransactionTypes(this.applicationContext)
Patcher.patchAll(this.applicationContext)
}
/**

@ -5,12 +5,24 @@ import io.realm.Realm
import net.pokeranalytics.android.model.filter.Query
import net.pokeranalytics.android.model.filter.QueryCondition
import net.pokeranalytics.android.model.realm.*
import net.pokeranalytics.android.util.Preferences
class Patcher {
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 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()
realm.executeTransaction {
val tts = realm.where(TransactionType::class.java).findAll()

@ -6,13 +6,17 @@ import java.util.*
class Preferences {
private val ONCE_PREFIX = "singleExecution_"
enum class Keys(var identifier: String) {
CURRENCY_CODE("CurrencyCode"),
LOCALE_CODE("LocaleCode"),
FIRST_LAUNCH("firstLaunch"),
STOP_SHOWING_DISCLAIMER("stopShowingDisclaimer"),
ACTIVE_FILTER_ID("ActiveFilterId"),
LATEST_PURCHASE("latestPurchase")
LATEST_PURCHASE("latestPurchase"),
PATCH_BREAK("patchBreaks"),
PATCH_TRANSACTION_TYPES_NAMES("patchTransactionTypesNames")
}
companion object {
@ -99,6 +103,13 @@ class Preferences {
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