From 35ed31f6b9f653220e4f57f2bf4308cc1cb5e856 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Szczodrzy=C5=84ski?= Date: Thu, 24 Oct 2019 22:15:35 +0200 Subject: [PATCH] [APIv2/Librus] Add Attendance types, Classrooms, Event types, Notices, Notice types, PT meetings. Simplify JSON array iteration. --- .../pl/szczodrzynski/edziennik/Extensions.kt | 4 +- .../edziennik/api/v2/librus/DataLibrus.kt | 37 ++++++++++ .../edziennik/api/v2/librus/LibrusFeatures.kt | 7 +- .../api/v2/librus/data/LibrusData.kt | 56 +++++++++++++-- .../librus/data/api/LibrusApiAnnouncements.kt | 6 +- .../data/api/LibrusApiAttendanceTypes.kt | 29 +++++--- .../librus/data/api/LibrusApiAttendances.kt | 29 ++++---- .../v2/librus/data/api/LibrusApiClassrooms.kt | 44 ++++++++++++ .../v2/librus/data/api/LibrusApiEventTypes.kt | 35 +++++++++ .../api/v2/librus/data/api/LibrusApiEvents.kt | 13 ++-- .../api/v2/librus/data/api/LibrusApiGrades.kt | 9 +-- .../v2/librus/data/api/LibrusApiHomework.kt | 11 +-- .../librus/data/api/LibrusApiNoticeTypes.kt | 34 +++++++++ .../v2/librus/data/api/LibrusApiNotices.kt | 71 +++++++++++++++++++ .../v2/librus/data/api/LibrusApiPtMeetings.kt | 68 ++++++++++++++++++ .../v2/librus/data/api/LibrusApiSubjects.kt | 9 +-- .../data/api/LibrusApiTeacherFreeDayTypes.kt | 12 +--- .../data/api/LibrusApiTeacherFreeDays.kt | 11 +-- .../api/v2/librus/data/api/LibrusApiUnits.kt | 6 +- .../api/v2/librus/data/api/LibrusApiUsers.kt | 4 +- .../data/api/LibrusApiVirtualClasses.kt | 4 +- .../edziennik/api/v2/models/Data.kt | 35 ++++++--- .../data/db/modules/events/EventType.java | 4 +- .../ui/dialogs/event/EventManualDialog.java | 10 +-- .../ui/modules/login/LoginSyncFragment.kt | 22 +++--- app/src/main/res/values/strings.xml | 8 +++ 26 files changed, 464 insertions(+), 114 deletions(-) create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiClassrooms.kt create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiEventTypes.kt create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiNoticeTypes.kt create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiNotices.kt create mode 100644 app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiPtMeetings.kt diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt index 2ab17634..5edf5fc4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/Extensions.kt @@ -14,8 +14,8 @@ import com.google.gson.JsonArray import com.google.gson.JsonElement import com.google.gson.JsonObject import im.wangchao.mhttp.Response -import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile +import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher import pl.szczodrzynski.edziennik.data.db.modules.teams.Team import pl.szczodrzynski.navlib.R import pl.szczodrzynski.navlib.crc16 @@ -48,6 +48,8 @@ fun JsonObject?.getFloat(key: String, defaultValue: Float): Float = get(key)?.le fun JsonObject?.getJsonObject(key: String, defaultValue: JsonObject): JsonObject = get(key)?.let { if (it.isJsonNull) defaultValue else it.asJsonObject } ?: defaultValue fun JsonObject?.getJsonArray(key: String, defaultValue: JsonArray): JsonArray = get(key)?.let { if (it.isJsonNull) defaultValue else it.asJsonArray } ?: defaultValue +fun JsonArray?.asJsonObjectList() = this?.map { it.asJsonObject } + fun CharSequence?.isNotNullNorEmpty(): Boolean { return this != null && this.isNotEmpty() } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/DataLibrus.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/DataLibrus.kt index 600453b1..a18b4511 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/DataLibrus.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/DataLibrus.kt @@ -51,6 +51,43 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app } } + fun getColor(id: Int?): Int { + return when (id) { + 1 -> 0xFFF0E68C + 2 -> 0xFF87CEFA + 3 -> 0xFFB0C4DE + 4 -> 0xFFF0F8FF + 5 -> 0xFFF0FFFF + 6 -> 0xFFF5F5DC + 7 -> 0xFFFFEBCD + 8 -> 0xFFFFF8DC + 9 -> 0xFFA9A9A9 + 10 -> 0xFFBDB76B + 11 -> 0xFF8FBC8F + 12 -> 0xFFDCDCDC + 13 -> 0xFFDAA520 + 14 -> 0xFFE6E6FA + 15 -> 0xFFFFA07A + 16 -> 0xFF32CD32 + 17 -> 0xFF66CDAA + 18 -> 0xFF66CDAA + 19 -> 0xFFC0C0C0 + 20 -> 0xFFD2B48C + 21 -> 0xFF3333FF + 22 -> 0xFF7B68EE + 23 -> 0xFFBA55D3 + 24 -> 0xFFFFB6C1 + 25 -> 0xFFFF1493 + 26 -> 0xFFDC143C + 27 -> 0xFFFF0000 + 28 -> 0xFFFF8C00 + 29 -> 0xFFFFD700 + 30 -> 0xFFADFF2F + 31 -> 0xFF7CFC00 + else -> 0xff2196f3 + }.toInt() + } + /* _____ _ _ | __ \ | | | | | |__) |__ _ __| |_ __ _| | diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/LibrusFeatures.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/LibrusFeatures.kt index 7e0b26d3..79c7d2df 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/LibrusFeatures.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/LibrusFeatures.kt @@ -30,11 +30,12 @@ const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_GRADES = 1033 const val ENDPOINT_LIBRUS_API_TEXT_GRADES = 1034 const val ENDPOINT_LIBRUS_API_DESCRIPTIVE_TEXT_GRADES = 1035 const val ENDPOINT_LIBRUS_API_BEHAVIOUR_GRADES = 1036 -const val ENDPOINT_LIBRUS_API_EVENTS = 1040 -const val ENDPOINT_LIBRUS_API_EVENT_TYPES = 1041 +const val ENDPOINT_LIBRUS_API_EVENT_TYPES = 1040 +const val ENDPOINT_LIBRUS_API_EVENTS = 1041 const val ENDPOINT_LIBRUS_API_HOMEWORK = 1050 const val ENDPOINT_LIBRUS_API_LUCKY_NUMBER = 1060 -const val ENDPOINT_LIBRUS_API_NOTICES = 1070 +const val ENDPOINT_LIBRUS_API_NOTICE_TYPES = 1070 +const val ENDPOINT_LIBRUS_API_NOTICES = 1071 const val ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES = 1080 const val ENDPOINT_LIBRUS_API_ATTENDANCES = 1081 const val ENDPOINT_LIBRUS_API_ANNOUNCEMENTS = 1090 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt index 0302dc2a..73ea0387 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/LibrusData.kt @@ -45,10 +45,43 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) { data.startProgress(R.string.edziennik_progress_endpoint_school_info) LibrusApiSchools(data) { onSuccess() } } + ENDPOINT_LIBRUS_API_CLASSES -> { + data.startProgress(R.string.edziennik_progress_endpoint_classes) + LibrusApiClasses(data) { onSuccess() } + } + ENDPOINT_LIBRUS_API_VIRTUAL_CLASSES -> { + data.startProgress(R.string.edziennik_progress_endpoint_teams) + LibrusApiVirtualClasses(data) { onSuccess() } + } + ENDPOINT_LIBRUS_API_UNITS -> { + data.startProgress(R.string.edziennik_progress_endpoint_units) + LibrusApiUnits(data) { onSuccess() } + } + ENDPOINT_LIBRUS_API_USERS -> { + data.startProgress(R.string.edziennik_progress_endpoint_teachers) + LibrusApiUsers(data) { onSuccess() } + } + ENDPOINT_LIBRUS_API_SUBJECTS -> { + data.startProgress(R.string.edziennik_progress_endpoint_subjects) + LibrusApiSubjects(data) { onSuccess() } + } + ENDPOINT_LIBRUS_API_CLASSROOMS -> { + data.startProgress(R.string.edziennik_progress_endpoint_classrooms) + LibrusApiClassrooms(data) { onSuccess() } + } + // TODO push config + // TODO timetable + ENDPOINT_LIBRUS_API_NORMAL_GRADES -> { data.startProgress(R.string.edziennik_progress_endpoint_grades) LibrusApiGrades(data) { onSuccess() } } + // TODO grades + + ENDPOINT_LIBRUS_API_EVENT_TYPES -> { + data.startProgress(R.string.edziennik_progress_endpoint_event_types) + LibrusApiEventTypes(data) { onSuccess() } + } ENDPOINT_LIBRUS_API_EVENTS -> { data.startProgress(R.string.edziennik_progress_endpoint_events) LibrusApiEvents(data) { onSuccess() } @@ -57,6 +90,18 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) { data.startProgress(R.string.edziennik_progress_endpoint_homework) LibrusApiHomework(data) { onSuccess() } } + ENDPOINT_LIBRUS_API_LUCKY_NUMBER -> { + data.startProgress(R.string.edziennik_progress_endpoint_lucky_number) + LibrusApiLuckyNumber(data) { onSuccess() } + } + ENDPOINT_LIBRUS_API_NOTICE_TYPES -> { + data.startProgress(R.string.edziennik_progress_endpoint_notice_types) + LibrusApiNoticeTypes(data) { onSuccess() } + } + ENDPOINT_LIBRUS_API_NOTICES -> { + data.startProgress(R.string.edziennik_progress_endpoint_notices) + LibrusApiNotices(data) { onSuccess() } + } ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES -> { data.startProgress(R.string.edziennik_progress_endpoint_attendance_types) LibrusApiAttendanceTypes(data) { onSuccess() } @@ -69,13 +114,9 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) { data.startProgress(R.string.edziennik_progress_endpoint_announcements) LibrusApiAnnouncements(data) { onSuccess() } } - ENDPOINT_LIBRUS_API_LUCKY_NUMBER -> { - data.startProgress(R.string.edziennik_progress_endpoint_lucky_number) - LibrusApiLuckyNumber(data) { onSuccess() } - } - ENDPOINT_LIBRUS_API_CLASSES -> { - data.startProgress(R.string.edziennik_progress_endpoint_classes) - LibrusApiClasses(data) { onSuccess() } + ENDPOINT_LIBRUS_API_PT_MEETINGS -> { + data.startProgress(R.string.edziennik_progress_endpoint_pt_meetings) + LibrusApiPtMeetings(data) { onSuccess() } } ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES -> { data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_day_types) @@ -85,6 +126,7 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) { data.startProgress(R.string.edziennik_progress_endpoint_teacher_free_days) LibrusApiTeacherFreeDays(data) { onSuccess() } } + ENDPOINT_LIBRUS_SYNERGIA_HOMEWORK -> { data.startProgress(R.string.edziennik_progress_endpoint_homework) LibrusSynergiaHomework(data) { onSuccess() } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAnnouncements.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAnnouncements.kt index 4e93e290..e05f1ef0 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAnnouncements.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAnnouncements.kt @@ -22,11 +22,9 @@ class LibrusApiAnnouncements(override val data: DataLibrus, init { apiGet(TAG, "SchoolNotices") { json -> - val announcements = json.getJsonArray("SchoolNotices") - - announcements?.forEach { announcementEl -> - val announcement = announcementEl.asJsonObject + val announcements = json.getJsonArray("SchoolNotices").asJsonObjectList() + announcements?.forEach { announcement -> val id = Utils.crc16(announcement.getString("Id")?.toByteArray() ?: return@forEach).toLong() val subject = announcement.getString("Subject") ?: "" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAttendanceTypes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAttendanceTypes.kt index aa268a80..1ee34f9f 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAttendanceTypes.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAttendanceTypes.kt @@ -4,11 +4,13 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api +import android.graphics.Color import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi -import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS +import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance +import pl.szczodrzynski.edziennik.data.db.modules.attendance.AttendanceType class LibrusApiAttendanceTypes(override val data: DataLibrus, val onSuccess: () -> Unit) : LibrusApi(data) { @@ -18,24 +20,29 @@ class LibrusApiAttendanceTypes(override val data: DataLibrus, init { apiGet(TAG, "Attendances/Types") { json -> - val attendanceTypes = json.getJsonArray("Types") + val attendanceTypes = json.getJsonArray("Types").asJsonObjectList() - attendanceTypes?.forEach { attendanceTypeEl -> - val attendanceType = attendanceTypeEl.asJsonObject + attendanceTypes?.forEach { attendanceType -> + val id = attendanceType.getLong("Id") ?: return@forEach + val name = attendanceType.getString("Name") ?: "" + val color = attendanceType.getString("ColorRGB")?.let { Color.parseColor("#$it") } ?: -1 - val id = attendanceType.getInt("Id") ?: return@forEach val standardId = when (attendanceType.getBoolean("Standard") ?: false) { true -> id - false -> attendanceType.getJsonObject("StandardType")?.getInt("Id") - ?: return@forEach + false -> attendanceType.getJsonObject("StandardType")?.getLong("Id") ?: id + } + val type = when (standardId) { + 1L -> Attendance.TYPE_ABSENT + 2L -> Attendance.TYPE_BELATED + 3L -> Attendance.TYPE_ABSENT_EXCUSED + 4L -> Attendance.TYPE_RELEASED + /*100*/else -> Attendance.TYPE_PRESENT } - val name = attendanceType.getString("Name") ?: "" - - data.attendanceTypes.put(id, Pair(standardId, name)) + data.attendanceTypes.put(id, AttendanceType(profileId, id, name, type, color)) } - data.setSyncNext(ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES, SYNC_ALWAYS) + data.setSyncNext(ENDPOINT_LIBRUS_API_ATTENDANCE_TYPES, 4*DAY) onSuccess() } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAttendances.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAttendances.kt index 8bd7f243..52a3ea26 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAttendances.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiAttendances.kt @@ -4,6 +4,7 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api +import androidx.core.util.isEmpty import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_ATTENDANCES @@ -21,12 +22,14 @@ class LibrusApiAttendances(override val data: DataLibrus, } init { + if (data.attendanceTypes.isEmpty()) { + data.db.attendanceTypeDao().getAllNow(profileId).toSparseArray(data.attendanceTypes) { it.id } + } + apiGet(TAG, "Attendances") { json -> - val attendances = json.getJsonArray("Attendances") - - attendances?.forEach { attendanceEl -> - val attendance = attendanceEl.asJsonObject + val attendances = json.getJsonArray("Attendances").asJsonObjectList() + attendances?.forEach { attendance -> val id = Utils.strToInt((attendance.getString("Id") ?: return@forEach) .replace("[^\\d.]".toRegex(), "")).toLong() val teacherId = attendance.getJsonObject("AddedBy")?.getLong("Id") ?: -1 @@ -37,17 +40,9 @@ class LibrusApiAttendances(override val data: DataLibrus, it.weekDay == lessonDate.weekDay && it.startTime.value == startTime.value }?.subjectId ?: -1 val semester = attendance.getInt("Semester") ?: return@forEach - var type = attendance.getJsonObject("Type")?.getInt("Id") ?: return@forEach - val attendanceType = data.attendanceTypes.get(type) - val topic = attendanceType.second - - type = when(type) { - 1 -> Attendance.TYPE_ABSENT - 2 -> Attendance.TYPE_BELATED - 3 -> Attendance.TYPE_ABSENT_EXCUSED - 4 -> Attendance.TYPE_RELEASED - else -> Attendance.TYPE_PRESENT - } + val type = attendance.getJsonObject("Type")?.getLong("Id") ?: return@forEach + val typeObject = data.attendanceTypes.get(type) + val topic = typeObject?.name ?: "" val attendanceObject = Attendance( profileId, @@ -58,13 +53,13 @@ class LibrusApiAttendances(override val data: DataLibrus, topic, lessonDate, startTime, - type + typeObject.type ) val addedDate = Date.fromIso(attendance.getString("AddDate") ?: return@forEach) data.attendanceList.add(attendanceObject) - if(type != Attendance.TYPE_PRESENT) { + if(typeObject.type != Attendance.TYPE_PRESENT) { data.metadataList.add(Metadata( profileId, Metadata.TYPE_ATTENDANCE, diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiClassrooms.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiClassrooms.kt new file mode 100644 index 00000000..662225e0 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiClassrooms.kt @@ -0,0 +1,44 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-10-24. + */ + +package pl.szczodrzynski.edziennik.api.v2.librus.data.api + +import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus +import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_CLASSROOMS +import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi +import pl.szczodrzynski.edziennik.data.db.modules.classrooms.Classroom +import java.util.* + +class LibrusApiClassrooms(override val data: DataLibrus, + val onSuccess: () -> Unit) : LibrusApi(data) { + companion object { + const val TAG = "LibrusApiClassrooms" + } + + init { + apiGet(TAG, "Classrooms") { json -> + val classrooms = json.getJsonArray("Classrooms").asJsonObjectList() + + classrooms?.forEach { classroom -> + val id = classroom.getLong("Id") ?: return@forEach + val name = classroom.getString("Name")?.toLowerCase(Locale.getDefault()) ?: "" + val symbol = classroom.getString("Symbol")?.toLowerCase(Locale.getDefault()) ?: "" + val nameShort = name.split(" ").onEach { it[0] }.joinToString() + + val friendlyName = if (name != symbol && !name.contains(symbol) && !nameShort.contains(symbol)) { + classroom.getString("Symbol") + " " + classroom.getString("Name") + } + else { + classroom.getString("Name") ?: "" + } + + data.classrooms.put(id, Classroom(profileId, id, friendlyName)) + } + + data.setSyncNext(ENDPOINT_LIBRUS_API_CLASSROOMS, 4*DAY) + onSuccess() + } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiEventTypes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiEventTypes.kt new file mode 100644 index 00000000..42fad5d2 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiEventTypes.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-10-24. + */ + +package pl.szczodrzynski.edziennik.api.v2.librus.data.api + +import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus +import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_EVENT_TYPES +import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi +import pl.szczodrzynski.edziennik.data.db.modules.events.EventType + +class LibrusApiEventTypes(override val data: DataLibrus, + val onSuccess: () -> Unit) : LibrusApi(data) { + companion object { + const val TAG = "LibrusApiEventTypes" + } + + init { + apiGet(TAG, "HomeWorks/Categories") { json -> + val eventTypes = json.getJsonArray("Categories").asJsonObjectList() + + eventTypes?.forEach { eventType -> + val id = eventType.getLong("Id") ?: return@forEach + val name = eventType.getString("Name") ?: "" + val color = data.getColor(eventType.getJsonObject("Color")?.getInt("Id")) + + data.eventTypes.put(id, EventType(profileId, id, name, color)) + } + + data.setSyncNext(ENDPOINT_LIBRUS_API_EVENT_TYPES, 4*DAY) + onSuccess() + } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiEvents.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiEvents.kt index ed6ece5c..512a8caa 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiEvents.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiEvents.kt @@ -4,9 +4,10 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api +import androidx.core.util.isEmpty import pl.szczodrzynski.edziennik.* -import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_EVENTS import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus +import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_EVENTS import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS import pl.szczodrzynski.edziennik.data.db.modules.events.Event @@ -21,12 +22,14 @@ class LibrusApiEvents(override val data: DataLibrus, } init { + if (data.eventTypes.isEmpty()) { + data.db.eventTypeDao().getAllNow(profileId).toSparseArray(data.eventTypes) { it.id } + } + apiGet(TAG, "HomeWorks") { json -> - val events = json.getJsonArray("HomeWorks") - - events?.forEach { eventEl -> - val event = eventEl.asJsonObject + val events = json.getJsonArray("HomeWorks").asJsonObjectList() + events?.forEach { event -> val id = event.getLong("Id") ?: return@forEach val eventDate = Date.fromY_m_d(event.getString("Date")) val topic = event.getString("Content") ?: "" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGrades.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGrades.kt index 8f4699c9..930938d0 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGrades.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiGrades.kt @@ -1,8 +1,8 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api import pl.szczodrzynski.edziennik.* -import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GRADES import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus +import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GRADES import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade @@ -10,7 +10,6 @@ import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata import pl.szczodrzynski.edziennik.utils.Utils import pl.szczodrzynski.edziennik.utils.models.Date - class LibrusApiGrades(override val data: DataLibrus, val onSuccess: () -> Unit) : LibrusApi(data) { companion object { @@ -19,11 +18,9 @@ class LibrusApiGrades(override val data: DataLibrus, init { apiGet(TAG, "Grades") { json -> - val grades = json.getJsonArray("Grades") - - grades?.forEach { gradeEl -> - val grade = gradeEl.asJsonObject + val grades = json.getJsonArray("Grades").asJsonObjectList() + grades?.forEach { grade -> val id = grade.getLong("Id") ?: return@forEach val categoryId = grade.getJsonObject("Category")?.getLong("Id") ?: -1 val name = grade.getString("Grade") ?: "" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiHomework.kt index c3f67c8d..ba16ebe9 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiHomework.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiHomework.kt @@ -4,16 +4,13 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api +import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_HOMEWORK import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS import pl.szczodrzynski.edziennik.data.db.modules.events.Event import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata -import pl.szczodrzynski.edziennik.getJsonArray -import pl.szczodrzynski.edziennik.getJsonObject -import pl.szczodrzynski.edziennik.getLong -import pl.szczodrzynski.edziennik.getString import pl.szczodrzynski.edziennik.utils.models.Date class LibrusApiHomework(override val data: DataLibrus, @@ -24,11 +21,9 @@ class LibrusApiHomework(override val data: DataLibrus, init { apiGet(TAG, "HomeWorkAssignments") { json -> - val homeworkList = json.getJsonArray("HomeWorkAssignments") - - homeworkList?.forEach { homeworkEl -> - val homework = homeworkEl.asJsonObject + val homeworkList = json.getJsonArray("HomeWorkAssignments").asJsonObjectList() + homeworkList?.forEach { homework -> val id = homework.getLong("Id") ?: return@forEach val eventDate = Date.fromY_m_d(homework.getString("DueDate")) val topic = homework.getString("Topic") + "\n" + homework.getString("Text") diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiNoticeTypes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiNoticeTypes.kt new file mode 100644 index 00000000..f49b15c7 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiNoticeTypes.kt @@ -0,0 +1,34 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-10-24. + */ + +package pl.szczodrzynski.edziennik.api.v2.librus.data.api + +import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus +import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NOTICE_TYPES +import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi +import pl.szczodrzynski.edziennik.data.db.modules.notices.NoticeType + +class LibrusApiNoticeTypes(override val data: DataLibrus, + val onSuccess: () -> Unit) : LibrusApi(data) { + companion object { + const val TAG = "LibrusApiNoticeTypes" + } + + init { + apiGet(TAG, "Notes/Categories") { json -> + val noticeTypes = json.getJsonArray("Categories").asJsonObjectList() + + noticeTypes?.forEach { noticeType -> + val id = noticeType.getLong("Id") ?: return@forEach + val name = noticeType.getString("CategoryName") ?: "" + + data.noticeTypes.put(id, NoticeType(profileId, id, name)) + } + + data.setSyncNext(ENDPOINT_LIBRUS_API_NOTICE_TYPES, 4*DAY) + onSuccess() + } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiNotices.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiNotices.kt new file mode 100644 index 00000000..2f4ca5c9 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiNotices.kt @@ -0,0 +1,71 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-10-24. + */ + +package pl.szczodrzynski.edziennik.api.v2.librus.data.api + +import androidx.core.util.isEmpty +import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus +import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NOTICES +import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi +import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS +import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata +import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice +import pl.szczodrzynski.edziennik.utils.models.Date + +class LibrusApiNotices(override val data: DataLibrus, + val onSuccess: () -> Unit) : LibrusApi(data) { + companion object { + const val TAG = "LibrusApiNotices" + } + + init { + if (data.noticeTypes.isEmpty()) { + data.db.noticeTypeDao().getAllNow(profileId).toSparseArray(data.noticeTypes) { it.id } + } + + apiGet(TAG, "Notes") { json -> + val notes = json.getJsonArray("Notes").asJsonObjectList() + + notes?.forEach { note -> + val id = note.getLong("Id") ?: return@forEach + val text = note.getString("Text") ?: "" + val categoryId = note.getJsonObject("Category")?.getLong("Id") ?: -1 + val teacherId = note.getJsonObject("AddedBy")?.getLong("Id") ?: -1 + val addedDate = note.getString("Date")?.let { Date.fromY_m_d(it) } ?: return@forEach + + val type = when (note.getInt("Positive")) { + 0 -> Notice.TYPE_NEGATIVE + 1 -> Notice.TYPE_POSITIVE + /*2*/else -> Notice.TYPE_NEUTRAL + } + val categoryText = data.noticeTypes[categoryId]?.name ?: "" + val semester = profile?.dateToSemester(addedDate) ?: 1 + + val noticeObject = Notice( + profileId, + id, + categoryText+"\n"+text, + semester, + type, + teacherId + ) + + data.noticeList.add(noticeObject) + data.metadataList.add( + Metadata( + profileId, + Metadata.TYPE_NOTICE, + id, + profile?.empty ?: false, + profile?.empty ?: false, + addedDate.inMillis + )) + } + + data.setSyncNext(ENDPOINT_LIBRUS_API_NOTICES, SYNC_ALWAYS) + onSuccess() + } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiPtMeetings.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiPtMeetings.kt new file mode 100644 index 00000000..2c4e5f53 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiPtMeetings.kt @@ -0,0 +1,68 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-10-24. + */ + +package pl.szczodrzynski.edziennik.api.v2.librus.data.api + +import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus +import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_PT_MEETINGS +import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi +import pl.szczodrzynski.edziennik.data.db.modules.events.Event +import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata +import pl.szczodrzynski.edziennik.utils.models.Date +import pl.szczodrzynski.edziennik.utils.models.Time + +class LibrusApiPtMeetings(override val data: DataLibrus, + val onSuccess: () -> Unit) : LibrusApi(data) { + companion object { + const val TAG = "LibrusApiPtMeetings" + } + + init { + apiGet(TAG, "ParentTeacherConferences") { json -> + val ptMeetings = json.getJsonArray("ParentTeacherConferences").asJsonObjectList() + + ptMeetings?.forEach { meeting -> + val id = meeting.getLong("Id") ?: return@forEach + val topic = meeting.getString("Topic") ?: "" + val teacherId = meeting.getJsonObject("Teacher")?.getLong("Id") ?: -1 + val eventDate = meeting.getString("Date")?.let { Date.fromY_m_d(it) } ?: return@forEach + val startTime = meeting.getString("Time")?.let { + if (it == "00:00:00") + null + else + Time.fromH_m_s(it) + } + + val eventObject = Event( + profileId, + id, + eventDate, + startTime, + topic, + -1, + Event.TYPE_PT_MEETING, + false, + teacherId, + -1, + data.teamClass?.id ?: -1 + ) + + data.eventList.add(eventObject) + data.metadataList.add( + Metadata( + profileId, + Metadata.TYPE_EVENT, + id, + profile?.empty ?: false, + profile?.empty ?: false, + System.currentTimeMillis() + )) + } + + data.setSyncNext(ENDPOINT_LIBRUS_API_PT_MEETINGS, 12*HOUR) + onSuccess() + } + } +} diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiSubjects.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiSubjects.kt index f595bf09..2cfd9be2 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiSubjects.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiSubjects.kt @@ -4,14 +4,11 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api -import pl.szczodrzynski.edziennik.DAY +import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_SUBJECTS import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject -import pl.szczodrzynski.edziennik.getJsonArray -import pl.szczodrzynski.edziennik.getLong -import pl.szczodrzynski.edziennik.getString class LibrusApiSubjects(override val data: DataLibrus, val onSuccess: () -> Unit) : LibrusApi(data) { @@ -21,9 +18,9 @@ class LibrusApiSubjects(override val data: DataLibrus, init { apiGet(TAG, "Subjects") { json -> - json.getJsonArray("Subjects")?.forEach { subjectEl -> - val subject = subjectEl.asJsonObject + val subjects = json.getJsonArray("Subjects").asJsonObjectList() + subjects?.forEach { subject -> val id = subject.getLong("Id") ?: return@forEach val longName = subject.getString("Name") ?: "" val shortName = subject.getString("Short") ?: "" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTeacherFreeDayTypes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTeacherFreeDayTypes.kt index dcfdcbeb..49692e25 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTeacherFreeDayTypes.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTeacherFreeDayTypes.kt @@ -4,15 +4,11 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api -import pl.szczodrzynski.edziennik.DAY +import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_TEACHER_FREE_DAY_TYPES import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi -import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsenceType -import pl.szczodrzynski.edziennik.getJsonArray -import pl.szczodrzynski.edziennik.getLong -import pl.szczodrzynski.edziennik.getString class LibrusApiTeacherFreeDayTypes(override val data: DataLibrus, val onSuccess: () -> Unit) : LibrusApi(data) { @@ -22,11 +18,9 @@ class LibrusApiTeacherFreeDayTypes(override val data: DataLibrus, init { apiGet(TAG, "TeacherFreeDays/Types") { json -> - val teacherAbsenceTypes = json.getJsonArray("Types") - - teacherAbsenceTypes?.forEach { teacherAbsenceTypeEl -> - val teacherAbsenceType = teacherAbsenceTypeEl.asJsonObject + val teacherAbsenceTypes = json.getJsonArray("Types").asJsonObjectList() + teacherAbsenceTypes?.forEach { teacherAbsenceType -> val id = teacherAbsenceType.getLong("Id") ?: return@forEach val name = teacherAbsenceType.getString("Name") ?: return@forEach diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTeacherFreeDays.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTeacherFreeDays.kt index 3be6fabb..649e3377 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTeacherFreeDays.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiTeacherFreeDays.kt @@ -4,6 +4,7 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api +import androidx.core.util.isEmpty import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.MainActivity.Companion.DRAWER_ITEM_AGENDA import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus @@ -21,12 +22,14 @@ class LibrusApiTeacherFreeDays(override val data: DataLibrus, } init { + if (data.teacherAbsenceTypes.isEmpty()) { + data.db.teacherAbsenceTypeDao().getAllNow(profileId).toSparseArray(data.teacherAbsenceTypes) { it.id } + } + apiGet(TAG, "TeacherFreeDays") { json -> - val teacherAbsences = json.getJsonArray("TeacherFreeDays") - - teacherAbsences?.forEach { teacherAbsenceEl -> - val teacherAbsence = teacherAbsenceEl.asJsonObject + val teacherAbsences = json.getJsonArray("TeacherFreeDays").asJsonObjectList() + teacherAbsences?.forEach { teacherAbsence -> val id = teacherAbsence.getLong("Id") ?: return@forEach val teacherId = teacherAbsence.getJsonObject("Teacher")?.getLong("Id") ?: return@forEach diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiUnits.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiUnits.kt index 78d10103..42353ad5 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiUnits.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiUnits.kt @@ -23,9 +23,9 @@ class LibrusApiUnits(override val data: DataLibrus, } apiGet(TAG, "Units") { json -> - val units = json.getJsonArray("Units") - units?.singleOrNull { it.asJsonObject.getLong("Id") == data.unitId }?.also { unitEl -> - val unit = unitEl.asJsonObject + val units = json.getJsonArray("Units").asJsonObjectList() + + units?.singleOrNull { it.getLong("Id") == data.unitId }?.also { unit -> val startPoints = unit.getJsonObject("BehaviourGradesSettings")?.getJsonObject("StartPoints") startPoints?.apply { data.startPointsSemester1 = getInt("Semester1", defaultValue = 0) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiUsers.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiUsers.kt index 5818cd59..1277ec06 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiUsers.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiUsers.kt @@ -18,9 +18,9 @@ class LibrusApiUsers(override val data: DataLibrus, init { apiGet(TAG, "Users") { json -> - json.getJsonArray("Users")?.forEach { userEl -> - val user = userEl.asJsonObject + val users = json.getJsonArray("Users").asJsonObjectList() + users?.forEach { user -> val id = user.getLong("Id") ?: return@forEach val firstName = user.getString("FirstName")?.fixWhiteSpaces() ?: "" val lastName = user.getString("LastName")?.fixWhiteSpaces() ?: "" diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiVirtualClasses.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiVirtualClasses.kt index 8d63f331..3cc1559e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiVirtualClasses.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiVirtualClasses.kt @@ -18,9 +18,9 @@ class LibrusApiVirtualClasses(override val data: DataLibrus, init { apiGet(TAG, "VirtualClasses") { json -> - json.getJsonArray("VirtualClasses")?.forEach { virtualClassEl -> - val virtualClass = virtualClassEl.asJsonObject + val virtualClasses = json.getJsonArray("VirtualClasses").asJsonObjectList() + virtualClasses?.forEach { virtualClass -> val id = virtualClass.getLong("Id") ?: return@forEach val name = virtualClass.getString("Name") ?: "" val teacherId = virtualClass.getJsonObject("Teacher")?.getLong("Id") ?: -1 diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt index 5baa62bb..54dfdae3 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/models/Data.kt @@ -2,6 +2,7 @@ package pl.szczodrzynski.edziennik.api.v2.models import android.util.LongSparseArray import android.util.SparseArray +import androidx.core.util.size import com.google.gson.JsonObject import im.wangchao.mhttp.Response import pl.szczodrzynski.edziennik.App @@ -14,6 +15,8 @@ import pl.szczodrzynski.edziennik.data.db.AppDb import pl.szczodrzynski.edziennik.data.db.modules.announcements.Announcement import pl.szczodrzynski.edziennik.data.db.modules.api.EndpointTimer import pl.szczodrzynski.edziennik.data.db.modules.attendance.Attendance +import pl.szczodrzynski.edziennik.data.db.modules.attendance.AttendanceType +import pl.szczodrzynski.edziennik.data.db.modules.classrooms.Classroom import pl.szczodrzynski.edziennik.data.db.modules.events.Event import pl.szczodrzynski.edziennik.data.db.modules.events.EventType import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade @@ -27,6 +30,7 @@ import pl.szczodrzynski.edziennik.data.db.modules.messages.Message import pl.szczodrzynski.edziennik.data.db.modules.messages.MessageRecipient import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata import pl.szczodrzynski.edziennik.data.db.modules.notices.Notice +import pl.szczodrzynski.edziennik.data.db.modules.notices.NoticeType import pl.szczodrzynski.edziennik.data.db.modules.notification.Notification import pl.szczodrzynski.edziennik.data.db.modules.profiles.Profile import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject @@ -102,7 +106,11 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) val teamList = LongSparseArray() val lessonRanges = SparseArray() val gradeCategories = LongSparseArray() - val attendanceTypes = SparseArray>() + + val classrooms = LongSparseArray() + val attendanceTypes = LongSparseArray() + val noticeTypes = LongSparseArray() + val eventTypes = LongSparseArray() val teacherAbsenceTypes = LongSparseArray() private var mTeamClass: Team? = null @@ -125,7 +133,6 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) var eventsToRemove: DataRemoveModel? = null val eventList = mutableListOf() - val eventTypeList = mutableListOf() var noticesToRemove: DataRemoveModel? = null val noticeList = mutableListOf() @@ -158,7 +165,6 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) db.teamDao().getAllNow(profileId).toSparseArray(teamList) { it.id } db.lessonRangeDao().getAllNow(profileId).toSparseArray(lessonRanges) { it.lessonNumber } db.gradeCategoryDao().getAllNow(profileId).toSparseArray(gradeCategories) { it.categoryId } - db.teacherAbsenceTypeDao().getAllNow(profileId).toSparseArray(teacherAbsenceTypes) { it.id } } } @@ -170,12 +176,18 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) subjectList.clear() teamList.clear() lessonRanges.clear() + gradeCategories.clear() + + classrooms.clear() + attendanceTypes.clear() + noticeTypes.clear() + eventTypes.clear() + teacherAbsenceTypes.clear() lessonList.clear() lessonChangeList.clear() gradeCategories.clear() gradeList.clear() - eventTypeList.clear() noticeList.clear() attendanceList.clear() announcementList.clear() @@ -239,8 +251,17 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) db.lessonRangeDao().addAll(lessonRanges.values()) db.gradeCategoryDao().clear(profileId) db.gradeCategoryDao().addAll(gradeCategories.values()) - db.teacherAbsenceTypeDao().clear(profileId) - db.teacherAbsenceTypeDao().addAll(teacherAbsenceTypes.values()) + + if (classrooms.size > 0) + db.classroomDao().addAll(classrooms.values()) + if (attendanceTypes.size > 0) + db.attendanceTypeDao().addAll(attendanceTypes.values()) + if (noticeTypes.size > 0) + db.noticeTypeDao().addAll(noticeTypes.values()) + if (eventTypes.size > 0) + db.eventTypeDao().addAll(eventTypes.values()) + if (teacherAbsenceTypes.size > 0) + db.teacherAbsenceTypeDao().addAll(teacherAbsenceTypes.values()) gradesToRemove?.let { it -> it.removeAll?.let { _ -> db.gradeDao().clear(profileId) } @@ -260,8 +281,6 @@ open class Data(val app: App, val profile: Profile?, val loginStore: LoginStore) db.eventDao().removeFuture(profile.id, Date.getToday()) db.eventDao().addAll(eventList) } - if (eventTypeList.isNotEmpty()) - db.eventTypeDao().addAll(eventTypeList) if (noticeList.isNotEmpty()) { db.noticeDao().clear(profile.id) db.noticeDao().addAll(noticeList) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/events/EventType.java b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/events/EventType.java index e06f7656..30c4794a 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/events/EventType.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/modules/events/EventType.java @@ -11,14 +11,14 @@ public class EventType { public int profileId; @ColumnInfo(name = "eventType") - public int id; + public long id; @ColumnInfo(name = "eventTypeName") public String name; @ColumnInfo(name = "eventTypeColor") public int color; - public EventType(int profileId, int id, String name, int color) { + public EventType(int profileId, long id, String name, int color) { this.profileId = profileId; this.id = id; this.name = name; diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.java b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.java index af333143..8bc27048 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.java +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/dialogs/event/EventManualDialog.java @@ -34,8 +34,8 @@ import com.wdullaer.materialdatetimepicker.time.TimePickerDialog; import java.util.List; import pl.szczodrzynski.edziennik.App; -import pl.szczodrzynski.edziennik.R; import pl.szczodrzynski.edziennik.MainActivity; +import pl.szczodrzynski.edziennik.R; import pl.szczodrzynski.edziennik.data.api.AppError; import pl.szczodrzynski.edziennik.data.db.modules.events.Event; import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull; @@ -46,12 +46,12 @@ import pl.szczodrzynski.edziennik.data.db.modules.profiles.ProfileFull; import pl.szczodrzynski.edziennik.data.db.modules.subjects.Subject; import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher; import pl.szczodrzynski.edziennik.data.db.modules.teams.Team; -import pl.szczodrzynski.edziennik.utils.models.Date; -import pl.szczodrzynski.edziennik.utils.models.Time; -import pl.szczodrzynski.edziennik.utils.models.Week; import pl.szczodrzynski.edziennik.network.ServerRequest; import pl.szczodrzynski.edziennik.utils.TextInputDropDown; import pl.szczodrzynski.edziennik.utils.Themes; +import pl.szczodrzynski.edziennik.utils.models.Date; +import pl.szczodrzynski.edziennik.utils.models.Time; +import pl.szczodrzynski.edziennik.utils.models.Week; import static pl.szczodrzynski.edziennik.App.APP_URL; import static pl.szczodrzynski.edziennik.data.api.AppError.CODE_OTHER; @@ -727,7 +727,7 @@ public class EventManualDialog { popup.setOnMenuItemClickListener(item -> { if (item.getGroupId() == 0 && eventTypes != null) { EventType typeObj = eventTypes.get(item.getItemId()); - eventType = typeObj.id; + eventType = (int)typeObj.id; eventColor = -1; // set -1 as it's the event type's default color registerEventManualColorPreview.setBackgroundColor(typeObj.color); // set event type's color here to show how will it look } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginSyncFragment.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginSyncFragment.kt index 006c8e75..1a0086fe 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginSyncFragment.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/login/LoginSyncFragment.kt @@ -127,17 +127,17 @@ class LoginSyncFragment : Fragment() { profile.loginStoreId = loginStoreId loginStore.id = loginStoreId val typeList = listOf( - EventType(profileId, TYPE_HOMEWORK, getString(R.string.event_type_homework), COLOR_HOMEWORK), - EventType(profileId, TYPE_DEFAULT, getString(R.string.event_other), COLOR_DEFAULT), - EventType(profileId, TYPE_EXAM, getString(R.string.event_exam), COLOR_EXAM), - EventType(profileId, TYPE_SHORT_QUIZ, getString(R.string.event_short_quiz), COLOR_SHORT_QUIZ), - EventType(profileId, TYPE_ESSAY, getString(R.string.event_essay), COLOR_SHORT_QUIZ), - EventType(profileId, TYPE_PROJECT, getString(R.string.event_project), COLOR_PROJECT), - EventType(profileId, TYPE_PT_MEETING, getString(R.string.event_pt_meeting), COLOR_PT_MEETING), - EventType(profileId, TYPE_EXCURSION, getString(R.string.event_excursion), COLOR_EXCURSION), - EventType(profileId, TYPE_READING, getString(R.string.event_reading), COLOR_READING), - EventType(profileId, TYPE_CLASS_EVENT, getString(R.string.event_class_event), COLOR_CLASS_EVENT), - EventType(profileId, TYPE_INFORMATION, getString(R.string.event_information), COLOR_INFORMATION) + EventType(profileId, TYPE_HOMEWORK.toLong(), getString(R.string.event_type_homework), COLOR_HOMEWORK), + EventType(profileId, TYPE_DEFAULT.toLong(), getString(R.string.event_other), COLOR_DEFAULT), + EventType(profileId, TYPE_EXAM.toLong(), getString(R.string.event_exam), COLOR_EXAM), + EventType(profileId, TYPE_SHORT_QUIZ.toLong(), getString(R.string.event_short_quiz), COLOR_SHORT_QUIZ), + EventType(profileId, TYPE_ESSAY.toLong(), getString(R.string.event_essay), COLOR_SHORT_QUIZ), + EventType(profileId, TYPE_PROJECT.toLong(), getString(R.string.event_project), COLOR_PROJECT), + EventType(profileId, TYPE_PT_MEETING.toLong(), getString(R.string.event_pt_meeting), COLOR_PT_MEETING), + EventType(profileId, TYPE_EXCURSION.toLong(), getString(R.string.event_excursion), COLOR_EXCURSION), + EventType(profileId, TYPE_READING.toLong(), getString(R.string.event_reading), COLOR_READING), + EventType(profileId, TYPE_CLASS_EVENT.toLong(), getString(R.string.event_class_event), COLOR_CLASS_EVENT), + EventType(profileId, TYPE_INFORMATION.toLong(), getString(R.string.event_information), COLOR_INFORMATION) ) app.db.eventTypeDao().addAll(typeList) app.profileSaveFull(profile, loginStore) diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3deb4994..a390c853 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -955,4 +955,12 @@ Synchronizuję... [%d%%] %s Pobieranie uwag... + Pobieranie grup klasowych... + Pobieranie informacji o jednostce... + Pobieranie listy nauczycieli... + Pobieranie listy przedmiotów... + Pobieranie listy sal lekcyjnych... + Pobieranie kategorii wydarzeń... + Pobieranie kategorii uwag... + Pobieranie zebrań z rodzicami...