Add subjects sorting in grades
MODIFY
app/src/main/java/io/github/wulkanowy/data/repositories/preferences/PreferencesRepository.kt
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)

ADD
app/src/main/java/io/github/wulkanowy/ui/modules/grade/GradeSortingMode.kt
+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

MODIFY
app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt
app/src/main/java/io/github/wulkanowy/ui/modules/grade/details/GradeDetailsPresenter.kt
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<GradeDetailsWithAverage>): List<GradeDetailsItem> {
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 }

MODIFY
app/src/main/res/values/preferences_defaults.xml
app/src/main/res/values/preferences_defaults.xml
<string name="pref_default_grade_modifier_minus">0.33</string>
<bool name="pref_default_fill_message_content">true</bool>
<string name="pref_default_timetable_show_whole_class">no</string>
+ <string name="pref_default_grade_sorting_mode">alphabetic</string>
<bool name="pref_default_timetable_show_timers">false</bool>
<bool name="pref_default_homework_fullscreen">false</bool>
<bool name="pref_default_subjects_without_grades">false</bool>

MODIFY
app/src/main/res/values/preferences_keys.xml
app/src/main/res/values/preferences_keys.xml
<string name="pref_key_grade_modifier_plus">grade_modifier_plus</string>
<string name="pref_key_grade_modifier_minus">grade_modifier_minus</string>
<string name="pref_key_fill_message_content">fill_message_content</string>
+ <string name="pref_key_grade_sorting_mode">grade_sorting_mode</string>
<string name="pref_key_timetable_show_whole_class">show_whole_class_plan</string>
<string name="pref_key_timetable_show_timers">timetable_show_timers</string>
<string name="pref_key_homework_fullscreen">homework_fullscreen</string>

MODIFY
app/src/main/res/values/preferences_values.xml
app/src/main/res/values/preferences_values.xml
<item>0.75</item>
</string-array>
+ <string-array name="grade_sorting_mode_entries">
+ <item>Alphabetic</item>
+ <item>By date</item>
+ </string-array>
+ <string-array name="grade_sorting_mode_values" translatable="false">
+ <item>alphabetic</item>
+ <item>date</item>
+ </string-array>
+
<string-array name="grade_color_scheme_entries">
<item>Dzienniczek+</item>
<item>Wulkanowy</item>

MODIFY
app/src/main/res/values/strings.xml
app/src/main/res/values/strings.xml
<string name="pref_view_timetable_show_whole_class">Show whole class lessons</string>
<string name="pref_view_subjects_without_grades">Show subjects without grades in Grades</string>
<string name="pref_view_grade_color_scheme">Grades color scheme</string>
+ <string name="pref_view_grade_sorting_mode">Subjects sorting in "Grades"</string>
<string name="pref_view_app_language">App language</string>
<string name="pref_notify_header">Notifications</string>

MODIFY
app/src/main/res/xml/scheme_preferences.xml
app/src/main/res/xml/scheme_preferences.xml
app:key="@string/pref_key_grade_color_scheme"
app:title="@string/pref_view_grade_color_scheme"
app:useSimpleSummaryProvider="true" />
+ <ListPreference
+ app:defaultValue="@string/pref_default_grade_sorting_mode"
+ app:entries="@array/grade_sorting_mode_entries"
+ app:entryValues="@array/grade_sorting_mode_values"
+ app:iconSpaceReserved="false"
+ app:key="@string/pref_key_grade_sorting_mode"
+ app:title="@string/pref_view_grade_sorting_mode"
+ app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="@string/pref_default_app_language"
app:entries="@array/app_language_entries"

Add subjects sorting in grades (#946)