Fix grade sorting (#825)

This commit is contained in:
Mikołaj Pich 2020-05-24 19:23:35 +02:00 committed by GitHub
parent d558c4db66
commit c3a6f8253a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 21 deletions

View File

@ -171,10 +171,13 @@ class GradeDetailsPresenter @Inject constructor(
}
private fun createGradeItems(items: List<GradeDetailsWithAverage>): List<GradeDetailsItem> {
return items.filter { it.grades.isNotEmpty() }.map { (subject, average, points, _, grades) ->
val subItems = grades.map {
GradeDetailsItem(it, ViewType.ITEM)
}
return items
.filter { it.grades.isNotEmpty() }
.sortedBy { it.subject }
.map { (subject, average, points, _, grades) ->
val subItems = grades
.sortedByDescending { it.date }
.map { GradeDetailsItem(it, ViewType.ITEM) }
listOf(GradeDetailsItem(GradeDetailsHeader(
subject = subject,

View File

@ -103,14 +103,8 @@ class GradeSummaryPresenter @Inject constructor(
}
private fun createGradeSummaryItems(items: List<GradeDetailsWithAverage>): List<GradeSummary> {
return items.map {
it.summary.copy(average = it.average)
}
}
private fun checkEmpty(gradeSummary: GradeSummary, averages: List<Triple<String, Double, String>>): Boolean {
return gradeSummary.run {
finalGrade.isBlank() && predictedGrade.isBlank() && averages.singleOrNull { it.first == subject } == null
}
return items
.sortedBy { it.subject }
.map { it.summary.copy(average = it.average) }
}
}