From 68fdb167c2580e0a14d23b8f5c978993f7fd00b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Borcz?= Date: Mon, 15 Nov 2021 22:35:01 +0100 Subject: [PATCH] Sort items in homework and grade tiles on the dashboard (#1634) --- .../modules/dashboard/DashboardPresenter.kt | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt index f791fa0d0..2ec198be2 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardPresenter.kt @@ -316,18 +316,17 @@ class DashboardPresenter @Inject constructor( gradeRepository.getGrades(student, semester, forceRefresh) }.map { originalResource -> - val filteredSubjectWithGrades = originalResource.data?.first.orEmpty() - .filter { grade -> - grade.date.isAfter(LocalDate.now().minusDays(7)) - } - .groupBy { grade -> grade.subject } + val filteredSubjectWithGrades = originalResource.data?.first + .orEmpty() + .filter { it.date >= LocalDate.now().minusDays(7) } + .groupBy { it.subject } .mapValues { entry -> entry.value .take(5) - .sortedBy { grade -> grade.date } + .sortedByDescending { it.date } } .toList() - .sortedBy { subjectWithGrades -> subjectWithGrades.second[0].date } + .sortedByDescending { (_, grades) -> grades[0].date } .toMap() Resource( @@ -431,9 +430,9 @@ class DashboardPresenter @Inject constructor( }.map { homeworkResource -> val currentDate = LocalDate.now() - val filteredHomework = homeworkResource.data?.filter { - (it.date.isAfter(currentDate) || it.date == currentDate) && !it.isDone - } + val filteredHomework = homeworkResource.data + ?.filter { (it.date.isAfter(currentDate) || it.date == currentDate) && !it.isDone } + ?.sortedBy { it.date } homeworkResource.copy(data = filteredHomework) }.onEach {