diff --git a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt index bf104448..f55b05e0 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt @@ -718,107 +718,110 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat } override fun updateValue(value: Any?, row: RowRepresentable) { - realm.beginTransaction() - when (row) { - SessionRow.BANKROLL -> bankroll = value as Bankroll? - SessionRow.BLINDS -> if (value is ArrayList<*>) { - cgSmallBlind = try { - (value[0] as String? ?: "0").toDouble() - } catch (e: Exception) { - null - } - - cgBigBlind = try { - (value[1] as String? ?: "0").toDouble() - } catch (e: Exception) { - null - } - - cgBigBlind?.let { - if (cgSmallBlind == null || cgSmallBlind == 0.0) { - cgSmallBlind = it / 2.0 - } - } - } else if (value == null) { - cgSmallBlind = null - cgBigBlind = null - } - SessionRow.BREAK_TIME -> { - this.breakDuration = if (value != null) (value as String).toLong() * 60 * 1000 else 0 - } - SessionRow.BUY_IN -> { - val localResult = if (this.result != null) this.result as Result else realm.createObject(Result::class.java) - localResult.buyin = value as Double? - this.result = localResult - this.updateRowRepresentation() - } - SessionRow.CASHED_OUT, SessionRow.PRIZE -> { - val localResult = if (this.result != null) this.result as Result else realm.createObject(Result::class.java) - - if (value == null) { - localResult.cashout = null - } else { - localResult.cashout = (value as String).toDouble() - } - - this.result = localResult - } - SessionRow.NET_RESULT -> { - this.result?.let { result -> - result.netResult = (value as String).toDouble() - } - } - SessionRow.COMMENT -> comment = value as String? ?: "" - SessionRow.END_DATE -> if (value is Date?) { - this.endDate = value + realm.executeTransaction { - } - SessionRow.GAME -> { - if (value is ArrayList<*>) { - limit = try { - (value[0] as Int?) + when (row) { + SessionRow.BANKROLL -> bankroll = value as Bankroll? + SessionRow.BLINDS -> if (value is ArrayList<*>) { + cgSmallBlind = try { + (value[0] as String? ?: "0").toDouble() } catch (e: Exception) { null } - game = try { - (value[1] as Game?) + + cgBigBlind = try { + (value[1] as String? ?: "0").toDouble() } catch (e: Exception) { null } - } else if (value is Game) { - game = value + + cgBigBlind?.let { + if (cgSmallBlind == null || cgSmallBlind == 0.0) { + cgSmallBlind = it / 2.0 + } + } } else if (value == null) { - limit = null - game = null + cgSmallBlind = null + cgBigBlind = null + } + SessionRow.BREAK_TIME -> { + this.breakDuration = if (value != null) (value as String).toLong() * 60 * 1000 else 0 + } + SessionRow.BUY_IN -> { + val localResult = if (this.result != null) this.result as Result else realm.createObject(Result::class.java) + localResult.buyin = value as Double? + this.result = localResult + this.updateRowRepresentation() + } + SessionRow.CASHED_OUT, SessionRow.PRIZE -> { + val localResult = if (this.result != null) this.result as Result else realm.createObject(Result::class.java) + + if (value == null) { + localResult.cashout = null + } else { + localResult.cashout = (value as String).toDouble() + } + this.result = localResult + } + SessionRow.NET_RESULT -> { + this.result?.let { result -> + result.netResult = (value as String).toDouble() + } + } + SessionRow.COMMENT -> comment = value as String? ?: "" + + SessionRow.END_DATE -> if (value is Date?) { + this.endDate = value + + } + SessionRow.GAME -> { + if (value is ArrayList<*>) { + limit = try { + (value[0] as Int?) + } catch (e: Exception) { + null + } + game = try { + (value[1] as Game?) + } catch (e: Exception) { + null + } + } else if (value is Game) { + game = value + } else if (value == null) { + limit = null + game = null + + } + } + SessionRow.INITIAL_BUY_IN -> tournamentEntryFee = if (value == null) null else (value as String).toDouble() + SessionRow.LOCATION -> location = value as Location? + SessionRow.PLAYERS -> tournamentNumberOfPlayers = if (value != null) (value as String).toInt() else null + SessionRow.POSITION -> { + val localResult = if (result != null) result as Result else realm.createObject(Result::class.java) + localResult.tournamentFinalPosition = if (value == null) null else (value as String).toInt() + result = localResult + } + SessionRow.START_DATE -> if (value is Date) { + this.startDate = value + } + SessionRow.TABLE_SIZE -> tableSize = value as Int? + SessionRow.TIPS -> { + val localResult = if (result != null) result as Result else realm.createObject(Result::class.java) + localResult.tips = value as Double? + result = localResult + } + SessionRow.TOURNAMENT_NAME -> tournamentName = value as TournamentName? + SessionRow.TOURNAMENT_TYPE -> tournamentType = value as Int? + SessionRow.TOURNAMENT_FEATURE -> value?.let { + tournamentFeatures = RealmList() + tournamentFeatures.addAll((it as ArrayList)) } - } - SessionRow.INITIAL_BUY_IN -> tournamentEntryFee = if (value == null) null else (value as String).toDouble() - SessionRow.LOCATION -> location = value as Location? - SessionRow.PLAYERS -> tournamentNumberOfPlayers = if (value != null) (value as String).toInt() else null - SessionRow.POSITION -> { - val localResult = if (result != null) result as Result else realm.createObject(Result::class.java) - localResult.tournamentFinalPosition = if (value == null) null else (value as String).toInt() - result = localResult - } - SessionRow.START_DATE -> if (value is Date) { - this.startDate = value - } - SessionRow.TABLE_SIZE -> tableSize = value as Int? - SessionRow.TIPS -> { - val localResult = if (result != null) result as Result else realm.createObject(Result::class.java) - localResult.tips = value as Double? - result = localResult - } - SessionRow.TOURNAMENT_NAME -> tournamentName = value as TournamentName? - SessionRow.TOURNAMENT_TYPE -> tournamentType = value as Int? - SessionRow.TOURNAMENT_FEATURE -> value?.let { - tournamentFeatures = RealmList() - tournamentFeatures.addAll((it as ArrayList)) } } - realm.commitTransaction() + } } diff --git a/app/src/main/java/net/pokeranalytics/android/model/utils/SessionSetManager.kt b/app/src/main/java/net/pokeranalytics/android/model/utils/SessionSetManager.kt index 611aa32c..c62b84c3 100644 --- a/app/src/main/java/net/pokeranalytics/android/model/utils/SessionSetManager.kt +++ b/app/src/main/java/net/pokeranalytics/android/model/utils/SessionSetManager.kt @@ -2,6 +2,7 @@ package net.pokeranalytics.android.model.utils import io.realm.RealmQuery import io.realm.RealmResults +import net.pokeranalytics.android.exceptions.ModelException import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.SessionSet import kotlin.math.max @@ -28,10 +29,10 @@ class SessionSetManager { } if (session.startDate == null) { - throw IllegalStateException("Start date should never be null here") + throw ModelException("Start date should never be null here") } if (session.endDate == null) { - throw IllegalStateException("End date should never be null here") + throw ModelException("End date should never be null here") } val endDate = session.endDate!! // tested above val startDate = session.startDate!! diff --git a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt index ddf62652..8bf03113 100644 --- a/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt +++ b/app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt @@ -89,13 +89,21 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate { val data = currentSession.editDescriptors(row) when (row) { SessionRow.START_DATE -> DateTimePickerManager.create(requireContext(),row,this,currentSession.startDate) - SessionRow.END_DATE -> DateTimePickerManager.create( - requireContext(), - row, - this, - currentSession.endDate ?: currentSession.startDate ?: Date(), - currentSession.startDate - ) + SessionRow.END_DATE -> { + + if (this.currentSession.startDate == null) { + Toast.makeText(context, R.string.session_missing_start_date, Toast.LENGTH_SHORT).show() + } else { + DateTimePickerManager.create( + requireContext(), + row, + this, + currentSession.endDate ?: currentSession.startDate ?: Date(), + currentSession.startDate + ) + } + + } SessionRow.BANKROLL -> { BottomSheetFragment.create(fragmentManager, row, this, data, false, CurrencyUtils.getCurrency(currentSession.bankroll)) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8da8384e..a3d7ff6b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -2,6 +2,10 @@ Poker Analytics + Please set a start date for the session + + + Address Suggestions %s deleted