|
|
|
@ -33,10 +33,17 @@ class SessionSetManager { |
|
|
|
if (session.endDate == null) { |
|
|
|
if (session.endDate == null) { |
|
|
|
throw ModelException("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!! |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val sessionSets = this.matchingSets(session) |
|
|
|
|
|
|
|
cleanupSessionSets(session, sessionSets) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun matchingSets(session: Session) : RealmResults<SessionSet> { |
|
|
|
val realm = session.realm |
|
|
|
val realm = session.realm |
|
|
|
|
|
|
|
val endDate = session.endDate!! // tested above |
|
|
|
|
|
|
|
val startDate = session.startDate!! |
|
|
|
|
|
|
|
|
|
|
|
val query: RealmQuery<SessionSet> = realm.where(SessionSet::class.java) |
|
|
|
val query: RealmQuery<SessionSet> = realm.where(SessionSet::class.java) |
|
|
|
|
|
|
|
|
|
|
|
@ -50,12 +57,37 @@ class SessionSetManager { |
|
|
|
.greaterThanOrEqualTo("startDate", startDate) |
|
|
|
.greaterThanOrEqualTo("startDate", startDate) |
|
|
|
.lessThanOrEqualTo("endDate", endDate) |
|
|
|
.lessThanOrEqualTo("endDate", endDate) |
|
|
|
|
|
|
|
|
|
|
|
val sessionGroups = query.findAll() |
|
|
|
return query.findAll() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Multiple session sets update: |
|
|
|
|
|
|
|
* Merges or splits session sets |
|
|
|
|
|
|
|
* Does that by deleting then recreating |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private fun cleanupSessionSets(session: Session, sessionSets: RealmResults<SessionSet>) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// get all endedSessions from sets |
|
|
|
|
|
|
|
val allImpactedSessions = mutableSetOf<Session>() |
|
|
|
|
|
|
|
sessionSets.forEach { set -> |
|
|
|
|
|
|
|
set.sessions?.asIterable()?.let { allImpactedSessions.addAll(it) } |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
allImpactedSessions.add(session) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// delete all sets |
|
|
|
|
|
|
|
sessionSets.deleteAllFromRealm() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
allImpactedSessions.forEach { session -> |
|
|
|
|
|
|
|
val sets = matchingSets(session) |
|
|
|
|
|
|
|
this.updateTimeFrames(sets, session) |
|
|
|
|
|
|
|
// updateTimeline(session) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.updateTimeFrames(sessionGroups, session) |
|
|
|
// Timber.d("netDuration 3 = : ${set.timeFrame?.netDuration}") |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Update the global timeline using the impacted [sessionSets] and the updated [session] |
|
|
|
* Update the global timeline using the impacted [sessionSets] and the updated [session] |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|