Merge branch 'master' of gitlab.com:stax-river/poker-analytics

feature/top10
Aurelien Hubert 7 years ago
commit 83fa8a4f92
  1. 2
      app/src/main/java/net/pokeranalytics/android/PokerAnalyticsApplication.kt
  2. 30
      app/src/main/java/net/pokeranalytics/android/model/extensions/SessionExtensions.kt
  3. 8
      app/src/main/java/net/pokeranalytics/android/model/interfaces/Timed.kt
  4. 21
      app/src/main/java/net/pokeranalytics/android/model/realm/Session.kt
  5. 6
      app/src/main/java/net/pokeranalytics/android/model/realm/SessionSet.kt
  6. 12
      app/src/main/java/net/pokeranalytics/android/model/utils/SessionSetManager.kt
  7. 6
      app/src/main/java/net/pokeranalytics/android/ui/view/SessionRowView.kt
  8. 2
      app/src/main/java/net/pokeranalytics/android/util/DateExtension.kt

@ -63,7 +63,7 @@ class PokerAnalyticsApplication : Application() {
this.createDefaultData() this.createDefaultData()
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
this.createFakeSessions() // debug // this.createFakeSessions() // debug
} }
} }

@ -8,8 +8,7 @@ enum class SessionState {
PLANNED, PLANNED,
STARTED, STARTED,
PAUSED, PAUSED,
FINISHED, FINISHED
INVALID;
} }
/** /**
@ -21,32 +20,19 @@ fun Session.getState(): SessionState {
// if (timeFrame == null) { // if (timeFrame == null) {
// return SessionState.PENDING // return SessionState.PENDING
// } // }
val start = this.startDate
if (startDate > Date()) { if (start == null) {
return SessionState.PENDING
} else {
if (start > Date()) {
return SessionState.PLANNED return SessionState.PLANNED
} else if (endDate != null) { } else if (this.endDate != null) {
return SessionState.FINISHED return SessionState.FINISHED
} else if (this.pauseDate != null) { } else if (this.pauseDate != null) {
return SessionState.PAUSED return SessionState.PAUSED
} else { } else {
return SessionState.STARTED return SessionState.STARTED
} }
}
// val endDate = timeFrame?.endDate
// timeFrame?.let {sessionTimeFrame ->
// timeFrame?.startDate?.let {startDate ->
// if (startDate > Date()) {
// return SessionState.PLANNED
// } else if (endDate != null) {
// return SessionState.FINISHED
// } else if (sessionTimeFrame.paused) {
// return SessionState.PAUSED
// } else {
// return SessionState.STARTED
// }
// }
// }
// return SessionState.INVALID
} }

@ -4,7 +4,7 @@ import java.util.*
interface Timed { interface Timed {
var startDate: Date fun startDate() : Date?
fun endDate() : Date fun endDate() : Date
@ -16,7 +16,11 @@ interface Timed {
* Computes the net netDuration of the session * Computes the net netDuration of the session
*/ */
fun computeNetDuration() { fun computeNetDuration() {
this.netDuration = this.endDate().time - this.startDate.time - this.breakDuration this.startDate()?.let { start ->
this.netDuration = this.endDate().time - start.time - this.breakDuration
} ?: run {
this.netDuration = 0L
}
} }
var hourlyDuration: Double var hourlyDuration: Double

@ -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

