remove any month of year played before the first session when using upToNow

(cherry picked from commit 182c67124b)
feature/top10
Razmig Sarkissian 7 years ago
parent 3c3ebcece3
commit 1394e4ce85
  1. 22
      app/src/main/java/net/pokeranalytics/android/model/Criteria.kt

@ -24,6 +24,13 @@ fun List<List<QueryCondition>>.upToNow(): List<List<QueryCondition>> {
val currentYear = calendar.get(Calendar.YEAR) val currentYear = calendar.get(Calendar.YEAR)
val currentMonth = calendar.get(Calendar.MONTH) val currentMonth = calendar.get(Calendar.MONTH)
val realm = Realm.getDefaultInstance()
val firstSession = realm.where<Session>().sort("year", Sort.ASCENDING).findFirst()
realm.close()
val firstYear = firstSession?.year ?: currentYear
val firstMonth = firstSession?.month ?: currentMonth
val toRemove = this.filter { list -> val toRemove = this.filter { list ->
list.any { it is QueryCondition.AnyYear && it.listOfValues.first() == currentYear } list.any { it is QueryCondition.AnyYear && it.listOfValues.first() == currentYear }
}.filter { list -> }.filter { list ->
@ -32,6 +39,14 @@ fun List<List<QueryCondition>>.upToNow(): List<List<QueryCondition>> {
} }
} }
val toRemoveBefore = this.filter { list ->
list.any { it is QueryCondition.AnyYear && it.listOfValues.first() == firstYear }
}.filter { list ->
list.any {
it is QueryCondition.AnyMonthOfYear && it.listOfValues.first() < firstMonth
}
}
return this.filter{ list -> return this.filter{ list ->
var keep = true var keep = true
toRemove.forEach { toRemove.forEach {
@ -39,6 +54,13 @@ fun List<List<QueryCondition>>.upToNow(): List<List<QueryCondition>> {
keep = false keep = false
} }
} }
firstSession?.let {
toRemoveBefore.forEach {
if (list.containsAll(it)) {
keep = false
}
}
}
keep keep
} }
} }

Loading…
Cancel
Save