Fixing crash when setting an end date before a start date

feature/top10
Laurent 7 years ago
parent b93dd5f9d1
commit b7bc885157
  1. 179
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  2. 5
      app/src/main/java/net/pokeranalytics/android/model/utils/SessionSetManager.kt
  3. 22
      app/src/main/java/net/pokeranalytics/android/ui/fragment/SessionFragment.kt
  4. 4
      app/src/main/res/values/strings.xml

@ -718,107 +718,110 @@ open class Session : RealmObject(), Savable, Editable, StaticRowRepresentableDat
} }
override fun updateValue(value: Any?, row: RowRepresentable) { 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?) { realm.executeTransaction {
this.endDate = value
} when (row) {
SessionRow.GAME -> { SessionRow.BANKROLL -> bankroll = value as Bankroll?
if (value is ArrayList<*>) { SessionRow.BLINDS -> if (value is ArrayList<*>) {
limit = try { cgSmallBlind = try {
(value[0] as Int?) (value[0] as String? ?: "0").toDouble()
} catch (e: Exception) { } catch (e: Exception) {
null null
} }
game = try {
(value[1] as Game?) cgBigBlind = try {
(value[1] as String? ?: "0").toDouble()
} catch (e: Exception) { } catch (e: Exception) {
null null
} }
} else if (value is Game) {
game = value cgBigBlind?.let {
if (cgSmallBlind == null || cgSmallBlind == 0.0) {
cgSmallBlind = it / 2.0
}
}
} else if (value == null) { } else if (value == null) {
limit = null cgSmallBlind = null
game = 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<TournamentFeature>))
} }
}
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<TournamentFeature>))
} }
} }
realm.commitTransaction()
} }
} }

@ -2,6 +2,7 @@ package net.pokeranalytics.android.model.utils
import io.realm.RealmQuery import io.realm.RealmQuery
import io.realm.RealmResults import io.realm.RealmResults
import net.pokeranalytics.android.exceptions.ModelException
import net.pokeranalytics.android.model.realm.Session import net.pokeranalytics.android.model.realm.Session
import net.pokeranalytics.android.model.realm.SessionSet import net.pokeranalytics.android.model.realm.SessionSet
import kotlin.math.max import kotlin.math.max
@ -28,10 +29,10 @@ class SessionSetManager {
} }
if (session.startDate == null) { 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) { 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 endDate = session.endDate!! // tested above
val startDate = session.startDate!! val startDate = session.startDate!!

@ -89,13 +89,21 @@ class SessionFragment : PokerAnalyticsFragment(), RowRepresentableDelegate {
val data = currentSession.editDescriptors(row) val data = currentSession.editDescriptors(row)
when (row) { when (row) {
SessionRow.START_DATE -> DateTimePickerManager.create(requireContext(),row,this,currentSession.startDate) SessionRow.START_DATE -> DateTimePickerManager.create(requireContext(),row,this,currentSession.startDate)
SessionRow.END_DATE -> DateTimePickerManager.create( SessionRow.END_DATE -> {
requireContext(),
row, if (this.currentSession.startDate == null) {
this, Toast.makeText(context, R.string.session_missing_start_date, Toast.LENGTH_SHORT).show()
currentSession.endDate ?: currentSession.startDate ?: Date(), } else {
currentSession.startDate DateTimePickerManager.create(
) requireContext(),
row,
this,
currentSession.endDate ?: currentSession.startDate ?: Date(),
currentSession.startDate
)
}
}
SessionRow.BANKROLL -> { SessionRow.BANKROLL -> {
BottomSheetFragment.create(fragmentManager, row, this, data, false, CurrencyUtils.getCurrency(currentSession.bankroll)) BottomSheetFragment.create(fragmentManager, row, this, data, false, CurrencyUtils.getCurrency(currentSession.bankroll))
} }

@ -2,6 +2,10 @@
<string name="app_name">Poker Analytics</string> <string name="app_name">Poker Analytics</string>
<!-- Not translated --> <!-- Not translated -->
<string name="session_missing_start_date">Please set a start date for the session</string>
<!--<string name="session_missing_end_date">Please set the end date for the session</string>-->
<!--<string name="default_error_message">Sorry, something went wrong...please contact us!</string>-->
<string name="address">Address</string> <string name="address">Address</string>
<string name="suggestions">Suggestions</string> <string name="suggestions">Suggestions</string>
<string name="data_deleted" formatted="false">%s deleted</string> <string name="data_deleted" formatted="false">%s deleted</string>

Loading…
Cancel
Save