|
|
|
|
@ -4,11 +4,19 @@ import io.realm.RealmQuery |
|
|
|
|
import io.realm.RealmResults |
|
|
|
|
import net.pokeranalytics.android.model.realm.Session |
|
|
|
|
import net.pokeranalytics.android.model.realm.SessionSet |
|
|
|
|
import kotlin.math.max |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* The manager is in charge of updating the abstract concept of timeline, |
|
|
|
|
* representing the sequenced time frames where the user plays. |
|
|
|
|
*/ |
|
|
|
|
class SessionSetManager { |
|
|
|
|
|
|
|
|
|
companion object { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Updates the global timeline using the updated [session] |
|
|
|
|
*/ |
|
|
|
|
fun updateTimeline(session: Session) { |
|
|
|
|
|
|
|
|
|
if (!session.realm.isInTransaction) { |
|
|
|
|
@ -42,7 +50,7 @@ class SessionSetManager { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Update Time frames from sets |
|
|
|
|
* Update the global timeline using the impacted [sessionSets] and the updated [session] |
|
|
|
|
*/ |
|
|
|
|
private fun updateTimeFrames(sessionSets: RealmResults<SessionSet>, session: Session) { |
|
|
|
|
|
|
|
|
|
@ -53,6 +61,9 @@ class SessionSetManager { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Creates or update the session set for the [session] |
|
|
|
|
*/ |
|
|
|
|
private fun createOrUpdateSessionSet(session: Session) { |
|
|
|
|
|
|
|
|
|
val set = session.sessionSet |
|
|
|
|
@ -65,10 +76,14 @@ class SessionSetManager { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Create a set and affect it to the [session] |
|
|
|
|
*/ |
|
|
|
|
private fun createSessionSet(session: Session) { |
|
|
|
|
val set: SessionSet = SessionSet.newInstance(session.realm) |
|
|
|
|
set.startDate = session.startDate!! |
|
|
|
|
set.endDate = session.endDate!! |
|
|
|
|
set.breakDuration = session.breakDuration |
|
|
|
|
session.sessionSet = set |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -109,11 +124,17 @@ class SessionSetManager { |
|
|
|
|
session.sessionSet = set |
|
|
|
|
|
|
|
|
|
// Add all orphan endedSessions |
|
|
|
|
sessions.forEach { it.sessionSet = set } |
|
|
|
|
sessions.forEach { session -> |
|
|
|
|
session.sessionSet = set |
|
|
|
|
set.breakDuration = max(set.breakDuration, session.breakDuration) |
|
|
|
|
} |
|
|
|
|
// Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}") |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Removes the [session] from the timeline |
|
|
|
|
*/ |
|
|
|
|
fun removeFromTimeline(session: Session) { |
|
|
|
|
|
|
|
|
|
if (!session.realm.isInTransaction) { |
|
|
|
|
|