From fd034128e865adabd7470bf3e5ac9bd7df5193eb Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Sun, 29 Sep 2019 18:49:15 +0200 Subject: [PATCH] [Agenda] Add showing teachers absence time hours --- .../szczodrzynski/edziennik/data/api/Librus.java | 12 +++++++++++- .../szczodrzynski/edziennik/data/db/AppDb.java | 13 +++++++++++-- .../data/db/modules/teachers/TeacherAbsence.kt | 9 ++++++++- .../db/modules/teachers/TeacherAbsenceFull.kt | 6 ++++-- .../teacherabsence/TeacherAbsenceAdapter.kt | 16 +++++++++++++--- .../edziennik/utils/models/Time.java | 9 +++++++++ 6 files changed, 56 insertions(+), 9 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Librus.java b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Librus.java index f79f21d5..ff04e59e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Librus.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Librus.java @@ -3189,6 +3189,14 @@ public class Librus implements EdziennikInterface { Date dateFrom = Date.fromY_m_d(freeDay.get("DateFrom").getAsString()); Date dateTo = Date.fromY_m_d(freeDay.get("DateTo").getAsString()); + Time timeFrom = null; + Time timeTo = null; + + if (freeDay.get("TimeFrom") != null && freeDay.get("TimeTo") != null) { + timeFrom = Time.fromH_m_s(freeDay.get("TimeFrom").getAsString()); + timeTo = Time.fromH_m_s(freeDay.get("TimeTo").getAsString()); + } + long type = freeDay.getAsJsonObject("Type").get("Id").getAsLong(); //String topic = teacherFreeDaysTypes.get(type)+"\n"+(dateFrom.getValue() != dateTo.getValue() ? dateFrom.getFormattedString()+" - "+dateTo.getFormattedString() : ""); @@ -3199,7 +3207,9 @@ public class Librus implements EdziennikInterface { teacherId, type, dateFrom, - dateTo + dateTo, + timeFrom, + timeTo ); teacherAbsenceList.add(teacherAbsence); diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java index 207bd749..05ac2fb1 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/AppDb.java @@ -81,7 +81,7 @@ import android.content.Context; Message.class, MessageRecipient.class, DebugLog.class, - Metadata.class}, version = 53) + Metadata.class}, version = 54) @TypeConverters({ ConverterTime.class, ConverterDate.class, @@ -551,6 +551,13 @@ public abstract class AppDb extends RoomDatabase { ")"); } }; + private static final Migration MIGRATION_53_54 = new Migration(53, 54) { + @Override + public void migrate(@NonNull SupportSQLiteDatabase database) { + database.execSQL("ALTER TABLE teacherAbsence ADD teacherAbsenceTimeFrom TEXT DEFAULT NULL"); + database.execSQL("ALTER TABLE teacherAbsence ADD teacherAbsenceTimeTo TEXT DEFAULT NULL"); + } + }; public static AppDb getDatabase(final Context context) { @@ -601,7 +608,9 @@ public abstract class AppDb extends RoomDatabase { MIGRATION_49_50, MIGRATION_50_51, MIGRATION_51_52, - MIGRATION_52_53) + MIGRATION_52_53, + MIGRATION_53_54 + ) .allowMainThreadQueries() //.fallbackToDestructiveMigration() .build(); diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/teachers/TeacherAbsence.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/teachers/TeacherAbsence.kt index a8839fc9..76ed7450 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/teachers/TeacherAbsence.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/teachers/TeacherAbsence.kt @@ -3,6 +3,7 @@ package pl.szczodrzynski.edziennik.data.db.modules.teachers import androidx.room.ColumnInfo import androidx.room.Entity import pl.szczodrzynski.edziennik.utils.models.Date +import pl.szczodrzynski.edziennik.utils.models.Time @Entity(tableName = "teacherAbsence", primaryKeys = ["profileId", "teacherAbsenceId"]) @@ -22,6 +23,12 @@ open class TeacherAbsence ( val dateFrom: Date, @ColumnInfo(name = "teacherAbsenceDateTo") - val dateTo: Date + val dateTo: Date, + + @ColumnInfo(name = "teacherAbsenceTimeFrom") + val timeFrom: Time?, + + @ColumnInfo(name = "teacherAbsenceTimeTo") + val timeTo: Time? ) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/teachers/TeacherAbsenceFull.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/teachers/TeacherAbsenceFull.kt index b37f24f1..1c36c19c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/teachers/TeacherAbsenceFull.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/teachers/TeacherAbsenceFull.kt @@ -1,9 +1,11 @@ package pl.szczodrzynski.edziennik.data.db.modules.teachers import pl.szczodrzynski.edziennik.utils.models.Date +import pl.szczodrzynski.edziennik.utils.models.Time -class TeacherAbsenceFull(profileId: Int, id: Long, teacherId: Long, type: Long, dateFrom: Date, dateTo: Date) - : TeacherAbsence(profileId, id, teacherId, type, dateFrom, dateTo) { +class TeacherAbsenceFull(profileId: Int, id: Long, teacherId: Long, type: Long, + dateFrom: Date, dateTo: Date, timeFrom: Time?, timeTo: Time?) + : TeacherAbsence(profileId, id, teacherId, type, dateFrom, dateTo, timeFrom, timeTo) { var teacherFullName = "" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/teacherabsence/TeacherAbsenceAdapter.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/teacherabsence/TeacherAbsenceAdapter.kt index c64ea891..2d8eb2c6 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/teacherabsence/TeacherAbsenceAdapter.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/teacherabsence/TeacherAbsenceAdapter.kt @@ -31,9 +31,19 @@ class TeacherAbsenceAdapter( holder.teacherAbsenceTeacher.text = teacherAbsence.teacherFullName - val time = when(teacherAbsence.dateFrom.compareTo(teacherAbsence.dateTo)) { - 0 -> teacherAbsence.dateFrom.formattedStringShort - else -> teacherAbsence.dateFrom.formattedStringShort + " - " + teacherAbsence.dateTo.formattedStringShort + val time = when (teacherAbsence.timeFrom != null && teacherAbsence.timeTo != null) { + true -> when (teacherAbsence.dateFrom.compareTo(teacherAbsence.dateTo)) { + 0 -> teacherAbsence.dateFrom.formattedStringShort + " " + + teacherAbsence.timeFrom.stringHM + " - " + teacherAbsence.timeTo.stringHM + + else -> teacherAbsence.dateFrom.formattedStringShort + " " + teacherAbsence.timeTo.stringHM + + " - " + teacherAbsence.dateTo.formattedStringShort + " " + teacherAbsence.timeTo.stringHM + } + + false -> when (teacherAbsence.dateFrom.compareTo(teacherAbsence.dateTo)) { + 0 -> teacherAbsence.dateFrom.formattedStringShort + else -> teacherAbsence.dateFrom.formattedStringShort + " - " + teacherAbsence.dateTo.formattedStringShort + } } holder.teacherAbsenceTime.text = time diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/Time.java b/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/Time.java index 12277516..07b1c422 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/Time.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/utils/models/Time.java @@ -56,6 +56,9 @@ public class Time { return this; } + /** + * HHMMSS + */ public static Time fromHms(String time) { try { @@ -67,6 +70,9 @@ public class Time { } } + /** + * HH:MM + */ public static Time fromH_m(String time) { try { @@ -78,6 +84,9 @@ public class Time { } } + /** + * HH:MM:SS + */ public static Time fromH_m_s(String time) { try {