|
|
|
@ -68,12 +68,12 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen |
|
|
|
/** |
|
|
|
/** |
|
|
|
* The start date of the session |
|
|
|
* The start date of the session |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
override var startDate: Date = Date() |
|
|
|
var startDate: Date? = null |
|
|
|
set(value) { |
|
|
|
set(value) { |
|
|
|
field = value |
|
|
|
field = value |
|
|
|
this.computeNetDuration() |
|
|
|
this.computeNetDuration() |
|
|
|
// nullifies endate when setting the start date after the end date |
|
|
|
// nullifies endate when setting the start date after the end date |
|
|
|
if (this.endDate != null && this.startDate.after(this.endDate)) { |
|
|
|
if (value != null && this.endDate != null && value.after(this.endDate)) { |
|
|
|
this.endDate = null |
|
|
|
this.endDate = null |
|
|
|
} |
|
|
|
} |
|
|
|
this.dateChanged() |
|
|
|
this.dateChanged() |
|
|
|
@ -192,6 +192,10 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen |
|
|
|
return this.endDate ?: Date() |
|
|
|
return this.endDate ?: Date() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun startDate(): Date? { |
|
|
|
|
|
|
|
return this.startDate |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return if this session is a tournament |
|
|
|
* Return if this session is a tournament |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -251,7 +255,7 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen |
|
|
|
val hourlyRate: Double |
|
|
|
val hourlyRate: Double |
|
|
|
get() { |
|
|
|
get() { |
|
|
|
this.result?.let { result -> |
|
|
|
this.result?.let { result -> |
|
|
|
return result.net / this.netDuration.toDouble() |
|
|
|
return result.net / this.hourlyDuration |
|
|
|
} |
|
|
|
} |
|
|
|
throw ModelException("Session should have an existing Result relationship") |
|
|
|
throw ModelException("Session should have an existing Result relationship") |
|
|
|
} |
|
|
|
} |
|
|
|
@ -358,9 +362,8 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Return the netDuration of the current session |
|
|
|
* Return the netDuration of the current session |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
fun getDuration(): String { |
|
|
|
fun getFormattedDuration(): String { |
|
|
|
val enDate = this.endDate ?: Date() |
|
|
|
return this.netDuration.toMinutes() |
|
|
|
return startDate.getDuration(enDate) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -436,7 +439,7 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen |
|
|
|
rows.add( |
|
|
|
rows.add( |
|
|
|
HeaderRowRepresentable( |
|
|
|
HeaderRowRepresentable( |
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
title = getDuration(), |
|
|
|
title = getFormattedDuration(), |
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) |
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
@ -456,7 +459,7 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen |
|
|
|
rows.add( |
|
|
|
rows.add( |
|
|
|
HeaderRowRepresentable( |
|
|
|
HeaderRowRepresentable( |
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
RowViewType.HEADER_TITLE_AMOUNT_BIG, |
|
|
|
title = getDuration(), |
|
|
|
title = getFormattedDuration(), |
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) |
|
|
|
computedStat = ComputedStat(Stat.NETRESULT, result?.net ?: 0.0) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
@ -510,7 +513,7 @@ open class Session : RealmObject(), SessionInterface, Savable, StaticRowRepresen |
|
|
|
SessionRow.LOCATION -> location?.name ?: NULL_TEXT |
|
|
|
SessionRow.LOCATION -> location?.name ?: NULL_TEXT |
|
|
|
SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: NULL_TEXT |
|
|
|
SessionRow.PLAYERS -> tournamentNumberOfPlayers?.toString() ?: NULL_TEXT |
|
|
|
SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: NULL_TEXT |
|
|
|
SessionRow.POSITION -> result?.tournamentFinalPosition?.toString() ?: NULL_TEXT |
|
|
|
SessionRow.START_DATE -> this.startDate.shortDateTime() |
|
|
|
SessionRow.START_DATE -> this.startDate?.shortDateTime() ?: NULL_TEXT |
|
|
|
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT |
|
|
|
SessionRow.TABLE_SIZE -> this.tableSize?.let { TableSize(it).localizedTitle(context) } ?: NULL_TEXT |
|
|
|
SessionRow.TIPS -> result?.tips?.toCurrency() ?: NULL_TEXT |
|
|
|
SessionRow.TIPS -> result?.tips?.toCurrency() ?: NULL_TEXT |
|
|
|
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: NULL_TEXT |
|
|
|
SessionRow.TOURNAMENT_TYPE -> tournamentType?.name ?: NULL_TEXT |
|
|
|
|