mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-04-03 15:24:27 +02:00
[API/Edudziennik] Add saving teachers login ids.
This commit is contained in:
parent
62d82c88a1
commit
868e529e62
@ -135,6 +135,9 @@ object Regexes {
|
|||||||
val EDUDZIENNIK_HOMEWORK_ID by lazy {
|
val EDUDZIENNIK_HOMEWORK_ID by lazy {
|
||||||
"""/Homework/([\w-_]+?)/""".toRegex()
|
"""/Homework/([\w-_]+?)/""".toRegex()
|
||||||
}
|
}
|
||||||
|
val EDUDZIENNIK_TEACHER_ID by lazy {
|
||||||
|
"""/Teachers/([\w-_]+?)/""".toRegex()
|
||||||
|
}
|
||||||
|
|
||||||
val EDUDZIENNIK_SCHOOL_DETAIL_ID by lazy {
|
val EDUDZIENNIK_SCHOOL_DETAIL_ID by lazy {
|
||||||
"""<a id="School_detail".*?/School/([\w-_]+?)/""".toRegex(DOT_MATCHES_ALL)
|
"""<a id="School_detail".*?/School/([\w-_]+?)/""".toRegex(DOT_MATCHES_ALL)
|
||||||
|
@ -116,11 +116,13 @@ class DataEdudziennik(app: App, profile: Profile?, loginStore: LoginStore) : Dat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTeacher(firstName: String, lastName: String): Teacher {
|
fun getTeacher(firstName: String, lastName: String, longId: String? = null): Teacher {
|
||||||
val name = "$firstName $lastName".fixName()
|
val name = "$firstName $lastName".fixName()
|
||||||
val id = name.crc32()
|
val id = name.crc32()
|
||||||
return teacherList.singleOrNull { it.id == id } ?: run {
|
return teacherList.singleOrNull { it.id == id }?.also {
|
||||||
val teacher = Teacher(profileId, id, firstName, lastName)
|
if (longId != null && it.loginId == null) it.loginId = longId
|
||||||
|
} ?: run {
|
||||||
|
val teacher = Teacher(profileId, id, firstName, lastName, longId)
|
||||||
teacherList.put(id, teacher)
|
teacherList.put(id, teacher)
|
||||||
teacher
|
teacher
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.web
|
|||||||
import org.jsoup.Jsoup
|
import org.jsoup.Jsoup
|
||||||
import pl.szczodrzynski.edziennik.data.api.ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC
|
import pl.szczodrzynski.edziennik.data.api.ERROR_EDUDZIENNIK_WEB_TIMETABLE_NOT_PUBLIC
|
||||||
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_SUBJECT_ID
|
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_SUBJECT_ID
|
||||||
|
import pl.szczodrzynski.edziennik.data.api.Regexes.EDUDZIENNIK_TEACHER_ID
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.DataEdudziennik
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.ENDPOINT_EDUDZIENNIK_WEB_TIMETABLE
|
||||||
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
import pl.szczodrzynski.edziennik.data.api.edziennik.edudziennik.data.EdudziennikWeb
|
||||||
@ -105,9 +106,10 @@ class EdudziennikWebTimetable(override val data: DataEdudziennik,
|
|||||||
|
|
||||||
val teacherId = if (info.size >= 2) {
|
val teacherId = if (info.size >= 2) {
|
||||||
val teacherElement = info[1].child(0)
|
val teacherElement = info[1].child(0)
|
||||||
|
val teacherLongId = EDUDZIENNIK_TEACHER_ID.find(teacherElement.attr("href"))?.get(1)
|
||||||
val teacherName = teacherElement.text().trim()
|
val teacherName = teacherElement.text().trim()
|
||||||
teacherName.splitName()?.let { (teacherLastName, teacherFirstName) ->
|
teacherName.splitName()?.let { (teacherLastName, teacherFirstName) ->
|
||||||
data.getTeacher(teacherFirstName, teacherLastName)
|
data.getTeacher(teacherFirstName, teacherLastName, teacherLongId)
|
||||||
}?.id ?: -1
|
}?.id ?: -1
|
||||||
} else -1
|
} else -1
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user