diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt index 26c22264..2212bfd6 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt @@ -171,19 +171,22 @@ class GradeDetailsPresenter @Inject constructor( } private fun createGradeItems(items: List): List { - 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, - average = average, - pointsSum = points, - newGrades = grades.filter { grade -> !grade.isRead }.size, - grades = subItems - ), ViewType.HEADER)) + if (preferencesRepository.isGradeExpandable) emptyList() else subItems - }.flatten() + listOf(GradeDetailsItem(GradeDetailsHeader( + subject = subject, + average = average, + pointsSum = points, + newGrades = grades.filter { grade -> !grade.isRead }.size, + grades = subItems + ), ViewType.HEADER)) + if (preferencesRepository.isGradeExpandable) emptyList() else subItems + }.flatten() } private fun updateGrade(grade: Grade) { diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryPresenter.kt index 9b837213..26f922de 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/summary/GradeSummaryPresenter.kt @@ -103,14 +103,8 @@ class GradeSummaryPresenter @Inject constructor( } private fun createGradeSummaryItems(items: List): List { - return items.map { - it.summary.copy(average = it.average) - } - } - - private fun checkEmpty(gradeSummary: GradeSummary, averages: List>): 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) } } }