diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/preferences/PreferencesRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/preferences/PreferencesRepository.kt index c76bcf1e..fa12622c 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/preferences/PreferencesRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/preferences/PreferencesRepository.kt @@ -5,6 +5,7 @@ import android.content.SharedPreferences import dagger.hilt.android.qualifiers.ApplicationContext import io.github.wulkanowy.R import io.github.wulkanowy.ui.modules.grade.GradeAverageMode +import io.github.wulkanowy.ui.modules.grade.GradeSortingMode import javax.inject.Inject import javax.inject.Singleton @@ -77,6 +78,9 @@ class PreferencesRepository @Inject constructor( val showWholeClassPlan: String get() = getString(R.string.pref_key_timetable_show_whole_class, R.string.pref_default_timetable_show_whole_class) + val gradeSortingMode: GradeSortingMode + get() = GradeSortingMode.getByValue(getString(R.string.pref_key_grade_sorting_mode, R.string.pref_default_grade_sorting_mode)) + val showTimetableTimers: Boolean get() = getBoolean(R.string.pref_key_timetable_show_timers, R.bool.pref_default_timetable_show_timers) diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/grade/GradeSortingMode.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/GradeSortingMode.kt new file mode 100644 index 00000000..1e6b26e8 --- /dev/null +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/grade/GradeSortingMode.kt @@ -0,0 +1,10 @@ +package io.github.wulkanowy.ui.modules.grade + +enum class GradeSortingMode(val value: String) { + ALPHABETIC("alphabetic"), + DATE("date"); + + companion object { + fun getByValue(value: String) = values().firstOrNull { it.value == value } ?: ALPHABETIC + } +} \ No newline at end of file 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 3dfa0206..97b7b71c 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 @@ -1,5 +1,6 @@ package io.github.wulkanowy.ui.modules.grade.details +import android.annotation.SuppressLint import io.github.wulkanowy.data.Status import io.github.wulkanowy.data.db.entities.Grade import io.github.wulkanowy.data.repositories.grade.GradeRepository @@ -10,6 +11,8 @@ import io.github.wulkanowy.ui.base.BasePresenter import io.github.wulkanowy.ui.base.ErrorHandler import io.github.wulkanowy.ui.modules.grade.GradeAverageProvider import io.github.wulkanowy.ui.modules.grade.GradeDetailsWithAverage +import io.github.wulkanowy.ui.modules.grade.GradeSortingMode.ALPHABETIC +import io.github.wulkanowy.ui.modules.grade.GradeSortingMode.DATE import io.github.wulkanowy.utils.FirebaseAnalyticsHelper import io.github.wulkanowy.utils.afterLoading import io.github.wulkanowy.utils.flowWithResource @@ -184,10 +187,20 @@ class GradeDetailsPresenter @Inject constructor( } } + @SuppressLint("DefaultLocale") private fun createGradeItems(items: List): List { return items - .let { if (!preferencesRepository.showSubjectsWithoutGrades) it.filter { it.grades.isNotEmpty() } else it.filter { true }} - .sortedBy { it.subject } + .let { gradesWithAverages -> + if (!preferencesRepository.showSubjectsWithoutGrades) { + gradesWithAverages.filter { it.grades.isNotEmpty() } + } else gradesWithAverages + } + .let { + when (preferencesRepository.gradeSortingMode) { + DATE -> it.sortedByDescending { gradeDetailsWithAverage -> gradeDetailsWithAverage.grades.firstOrNull()?.date } + ALPHABETIC -> it.sortedBy { gradeDetailsWithAverage -> gradeDetailsWithAverage.subject.toLowerCase() } + } + } .map { (subject, average, points, _, grades) -> val subItems = grades .sortedByDescending { it.date } diff --git a/app/src/main/res/values-pl/preferences_values.xml b/app/src/main/res/values-pl/preferences_values.xml index 1d81fb58..c57d2be5 100644 --- a/app/src/main/res/values-pl/preferences_values.xml +++ b/app/src/main/res/values-pl/preferences_values.xml @@ -29,6 +29,10 @@ 0,5 0,75 + + Alfabetycznie + Według daty + Dzienniczek+ Wulkanowy diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index 28204419..33017452 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -399,6 +399,7 @@ Pokazuj lekcje całej klasy Pokazuj przedmioty bez ocen w Oceny Schemat kolorów ocen + Sortowanie przedmiotów w "Oceny" Język aplikacji Powiadomienia Pokazuj powiadomienia diff --git a/app/src/main/res/values/preferences_defaults.xml b/app/src/main/res/values/preferences_defaults.xml index bb987271..d42cfc32 100644 --- a/app/src/main/res/values/preferences_defaults.xml +++ b/app/src/main/res/values/preferences_defaults.xml @@ -19,6 +19,7 @@ 0.33 true no + alphabetic false false false diff --git a/app/src/main/res/values/preferences_keys.xml b/app/src/main/res/values/preferences_keys.xml index d948dc47..e9f9054e 100644 --- a/app/src/main/res/values/preferences_keys.xml +++ b/app/src/main/res/values/preferences_keys.xml @@ -20,6 +20,7 @@ grade_modifier_plus grade_modifier_minus fill_message_content + grade_sorting_mode show_whole_class_plan timetable_show_timers homework_fullscreen diff --git a/app/src/main/res/values/preferences_values.xml b/app/src/main/res/values/preferences_values.xml index 5824658c..06a9d8c4 100644 --- a/app/src/main/res/values/preferences_values.xml +++ b/app/src/main/res/values/preferences_values.xml @@ -75,6 +75,15 @@ 0.75 + + Alphabetic + By date + + + alphabetic + date + + Dzienniczek+ Wulkanowy diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b917ad5d..073e7738 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -415,6 +415,7 @@ Show whole class lessons Show subjects without grades in Grades Grades color scheme + Subjects sorting in "Grades" App language Notifications diff --git a/app/src/main/res/xml/scheme_preferences.xml b/app/src/main/res/xml/scheme_preferences.xml index bbb2aaeb..99cb3366 100644 --- a/app/src/main/res/xml/scheme_preferences.xml +++ b/app/src/main/res/xml/scheme_preferences.xml @@ -62,6 +62,14 @@ app:key="@string/pref_key_grade_color_scheme" app:title="@string/pref_view_grade_color_scheme" app:useSimpleSummaryProvider="true" /> +