From f165ee32e5cf1d25b4071ef6d5d3776892777ef1 Mon Sep 17 00:00:00 2001 From: Kacper Ziubryniewicz Date: Tue, 24 Dec 2019 15:52:15 +0100 Subject: [PATCH] [API/Edudziennik] Fix getting teacher in timetable and fix getting team name. --- .../szczodrzynski/edziennik/data/api/Regexes.kt | 2 +- .../data/web/EdudziennikWebTimetable.kt | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt index ccfd2301..952ca176 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/Regexes.kt @@ -133,6 +133,6 @@ object Regexes { """Klasa (.*?)""".toRegex(DOT_MATCHES_ALL) + """(.*?)""".toRegex(DOT_MATCHES_ALL) } } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTimetable.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTimetable.kt index 8ac973f4..d0b8984d 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTimetable.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/edudziennik/data/web/EdudziennikWebTimetable.kt @@ -82,7 +82,7 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik, val course = lesson.select(".course").firstOrNull() ?: return@forEachIndexed val info = course.select("span > span") - if (info.size < 2) return@forEachIndexed + if (info.isEmpty()) return@forEachIndexed val type = when (course.hasClass("substitute")) { true -> Lesson.TYPE_CHANGE @@ -99,11 +99,13 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik, /* Getting teacher */ - val teacherElement = info[1].child(0) - val teacherName = teacherElement.text().trim() - val teacher = teacherName.splitName()?.let { (teacherLastName, teacherFirstName) -> - data.getTeacher(teacherFirstName, teacherLastName) - } ?: return@forEachIndexed + val teacherId = if (info.size >= 2) { + val teacherElement = info[1].child(0) + val teacherName = teacherElement.text().trim() + teacherName.splitName()?.let { (teacherLastName, teacherFirstName) -> + data.getTeacher(teacherFirstName, teacherLastName) + }?.id ?: -1 + } else -1 val lessonObject = Lesson(profileId, -1).also { it.type = type @@ -112,7 +114,7 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik, it.startTime = startTime it.endTime = endTime it.subjectId = subject.id - it.teacherId = teacher.id + it.teacherId = teacherId it.id = it.buildId() }