Fixing crash when adding a session

csv
Laurent 6 years ago
parent 59e33ada31
commit ac8c0fdd54
  1. 2
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 22
      app/src/main/java/net/pokeranalytics/android/model/utils/FavoriteSessionFinder.kt
  3. 3
      app/src/main/java/net/pokeranalytics/android/ui/fragment/FeedFragment.kt
  4. 28
      app/src/main/java/net/pokeranalytics/android/util/csv/CSVDescriptor.kt

@ -68,7 +68,7 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
companion object { companion object {
fun newInstance(realm: Realm, isTournament: Boolean, bankroll: Bankroll? = null, managed: Boolean = false): Session { fun newInstance(realm: Realm, isTournament: Boolean, bankroll: Bankroll? = null, managed: Boolean = true): Session {
val session = Session() val session = Session()
session.result = Result() session.result = Result()
if (bankroll != null) { if (bankroll != null) {

@ -71,27 +71,27 @@ class FavoriteSessionFinder {
private const val FAVORITE_SIGNIFICANT_SESSIONS = 15L private const val FAVORITE_SIGNIFICANT_SESSIONS = 15L
/** /**
* Copies the favorite session parameters on the [newSession] * Copies the favorite session parameters on the [session]
*/ */
fun copyParametersFromFavoriteSession(newSession: Session, location: Location?, context: Context) { fun copyParametersFromFavoriteSession(session: Session, location: Location?, context: Context) {
val favoriteSession = val favoriteSession =
favoriteSession(newSession.type, location, newSession.realm, context) favoriteSession(session.type, location, session.realm, context)
favoriteSession?.let { fav -> favoriteSession?.let { fav ->
newSession.limit = fav.limit session.limit = fav.limit
newSession.game = fav.game session.game = fav.game
newSession.bankroll = fav.bankroll session.bankroll = fav.bankroll
newSession.tableSize = fav.tableSize session.tableSize = fav.tableSize
when (newSession.type) { when (session.type) {
Session.Type.CASH_GAME.ordinal -> { Session.Type.CASH_GAME.ordinal -> {
newSession.cgSmallBlind = fav.cgSmallBlind session.cgSmallBlind = fav.cgSmallBlind
newSession.cgBigBlind = fav.cgBigBlind session.cgBigBlind = fav.cgBigBlind
} }
Session.Type.TOURNAMENT.ordinal -> { Session.Type.TOURNAMENT.ordinal -> {
newSession.tournamentEntryFee = fav.tournamentEntryFee session.tournamentEntryFee = fav.tournamentEntryFee
} }
} }
} }

@ -6,7 +6,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Toast
import androidx.core.app.ActivityOptionsCompat import androidx.core.app.ActivityOptionsCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import androidx.interpolator.view.animation.FastOutSlowInInterpolator import androidx.interpolator.view.animation.FastOutSlowInInterpolator
@ -275,7 +274,7 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
val sessionCount = this.feedSessionAdapter.realmResults.size val sessionCount = this.feedSessionAdapter.realmResults.size
if (!AppGuard.isProUser && sessionCount >= AppGuard.MAX_SESSIONS_BEFORE_REQUESTING_SUBSCRIPTION) { // && !BuildConfig.DEBUG if (!AppGuard.isProUser && sessionCount >= AppGuard.MAX_SESSIONS_BEFORE_REQUESTING_SUBSCRIPTION) { // && !BuildConfig.DEBUG
Toast.makeText(context, "Please subscribe!", Toast.LENGTH_LONG).show() // Toast.makeText(context, "Please subscribe!", Toast.LENGTH_LONG).show()
BillingActivity.newInstance(requireContext()) BillingActivity.newInstance(requireContext())
return return
} }

@ -42,18 +42,26 @@ abstract class DataCSVDescriptor<T : Identifiable>(source: DataSource, vararg el
override fun cancel(realm: Realm) { override fun cancel(realm: Realm) {
// Timber.d(">>>>>>> Start delete of ${realmModelIds.size}") if (realm.isInTransaction) {
this.deleteInsertedFromRealm(realm)
realm.executeTransaction { } else {
this.realmModelIds.forEach { identifier -> realm.executeTransaction {
val data = realm.findById(identifier.clazz, identifier.id) this.deleteInsertedFromRealm(realm)
if (data is Session) {
data.cleanup()
}
data?.deleteFromRealm()
} }
this.realmModelIds.clear()
} }
}
private fun deleteInsertedFromRealm(realm: Realm) {
this.realmModelIds.forEach { identifier ->
val data = realm.findById(identifier.clazz, identifier.id)
if (data is Session) {
data.cleanup()
}
data?.deleteFromRealm()
}
this.realmModelIds.clear()
} }
override fun save(realm: Realm) { override fun save(realm: Realm) {

Loading…
Cancel
Save