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 {
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()
session.result = Result()
if (bankroll != null) {

@ -71,27 +71,27 @@ class FavoriteSessionFinder {
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 =
favoriteSession(newSession.type, location, newSession.realm, context)
favoriteSession(session.type, location, session.realm, context)
favoriteSession?.let { fav ->
newSession.limit = fav.limit
newSession.game = fav.game
newSession.bankroll = fav.bankroll
newSession.tableSize = fav.tableSize
session.limit = fav.limit
session.game = fav.game
session.bankroll = fav.bankroll
session.tableSize = fav.tableSize
when (newSession.type) {
when (session.type) {
Session.Type.CASH_GAME.ordinal -> {
newSession.cgSmallBlind = fav.cgSmallBlind
newSession.cgBigBlind = fav.cgBigBlind
session.cgSmallBlind = fav.cgSmallBlind
session.cgBigBlind = fav.cgBigBlind
}
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.View
import android.view.ViewGroup
import android.widget.Toast
import androidx.core.app.ActivityOptionsCompat
import androidx.core.view.isVisible
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
@ -275,7 +274,7 @@ class FeedFragment : FilterableFragment(), RowRepresentableDelegate {
val sessionCount = this.feedSessionAdapter.realmResults.size
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())
return
}

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

Loading…
Cancel
Save