@ -11,7 +11,7 @@ import java.util.*
open class SessionSet : RealmObject(), Timed { open class SessionSet : RealmObject(), Timed {
override var startDate: Date = Date() var startDate: Date = Date()
set(value) { set(value) {
field = value field = value
this.computeNetDuration() this.computeNetDuration()
@ -23,6 +23,10 @@ open class SessionSet : RealmObject(), Timed {
this.computeNetDuration() this.computeNetDuration()
} }
override fun startDate(): Date? {
return this.startDate
}
override fun endDate(): Date { override fun endDate(): Date {
return this.endDate return this.endDate
} }

@ -15,11 +15,11 @@ class SessionSetManager {
throw IllegalStateException("realm should be in transaction at this point") throw IllegalStateException("realm should be in transaction at this point")
} }
if (session.endDate == null) { if (session.startDate == null || session.endDate == null) {
throw IllegalStateException("End date should never be null here") throw IllegalStateException("Start or 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!!
val realm = session.realm val realm = session.realm
@ -57,7 +57,7 @@ class SessionSetManager {
val set = session.sessionSet val set = session.sessionSet
if (set != null) { if (set != null) {
set.startDate = session.startDate set.startDate = session.startDate!! // tested above
set.endDate = session.endDate!! set.endDate = session.endDate!!
} else { } else {
this.createSessionSet(session) this.createSessionSet(session)
@ -67,7 +67,7 @@ class SessionSetManager {
private fun createSessionSet(session: Session) { private fun createSessionSet(session: Session) {
val set: SessionSet = SessionSet.newInstance(session.realm) val set: SessionSet = SessionSet.newInstance(session.realm)
set.startDate = session.startDate set.startDate = session.startDate!!
set.endDate = session.endDate!! set.endDate = session.endDate!!
session.sessionSet = set session.sessionSet = set
} }
@ -78,7 +78,7 @@ class SessionSetManager {
*/ */
private fun mergeSessionGroups(session: Session, sessionSets: RealmResults<SessionSet>) { private fun mergeSessionGroups(session: Session, sessionSets: RealmResults<SessionSet>) {
var startDate = session.startDate var startDate = session.startDate!!
var endDate = session.endDate!! var endDate = session.endDate!!
// find earlier and later dates from all sets // find earlier and later dates from all sets

@ -98,10 +98,10 @@ class SessionRowView : FrameLayout {
// rowHistorySession.sessionInfoDurationIcon.isVisible = session.timeFrame != null // rowHistorySession.sessionInfoDurationIcon.isVisible = session.timeFrame != null
// rowHistorySession.sessionInfoDurationValue.isVisible = session.timeFrame != null // rowHistorySession.sessionInfoDurationValue.isVisible = session.timeFrame != null
// session.timeFrame?.let { // session.timeFrame?.let {
// rowHistorySession.sessionInfoDurationValue.text = session.getDuration() // rowHistorySession.sessionInfoDurationValue.text = session.getFormattedDuration()
// } // }
rowHistorySession.sessionInfoDurationValue.text = session.getDuration() rowHistorySession.sessionInfoDurationValue.text = session.getFormattedDuration()
// Location // Location
rowHistorySession.sessionInfoLocationIcon.isVisible = session.location != null rowHistorySession.sessionInfoLocationIcon.isVisible = session.location != null
@ -129,7 +129,7 @@ class SessionRowView : FrameLayout {
rowHistorySession.infoIcon.isVisible = true rowHistorySession.infoIcon.isVisible = true
rowHistorySession.infoIcon.setImageResource(R.drawable.ic_planned) rowHistorySession.infoIcon.setImageResource(R.drawable.ic_planned)
rowHistorySession.infoTitle.isVisible = true rowHistorySession.infoTitle.isVisible = true
rowHistorySession.infoTitle.text = session.startDate.shortTime() rowHistorySession.infoTitle.text = session.startDate!!.shortTime()
} else { } else {
rowHistorySession.gameResult.isVisible = true rowHistorySession.gameResult.isVisible = true
rowHistorySession.infoIcon.isVisible = false rowHistorySession.infoIcon.isVisible = false

@ -85,7 +85,7 @@ fun Date.getMonthAndYear(): String {
} }
// Return the netDuration between two dates // Return the netDuration between two dates
fun Date.getDuration(toDate: Date) : String { fun Date.getFormattedDuration(toDate: Date) : String {
val difference = (toDate.time - this.time).toInt() val difference = (toDate.time - this.time).toInt()
val numOfDays = (difference / (1000 * 60 * 60 * 24)) val numOfDays = (difference / (1000 * 60 * 60 * 24))
val hours = (difference / (1000 * 60 * 60)) val hours = (difference / (1000 * 60 * 60))

Loading…
Cancel
Save