From 46d0459070487af213c6e9409e7cf757ced96eff Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Wed, 2 Oct 2019 12:52:39 +0200 Subject: [PATCH] [Settings] Add setting for showing teacher absences --- .gitignore | 1 + .../ui/modules/agenda/AgendaFragment.java | 63 ++++++++++--------- .../modules/settings/SettingsNewFragment.java | 19 ++++++ app/src/main/res/values-en/strings.xml | 1 + app/src/main/res/values/strings.xml | 1 + 5 files changed, 54 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index 047ad745..e006b2ce 100644 --- a/.gitignore +++ b/.gitignore @@ -42,6 +42,7 @@ captures/ .idea/assetWizardSettings.xml .idea/dictionaries .idea/libraries +.idea/copyright # Android Studio 3 in .gitignore file. .idea/caches .idea/modules.xml diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.java index 726a8637..37db5001 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/agenda/AgendaFragment.java @@ -181,43 +181,44 @@ public class AgendaFragment extends Fragment { )); } + if (app.profile.getStudentData("showTeacherAbsences", true)) { + List teacherAbsenceList = app.db.teacherAbsenceDao().getAllFull(App.profileId); + List teacherAbsenceCounters = new ArrayList<>(); - List teacherAbsenceList = app.db.teacherAbsenceDao().getAllFull(App.profileId); - List teacherAbsenceCounters = new ArrayList<>(); + for (TeacherAbsenceFull absence : teacherAbsenceList) { + for (Date date = absence.getDateFrom().clone(); date.compareTo(absence.getDateTo()) < 1; date.stepForward(0, 0, 1)) { + boolean counterFound = false; + for (TeacherAbsenceCounter counter : teacherAbsenceCounters) { + if (counter.getTeacherAbsenceDate().compareTo(date) == 0) { + counter.setTeacherAbsenceCount(counter.getTeacherAbsenceCount() + 1); + counterFound = true; + break; + } + } - for (TeacherAbsenceFull absence : teacherAbsenceList) { - for (Date date = absence.getDateFrom().clone(); date.compareTo(absence.getDateTo()) < 1; date.stepForward(0, 0, 1)) { - boolean counterFound = false; - for (TeacherAbsenceCounter counter : teacherAbsenceCounters) { - if (counter.getTeacherAbsenceDate().compareTo(date) == 0) { - counter.setTeacherAbsenceCount(counter.getTeacherAbsenceCount() + 1); - counterFound = true; - break; + if (!counterFound) { + teacherAbsenceCounters.add(new TeacherAbsenceCounter(date.clone(), 1)); } } - - if (!counterFound) { - teacherAbsenceCounters.add(new TeacherAbsenceCounter(date.clone(), 1)); - } } - } - for (TeacherAbsenceCounter counter : teacherAbsenceCounters) { - Calendar startTime = Calendar.getInstance(); - Calendar endTime = Calendar.getInstance(); - Date date = counter.getTeacherAbsenceDate(); - startTime.set(date.year, date.month - 1, date.day, 10, 0, 0); - endTime.setTimeInMillis(startTime.getTimeInMillis() + (1000 * 60 * 45)); - eventList.add(new TeacherAbsenceEvent( - date.getInMillis(), - 0xffff1744, - Colors.legibleTextColor(0xffff1744), - startTime, - endTime, - App.profileId, - date, - counter.getTeacherAbsenceCount() - )); + for (TeacherAbsenceCounter counter : teacherAbsenceCounters) { + Calendar startTime = Calendar.getInstance(); + Calendar endTime = Calendar.getInstance(); + Date date = counter.getTeacherAbsenceDate(); + startTime.set(date.year, date.month - 1, date.day, 10, 0, 0); + endTime.setTimeInMillis(startTime.getTimeInMillis() + (1000 * 60 * 45)); + eventList.add(new TeacherAbsenceEvent( + date.getInMillis(), + 0xffff1744, + Colors.legibleTextColor(0xffff1744), + startTime, + endTime, + App.profileId, + date, + counter.getTeacherAbsenceCount() + )); + } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java index 34726682..22bc2f17 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/settings/SettingsNewFragment.java @@ -45,6 +45,7 @@ import pl.szczodrzynski.edziennik.BuildConfig; import pl.szczodrzynski.edziennik.Notifier; import pl.szczodrzynski.edziennik.R; import pl.szczodrzynski.edziennik.MainActivity; +import pl.szczodrzynski.edziennik.data.db.modules.login.LoginStore; import pl.szczodrzynski.edziennik.ui.modules.webpush.WebPushConfigActivity; import pl.szczodrzynski.edziennik.ui.dialogs.changelog.ChangelogDialog; import pl.szczodrzynski.edziennik.utils.models.Endpoint; @@ -1057,6 +1058,24 @@ public class SettingsNewFragment extends MaterialAboutFragment { }) ); + if (app.profile.getLoginStoreType() == LoginStore.LOGIN_TYPE_LIBRUS) { + items.add( + new MaterialAboutSwitchItem( + getString(R.string.settings_register_show_teacher_absences_text), + null, + new IconicsDrawable(activity) + .icon(CommunityMaterial.Icon.cmd_account_arrow_right) + .size(IconicsSize.dp(iconSizeDp)) + .color(IconicsColor.colorInt(iconColor)) + ) + .setChecked(app.profile.getStudentData("showTeacherAbsences", true)) + .setOnChangeAction((isChecked, tag) -> { + app.profile.putStudentData("showTeacherAbsences", isChecked); + return true; + }) + ); + } + } return items; } diff --git a/app/src/main/res/values-en/strings.xml b/app/src/main/res/values-en/strings.xml index 863f9802..a3c61488 100644 --- a/app/src/main/res/values-en/strings.xml +++ b/app/src/main/res/values-en/strings.xml @@ -854,4 +854,5 @@ Absent teachers Getting grade comments Getting school free days + Show teacher absences diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b081c59e..290b84cc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -910,4 +910,5 @@ Brak zadań domowych. Nieobecni nauczyciele Pobieranie komentarzy ocen + Pokazuj nieobecności nauczycieli