Fixes crash with possible negative limit

powerreport
Laurent 3 years ago
parent aa8112b965
commit 788c6a597d
  1. 14
      app/src/main/java/net/pokeranalytics/android/model/migrations/Patcher.kt
  2. 7
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  3. 3
      app/src/main/java/net/pokeranalytics/android/util/Preferences.kt

@ -35,6 +35,9 @@ class Patcher {
Preferences.executeOnce(Preferences.Keys.PATCH_BLINDS_FORMAT, context) {
patchBlindFormat()
}
Preferences.executeOnce(Preferences.Keys.PATCH_NEGATIVE_LIMITS, context) {
patchNegativeLimits()
}
Preferences.executeOnce(Preferences.Keys.ADD_NEW_TRANSACTION_TYPES, context) {
@ -131,6 +134,17 @@ class Patcher {
realm.close()
}
private fun patchNegativeLimits() {
val realm = Realm.getDefaultInstance()
realm.executeTransaction {
val sessions = realm.where(Session::class.java).lessThan("limit", 0).findAll()
sessions.forEach { session ->
session.limit = null
}
}
realm.close()
}
/*
02/09/19: A bug with the session set management made them kept instead of deleted,
thus making duration calculation wrong

@ -271,6 +271,13 @@ open class Session : RealmObject(), Savable, RowUpdatable, RowRepresentable, Tim
// The limit type: NL, PL...
var limit: Int? = null
set(value) {
field = if (value != null && value >= 0) {
value
} else {
null
}
}
// The game played during the Session
var game: Game? = null

@ -42,7 +42,8 @@ class Preferences {
LATEST_BLOG_POST_ID_DISPLAYED("latestBlogPostIdDisplayed"),
LAST_BLOG_TIPS_RETRIEVAL("lastBlogTipsRetrieval"),
SHOW_BLOG_TIPS("showBlogTips"),
LAST_REVIEW_REQUEST_DATE("lastReviewRequestDate")
LAST_REVIEW_REQUEST_DATE("lastReviewRequestDate"),
PATCH_NEGATIVE_LIMITS("negativeLimits")
}
enum class FeedMessage {

Loading…
Cancel
Save