From 62b824f68f714aca72f6d8c14ec48bd3fcde1b11 Mon Sep 17 00:00:00 2001 From: xAxee <50153178+xAxee@users.noreply.github.com> Date: Sat, 2 Dec 2023 20:01:28 +0100 Subject: [PATCH 1/2] Adding new features to attendance --- app/build.gradle | 2 +- .../config/ProfileConfigAttendance.kt | 2 ++ .../attendance/AttendanceSummaryFragment.kt | 8 ++++- .../ui/attendance/models/AttendanceSubject.kt | 1 + .../viewholder/SubjectViewHolder.kt | 9 +++++ .../settings/AttendanceConfigDialog.kt | 18 ++++++++++ .../utils/managers/AttendanceManager.kt | 4 +++ .../res/layout/attendance_config_dialog.xml | 35 ++++++++++++++++++- app/src/main/res/values-en/strings.xml | 1 + app/src/main/res/values/strings.xml | 3 ++ 10 files changed, 80 insertions(+), 3 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0ceae1a14..b1ab39fcc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -104,7 +104,7 @@ android { externalNativeBuild { cmake { path "src/main/cpp/CMakeLists.txt" - version "3.10.2" + version "3.22.1" } } lint { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfigAttendance.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfigAttendance.kt index ba4f9deb9..7e01502b4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfigAttendance.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfigAttendance.kt @@ -11,4 +11,6 @@ class ProfileConfigAttendance(base: ProfileConfig) { var groupConsecutiveDays by base.config(true) var showPresenceInMonth by base.config(false) var useSymbols by base.config(false) + var showDifference by base.config(false) + var sortedDescending by base.config(false) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceSummaryFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceSummaryFragment.kt index 828e5a95e..8597ac507 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceSummaryFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceSummaryFragment.kt @@ -215,6 +215,8 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope { totalCountSum += totalCount presenceCountSum += presenceCount + subject.presenceDifference = presenceCount - (totalCount-presenceCount); + subject.percentage = if (totalCount == 0) 0f else @@ -286,7 +288,11 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope { } } - return items.toMutableList() + if(manager.sortedDescending){ + return items.sortedByDescending { it.percentage }.toMutableList(); + } else { + return items.toMutableList() + } } private fun animatePercentageIndicator(targetProgress: Double) { diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/models/AttendanceSubject.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/models/AttendanceSubject.kt index db5f34a14..f3a7c178a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/models/AttendanceSubject.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/models/AttendanceSubject.kt @@ -23,4 +23,5 @@ data class AttendanceSubject( var typeCountMap: Map = mapOf() var percentage: Float = 0f + var presenceDifference: Int = 0 } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/viewholder/SubjectViewHolder.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/viewholder/SubjectViewHolder.kt index a7e5e5628..4efb91f34 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/viewholder/SubjectViewHolder.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/viewholder/SubjectViewHolder.kt @@ -49,6 +49,15 @@ class SubjectViewHolder( } else { b.percentage.setText(R.string.attendance_percentage_format, item.percentage) + + if(manager.showDifference){ + val differenceText = if(item.presenceDifference > 0) + "+" + item.presenceDifference + else + item.presenceDifference + + b.percentage.setText(b.percentage.text.toString() + " | " + differenceText); + } } } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/AttendanceConfigDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/AttendanceConfigDialog.kt index b47341419..1f8bfcf13 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/AttendanceConfigDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/AttendanceConfigDialog.kt @@ -6,9 +6,11 @@ package pl.szczodrzynski.edziennik.ui.dialogs.settings import android.view.LayoutInflater import androidx.appcompat.app.AppCompatActivity +import com.google.android.material.dialog.MaterialAlertDialogBuilder import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.databinding.AttendanceConfigDialogBinding import pl.szczodrzynski.edziennik.ext.onChange +import pl.szczodrzynski.edziennik.ext.onClick import pl.szczodrzynski.edziennik.ui.dialogs.base.ConfigDialog class AttendanceConfigDialog( @@ -33,6 +35,8 @@ class AttendanceConfigDialog( b.useSymbols.isChecked = app.profile.config.attendance.useSymbols b.groupConsecutiveDays.isChecked = app.profile.config.attendance.groupConsecutiveDays b.showPresenceInMonth.isChecked = app.profile.config.attendance.showPresenceInMonth + b.showDifference.isChecked = app.profile.config.attendance.showDifference + b.sortedDescending.isChecked = app.profile.config.attendance.sortedDescending } override fun initView() { @@ -45,5 +49,19 @@ class AttendanceConfigDialog( b.showPresenceInMonth.onChange { _, isChecked -> app.profile.config.attendance.showPresenceInMonth = isChecked } + b.showDifference.onChange { _, isChecked -> + app.profile.config.attendance.showDifference = isChecked + } + b.sortedDescending.onChange { _, isChecked -> + app.profile.config.attendance.sortedDescending = isChecked + } + + b.showDifferenceHelp.onClick { + MaterialAlertDialogBuilder(activity) + .setTitle(R.string.attendance_config_show_difference) + .setMessage(R.string.attendance_config_show_difference_message) + .setPositiveButton(R.string.ok, null) + .show() + } } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/managers/AttendanceManager.kt b/app/src/main/java/pl/szczodrzynski/edziennik/utils/managers/AttendanceManager.kt index 5b112af93..12e2611dc 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/utils/managers/AttendanceManager.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/managers/AttendanceManager.kt @@ -25,6 +25,10 @@ class AttendanceManager(val app: App) : CoroutineScope { val useSymbols get() = app.profile.config.attendance.useSymbols + val showDifference + get() = app.profile.config.attendance.showDifference + val sortedDescending + get() = app.profile.config.attendance.sortedDescending fun getTypeShort(baseType: Int): String { return when (baseType) { diff --git a/app/src/main/res/layout/attendance_config_dialog.xml b/app/src/main/res/layout/attendance_config_dialog.xml index a75da4acc..5603b35e8 100644 --- a/app/src/main/res/layout/attendance_config_dialog.xml +++ b/app/src/main/res/layout/attendance_config_dialog.xml @@ -3,7 +3,9 @@ ~ Copyright (c) Kuba Szczodrzyński 2020-5-4. --> - + + + + + + + + + diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index ff2c1c3a7..4c9b97c46 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -1433,4 +1433,5 @@ Agenda settings Share notes All lessons: + Display attendance differences diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e4204e210..4794791b2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -63,6 +63,9 @@ su Grupuj kolejne dni na liście Wyświetlaj obecność w widoku miesięcy + Wyświetlaj różnice obecności + Wyświetla różnice między obecnościami a nieobecnościami (Ile lekcji potrzebujesz lub możesz nie mieć aby mieć nadal 50%) \n\nnp. -1 oznacza, że brakuje ci jednej lekcji do 50% + Sortuj od największej obecności Konfiguracja frekwencji Używaj symboli i kolorów wg dziennika Widoczne po rozwinięciu listy From 4728f0a00a9a6b32be7c836b959e98c1ed87e94c Mon Sep 17 00:00:00 2001 From: xAxee <50153178+xAxee@users.noreply.github.com> Date: Wed, 6 Dec 2023 00:15:31 +0100 Subject: [PATCH 2/2] Add sort types to attendance --- .../config/ProfileConfigAttendance.kt | 4 +- .../edziennik/data/db/dao/AttendanceDao.kt | 1 - .../attendance/AttendanceSummaryFragment.kt | 11 ++- .../settings/AttendanceConfigDialog.kt | 19 ++++- .../utils/managers/AttendanceManager.kt | 10 ++- .../res/layout/attendance_config_dialog.xml | 78 +++++++++++++------ app/src/main/res/values-en/strings.xml | 6 +- app/src/main/res/values/strings.xml | 5 +- 8 files changed, 94 insertions(+), 40 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfigAttendance.kt b/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfigAttendance.kt index 7e01502b4..4f2c1a5c7 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfigAttendance.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/config/ProfileConfigAttendance.kt @@ -4,6 +4,8 @@ package pl.szczodrzynski.edziennik.config +import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_ALPHABET + @Suppress("RemoveExplicitTypeArguments") class ProfileConfigAttendance(base: ProfileConfig) { @@ -12,5 +14,5 @@ class ProfileConfigAttendance(base: ProfileConfig) { var showPresenceInMonth by base.config(false) var useSymbols by base.config(false) var showDifference by base.config(false) - var sortedDescending by base.config(false) + var orderBy by base.config(SORTED_BY_ALPHABET) } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AttendanceDao.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AttendanceDao.kt index a420c5b5a..fe99c96ba 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AttendanceDao.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/dao/AttendanceDao.kt @@ -56,7 +56,6 @@ abstract class AttendanceDao : BaseDao { // GET ALL - LIVE DATA fun getAll(profileId: Int) = getRaw("$QUERY WHERE attendances.profileId = $profileId $ORDER_BY") - // GET ALL - NOW fun getAllNow(profileId: Int) = getRawNow("$QUERY WHERE attendances.profileId = $profileId $ORDER_BY") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceSummaryFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceSummaryFragment.kt index 8597ac507..cec36d75d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceSummaryFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/attendance/AttendanceSummaryFragment.kt @@ -32,6 +32,9 @@ import pl.szczodrzynski.edziennik.ui.attendance.AttendanceFragment.Companion.VIE import pl.szczodrzynski.edziennik.ui.attendance.models.AttendanceSubject import pl.szczodrzynski.edziennik.ui.base.lazypager.LazyFragment import pl.szczodrzynski.edziennik.ui.grades.models.GradesSubject +import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_ALPHABET +import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_HIGHEST +import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_LOWEST import pl.szczodrzynski.edziennik.utils.models.Date import java.text.DecimalFormat import kotlin.coroutines.CoroutineContext @@ -288,10 +291,10 @@ class AttendanceSummaryFragment : LazyFragment(), CoroutineScope { } } - if(manager.sortedDescending){ - return items.sortedByDescending { it.percentage }.toMutableList(); - } else { - return items.toMutableList() + return when(manager.orderBy){ + SORTED_BY_HIGHEST -> items.sortedByDescending { it.percentage }.toMutableList() + SORTED_BY_LOWEST -> items.sortedBy { it.percentage }.toMutableList() + else -> items.sortedBy { it.subjectName.lowercase() }.toMutableList() } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/AttendanceConfigDialog.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/AttendanceConfigDialog.kt index 1f8bfcf13..8c140105a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/AttendanceConfigDialog.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/settings/AttendanceConfigDialog.kt @@ -11,7 +11,11 @@ import pl.szczodrzynski.edziennik.R import pl.szczodrzynski.edziennik.databinding.AttendanceConfigDialogBinding import pl.szczodrzynski.edziennik.ext.onChange import pl.szczodrzynski.edziennik.ext.onClick +import pl.szczodrzynski.edziennik.ext.setOnSelectedListener import pl.szczodrzynski.edziennik.ui.dialogs.base.ConfigDialog +import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_ALPHABET +import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_HIGHEST +import pl.szczodrzynski.edziennik.utils.managers.AttendanceManager.Companion.SORTED_BY_LOWEST class AttendanceConfigDialog( activity: AppCompatActivity, @@ -36,7 +40,13 @@ class AttendanceConfigDialog( b.groupConsecutiveDays.isChecked = app.profile.config.attendance.groupConsecutiveDays b.showPresenceInMonth.isChecked = app.profile.config.attendance.showPresenceInMonth b.showDifference.isChecked = app.profile.config.attendance.showDifference - b.sortedDescending.isChecked = app.profile.config.attendance.sortedDescending + + when (app.profile.config.attendance.orderBy) { + SORTED_BY_ALPHABET -> b.sortAttendanceByAlphabet + SORTED_BY_LOWEST -> b.sortAttendanceByLowest + SORTED_BY_HIGHEST -> b.sortAttendanceByHighest + else -> null + }?.isChecked = true } override fun initView() { @@ -52,9 +62,10 @@ class AttendanceConfigDialog( b.showDifference.onChange { _, isChecked -> app.profile.config.attendance.showDifference = isChecked } - b.sortedDescending.onChange { _, isChecked -> - app.profile.config.attendance.sortedDescending = isChecked - } + + b.sortAttendanceByAlphabet.setOnSelectedListener { app.profile.config.attendance.orderBy = SORTED_BY_ALPHABET } + b.sortAttendanceByHighest.setOnSelectedListener { app.profile.config.attendance.orderBy = SORTED_BY_HIGHEST } + b.sortAttendanceByLowest.setOnSelectedListener { app.profile.config.attendance.orderBy = SORTED_BY_LOWEST } b.showDifferenceHelp.onClick { MaterialAlertDialogBuilder(activity) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/managers/AttendanceManager.kt b/app/src/main/java/pl/szczodrzynski/edziennik/utils/managers/AttendanceManager.kt index 12e2611dc..fb02f9b1a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/utils/managers/AttendanceManager.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/managers/AttendanceManager.kt @@ -19,16 +19,20 @@ import kotlin.coroutines.CoroutineContext class AttendanceManager(val app: App) : CoroutineScope { + companion object { + const val SORTED_BY_ALPHABET = 0 + const val SORTED_BY_HIGHEST = 1 + const val SORTED_BY_LOWEST = 2 + } private val job = Job() override val coroutineContext: CoroutineContext get() = job + Dispatchers.Default - val useSymbols get() = app.profile.config.attendance.useSymbols val showDifference get() = app.profile.config.attendance.showDifference - val sortedDescending - get() = app.profile.config.attendance.sortedDescending + val orderBy + get() = app.profile.config.attendance.orderBy fun getTypeShort(baseType: Int): String { return when (baseType) { diff --git a/app/src/main/res/layout/attendance_config_dialog.xml b/app/src/main/res/layout/attendance_config_dialog.xml index 5603b35e8..398e10cee 100644 --- a/app/src/main/res/layout/attendance_config_dialog.xml +++ b/app/src/main/res/layout/attendance_config_dialog.xml @@ -32,6 +32,32 @@ android:minHeight="32dp" android:text="@string/attendance_config_use_symbols" /> + + + + + + + + - - + + android:layout_height="wrap_content"> - + android:minHeight="0dp" + android:text="@string/attendance_config_dialog_sort_by_alphabet" /> - + - + + + diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 4c9b97c46..6f2d2cd3b 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -1433,5 +1433,9 @@ Agenda settings Share notes All lessons: - Display attendance differences + Display attendance differences + Sort attendance + Alphabetically + From the highest + from the lowest diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4794791b2..16f9a52a0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -65,10 +65,12 @@ Wyświetlaj obecność w widoku miesięcy Wyświetlaj różnice obecności Wyświetla różnice między obecnościami a nieobecnościami (Ile lekcji potrzebujesz lub możesz nie mieć aby mieć nadal 50%) \n\nnp. -1 oznacza, że brakuje ci jednej lekcji do 50% - Sortuj od największej obecności Konfiguracja frekwencji Używaj symboli i kolorów wg dziennika Widoczne po rozwinięciu listy + Alfabetycznie + Od najniższej + Od najwyższej Nie ma tutaj żadnych nieobecności. w lekcja %d @@ -680,6 +682,7 @@ Tablica ogłoszeń Frekwencja Ustawienia frekwencji + Sortuj frekwencje Debugowanie Pomoc i opinie Zapisz plan lekcji jako obraz