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,19 +171,22 @@ class GradeDetailsPresenter @Inject constructor(
} }
private fun createGradeItems(items: List<GradeDetailsWithAverage>): List<GradeDetailsItem> { private fun createGradeItems(items: List<GradeDetailsWithAverage>): List<GradeDetailsItem> {
return items.filter { it.grades.isNotEmpty() }.map { (subject, average, points, _, grades) -> return items
val subItems = grades.map { .filter { it.grades.isNotEmpty() }
GradeDetailsItem(it, ViewType.ITEM) .sortedBy { it.subject }
} .map { (subject, average, points, _, grades) ->
val subItems = grades
.sortedByDescending { it.date }
.map { GradeDetailsItem(it, ViewType.ITEM) }
listOf(GradeDetailsItem(GradeDetailsHeader( listOf(GradeDetailsItem(GradeDetailsHeader(
subject = subject, subject = subject,
average = average, average = average,
pointsSum = points, pointsSum = points,
newGrades = grades.filter { grade -> !grade.isRead }.size, newGrades = grades.filter { grade -> !grade.isRead }.size,
grades = subItems grades = subItems
), ViewType.HEADER)) + if (preferencesRepository.isGradeExpandable) emptyList() else subItems ), ViewType.HEADER)) + if (preferencesRepository.isGradeExpandable) emptyList() else subItems
}.flatten() }.flatten()
} }
private fun updateGrade(grade: Grade) { private fun updateGrade(grade: Grade) {

View File

@ -103,14 +103,8 @@ class GradeSummaryPresenter @Inject constructor(
} }
private fun createGradeSummaryItems(items: List<GradeDetailsWithAverage>): List<GradeSummary> { private fun createGradeSummaryItems(items: List<GradeDetailsWithAverage>): List<GradeSummary> {
return items.map { return items
it.summary.copy(average = it.average) .sortedBy { it.subject }
} .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
}
} }
} }