diff --git a/app/src/main/java/io/github/wulkanowy/data/db/dao/GradeDao.kt b/app/src/main/java/io/github/wulkanowy/data/db/dao/GradeDao.kt index 3d0cf15f..ff332618 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/dao/GradeDao.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/dao/GradeDao.kt @@ -14,6 +14,6 @@ interface GradeDao : BaseDao { fun loadAll(semesterId: Int, studentId: Int): Flow> @Query("SELECT * FROM Grades WHERE semester_id = :semesterId AND student_id = :studentId " + - "AND entry NOT IN ('1', '1+', '2', '2+', '2-')") - fun loadAllCensored(semesterId: Int, studentId: Int): Flow> + "AND entry NOT IN(:censoredEntries)") + fun loadAllCensored(semesterId: Int, studentId: Int, censoredEntries: Array): Flow> } diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/GradeRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/GradeRepository.kt index c328be44..b271939d 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/GradeRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/GradeRepository.kt @@ -39,16 +39,10 @@ class GradeRepository @Inject constructor( private val saveFetchResultMutex = Mutex() private fun loadGrades(semesterId: Int, studentId: Int): Flow> { - val badGradesHidden = preferencesRepository - .selectedHiddenSettingTiles - .contains(DashboardItem.HiddenSettingTile.BAD_GRADES) + val hiddenGrades = preferencesRepository.hiddenGrades - Timber.i("Load grades for semester $semesterId student $studentId / $badGradesHidden") - return if (badGradesHidden) { - gradeDb.loadAllCensored(semesterId, studentId) - } else { - gradeDb.loadAll(semesterId, studentId) - } + Timber.i("Load grades for semester $semesterId student $studentId") + return gradeDb.loadAllCensored(semesterId, studentId, hiddenGrades.toTypedArray()) } fun getGrades( @@ -78,19 +72,13 @@ class GradeRepository @Inject constructor( } }, fetch = { - val badGradesHidden = preferencesRepository - .selectedHiddenSettingTiles - .contains(DashboardItem.HiddenSettingTile.BAD_GRADES) + val hiddenGrades = preferencesRepository.hiddenGrades val (details, summary, descriptive) = sdk.init(student) .switchSemester(semester) .getGrades(semester.semesterId) - val censoredDetails = if (badGradesHidden) { - details.filter { !listOf("1", "1+", "2", "2+", "2-").contains(it.entry) } - } else { - details - } + val censoredDetails = details.filterNot { it.entry in hiddenGrades } Triple( censoredDetails.mapToEntities(semester), diff --git a/app/src/main/java/io/github/wulkanowy/data/repositories/PreferencesRepository.kt b/app/src/main/java/io/github/wulkanowy/data/repositories/PreferencesRepository.kt index 7b356244..ed3fda07 100644 --- a/app/src/main/java/io/github/wulkanowy/data/repositories/PreferencesRepository.kt +++ b/app/src/main/java/io/github/wulkanowy/data/repositories/PreferencesRepository.kt @@ -297,6 +297,18 @@ class PreferencesRepository @Inject constructor( set(value) = value?.let { attendancePercentagePreference.set(it) } ?: attendancePercentagePreference.delete() + var hiddenGrades: List + get() = hiddenGradesPreference.get().toList() + set(value) = hiddenGradesPreference.set(value.toSet()) + + private val hiddenGradesPreference: Preference> + get() { + val defaultSet = context.resources.getStringArray(R.array.pref_default_hidden_grades).toSet() + val prefKey = "hidden_grades" + + return flowSharedPref.getStringSet(prefKey, defaultSet) + } + private val selectedDashboardTilesPreference: Preference> get() { val defaultSet = diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardItem.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardItem.kt index 30bf9480..6a05b105 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardItem.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/dashboard/DashboardItem.kt @@ -149,7 +149,6 @@ sealed class DashboardItem(val type: Type) { } enum class HiddenSettingTile { - BAD_GRADES, BAD_ATTENDANCE, NOTES, ATTENDANCE, diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreFragment.kt index 51ef0178..3cb8479c 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MoreFragment.kt @@ -105,6 +105,25 @@ class MoreFragment : BaseFragment(R.layout.fragment_more), super.onDestroyView() } + private fun showGradeDialog() { + val hiddenGrades = preferencesRepository.hiddenGrades + + val grades = requireContext().resources.getStringArray(R.array.hidden_settings_bad_grades) + val selectedItemsState = grades.map { grade -> hiddenGrades.any { it == grade } } + + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.pref_hidden_settings_bad_grades_title) + .setMultiChoiceItems(grades, selectedItemsState.toBooleanArray()) { _, _, _ -> } + .setPositiveButton(android.R.string.ok) { dialog, _ -> + val selectedState = (dialog as AlertDialog).listView.checkedItemPositions + val selectedValues = grades.filterIndexed { index, _ -> selectedState[index] } + + Timber.i("Selected hidden grades: $selectedValues") + presenter.onHiddenGradesSelected(selectedValues) + } + .show() + } + override fun showHiddenSettings(data: List) { val entries = requireContext().resources.getStringArray(R.array.hidden_settings_entries) val values = requireContext().resources.getStringArray(R.array.hidden_settings_values) @@ -144,6 +163,7 @@ class MoreFragment : BaseFragment(R.layout.fragment_more), presenter.onHiddenSettingsSelected(selectedValues, inputAttendancePercentage) } .setNegativeButton(android.R.string.cancel) { _, _ -> } + .setNeutralButton(R.string.pref_hidden_settings_bad_grades_title) { _, _ -> showGradeDialog() } .show() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MorePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MorePresenter.kt index dd586d41..7e36e3c8 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/more/MorePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/more/MorePresenter.kt @@ -55,6 +55,11 @@ class MorePresenter @Inject constructor( view?.restartApp() } + fun onHiddenGradesSelected(selectedItems: List) { + preferencesRepository.hiddenGrades = selectedItems + view?.restartApp() + } + fun onViewReselected() { Timber.i("More view is reselected") view?.popView(2) diff --git a/app/src/main/res/values-cs/preferences_values.xml b/app/src/main/res/values-cs/preferences_values.xml index 425fe8ae..948e61ec 100644 --- a/app/src/main/res/values-cs/preferences_values.xml +++ b/app/src/main/res/values-cs/preferences_values.xml @@ -69,7 +69,6 @@ - Špatné hodnocení Špatná účast Poznámky Falešná účast diff --git a/app/src/main/res/values-da-rDK/preferences_values.xml b/app/src/main/res/values-da-rDK/preferences_values.xml index b2760e11..fc3cbf0b 100644 --- a/app/src/main/res/values-da-rDK/preferences_values.xml +++ b/app/src/main/res/values-da-rDK/preferences_values.xml @@ -68,7 +68,6 @@ Conferences - Bad grades Bad attendance Notes Fake attendance diff --git a/app/src/main/res/values-de/preferences_values.xml b/app/src/main/res/values-de/preferences_values.xml index 309f56c5..c2a3f556 100644 --- a/app/src/main/res/values-de/preferences_values.xml +++ b/app/src/main/res/values-de/preferences_values.xml @@ -68,7 +68,6 @@ Sitzungen - Schlechte Noten Schlechte Anwesenheit Notizen Vorgetäuschte 100-prozentige Anwesenheit diff --git a/app/src/main/res/values-es-rES/preferences_values.xml b/app/src/main/res/values-es-rES/preferences_values.xml index b2760e11..fc3cbf0b 100644 --- a/app/src/main/res/values-es-rES/preferences_values.xml +++ b/app/src/main/res/values-es-rES/preferences_values.xml @@ -68,7 +68,6 @@ Conferences - Bad grades Bad attendance Notes Fake attendance diff --git a/app/src/main/res/values-it-rIT/preferences_values.xml b/app/src/main/res/values-it-rIT/preferences_values.xml index b2760e11..fc3cbf0b 100644 --- a/app/src/main/res/values-it-rIT/preferences_values.xml +++ b/app/src/main/res/values-it-rIT/preferences_values.xml @@ -68,7 +68,6 @@ Conferences - Bad grades Bad attendance Notes Fake attendance diff --git a/app/src/main/res/values-pl/preferences_values.xml b/app/src/main/res/values-pl/preferences_values.xml index cf809f23..c7beb982 100644 --- a/app/src/main/res/values-pl/preferences_values.xml +++ b/app/src/main/res/values-pl/preferences_values.xml @@ -68,7 +68,6 @@ Zebrania - Słabe oceny Słaba frekwencja Uwagi Fałszywa frekwencja diff --git a/app/src/main/res/values-ru/preferences_values.xml b/app/src/main/res/values-ru/preferences_values.xml index c10cb4c1..3bb60dda 100644 --- a/app/src/main/res/values-ru/preferences_values.xml +++ b/app/src/main/res/values-ru/preferences_values.xml @@ -68,7 +68,6 @@ Встречи - Плохие оценки Плохая посещаемость Примечания Фейковая посещаемость diff --git a/app/src/main/res/values-sk/preferences_values.xml b/app/src/main/res/values-sk/preferences_values.xml index eeceb77f..cbfec0bf 100644 --- a/app/src/main/res/values-sk/preferences_values.xml +++ b/app/src/main/res/values-sk/preferences_values.xml @@ -68,7 +68,6 @@ Stretnutie - Zlé známky Zlá účasť Poznámky Falošná účasť diff --git a/app/src/main/res/values-uk/preferences_values.xml b/app/src/main/res/values-uk/preferences_values.xml index 2f3786fd..8f8e8170 100644 --- a/app/src/main/res/values-uk/preferences_values.xml +++ b/app/src/main/res/values-uk/preferences_values.xml @@ -68,7 +68,6 @@ Зустрічі - Погані оцінки Погана відвідуваність Примітки Фальшива явка diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml new file mode 100644 index 00000000..dae941a4 --- /dev/null +++ b/app/src/main/res/values/arrays.xml @@ -0,0 +1,28 @@ + + + + 1 + 1+ + 2- + 2 + 2+ + 3- + 3 + 3+ + 4- + 4 + 4+ + 5- + 5 + 5+ + 6 + 6- + + + 1 + 1+ + 2- + 2 + 2+ + + diff --git a/app/src/main/res/values/preferences_defaults.xml b/app/src/main/res/values/preferences_defaults.xml index 2678362d..a4961b8b 100644 --- a/app/src/main/res/values/preferences_defaults.xml +++ b/app/src/main/res/values/preferences_defaults.xml @@ -36,9 +36,7 @@ GRADES ANNOUNCEMENTS - - BAD_GRADES - + false false false diff --git a/app/src/main/res/values/preferences_values.xml b/app/src/main/res/values/preferences_values.xml index 54455670..0b9cbf90 100644 --- a/app/src/main/res/values/preferences_values.xml +++ b/app/src/main/res/values/preferences_values.xml @@ -158,13 +158,11 @@ - Bad grades Bad attendance Notes Fake attendance - BAD_GRADES BAD_ATTENDANCE NOTES ATTENDANCE