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 602884eb..2f2a0d10 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 @@ -210,4 +210,9 @@ class DataLibrus(app: App, profile: Profile?, loginStore: LoginStore) : Data(app get() { mSchoolName = mSchoolName ?: profile?.getStudentData("schoolName", null); return mSchoolName } set(value) { profile?.putStudentData("schoolName", value) ?: return; mSchoolName = value } + private var mUnitId: Long? = null + var unitId: Long + get() { mUnitId = mUnitId ?: profile?.getStudentData("unitId", 0L); return mUnitId ?: 0L } + set(value) { profile?.putStudentData("unitId", value) ?: return; mUnitId = value } + } diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiClasses.kt b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiClasses.kt index 3f58300d..d41206b4 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiClasses.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiClasses.kt @@ -4,11 +4,14 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api -import pl.szczodrzynski.edziennik.* +import pl.szczodrzynski.edziennik.DAY import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_CLASSES import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi import pl.szczodrzynski.edziennik.data.db.modules.teams.Team +import pl.szczodrzynski.edziennik.getJsonObject +import pl.szczodrzynski.edziennik.getLong +import pl.szczodrzynski.edziennik.getString import pl.szczodrzynski.edziennik.utils.models.Date class LibrusApiClasses(override val data: DataLibrus, @@ -37,7 +40,7 @@ class LibrusApiClasses(override val data: DataLibrus, data.teamList.put(id, teamObject) - val unitId = studentClass.getJsonObject("Unit").getLong("Id") + data.unitId = studentClass.getJsonObject("Unit").getLong("Id") ?: 0L profile?.apply { dateSemester1Start = Date.fromY_m_d(studentClass.getString("BeginSchoolYear") @@ -46,7 +49,6 @@ class LibrusApiClasses(override val data: DataLibrus, ?: return@apply) dateYearEnd = Date.fromY_m_d(studentClass.getString("EndSchoolYear") ?: return@apply) - unitId?.let { putStudentData("unitId", it) } } } 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 new file mode 100644 index 00000000..f595bf09 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiSubjects.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-10-23. + */ + +package pl.szczodrzynski.edziennik.api.v2.librus.data.api + +import pl.szczodrzynski.edziennik.DAY +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) { + companion object { + const val TAG = "LibrusApiSubjects" + } + + init { + apiGet(TAG, "Subjects") { json -> + json.getJsonArray("Subjects")?.forEach { subjectEl -> + val subject = subjectEl.asJsonObject + + val id = subject.getLong("Id") ?: return@forEach + val longName = subject.getString("Name") ?: "" + val shortName = subject.getString("Short") ?: "" + + data.subjectList.put(id, Subject(profileId, id, longName, shortName)) + } + + data.subjectList.put(1, Subject(profileId, 1, "Zachowanie", "zach")) + + data.setSyncNext(ENDPOINT_LIBRUS_API_SUBJECTS, 4*DAY) + onSuccess() + } + } +} 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 new file mode 100644 index 00000000..5818cd59 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiUsers.kt @@ -0,0 +1,35 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-10-23. + */ + +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_USERS +import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi +import pl.szczodrzynski.edziennik.data.db.modules.teachers.Teacher + +class LibrusApiUsers(override val data: DataLibrus, + val onSuccess: () -> Unit) : LibrusApi(data) { + companion object { + const val TAG = "LibrusApiUsers" + } + + init { + apiGet(TAG, "Users") { json -> + json.getJsonArray("Users")?.forEach { userEl -> + val user = userEl.asJsonObject + + val id = user.getLong("Id") ?: return@forEach + val firstName = user.getString("FirstName")?.fixWhiteSpaces() ?: "" + val lastName = user.getString("LastName")?.fixWhiteSpaces() ?: "" + + data.teacherList.put(id, Teacher(profileId, id, firstName, lastName)) + } + + data.setSyncNext(ENDPOINT_LIBRUS_API_USERS, 4*DAY) + onSuccess() + } + } +} 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 new file mode 100644 index 00000000..8d63f331 --- /dev/null +++ b/app/src/main/java/pl/szczodrzynski/edziennik/api/v2/librus/data/api/LibrusApiVirtualClasses.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) Kuba Szczodrzyński 2019-10-23. + */ + +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_VIRTUAL_CLASSES +import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi +import pl.szczodrzynski.edziennik.data.db.modules.teams.Team + +class LibrusApiVirtualClasses(override val data: DataLibrus, + val onSuccess: () -> Unit) : LibrusApi(data) { + companion object { + const val TAG = "LibrusApiVirtualClasses" + } + + init { + apiGet(TAG, "VirtualClasses") { json -> + json.getJsonArray("VirtualClasses")?.forEach { virtualClassEl -> + val virtualClass = virtualClassEl.asJsonObject + + val id = virtualClass.getLong("Id") ?: return@forEach + val name = virtualClass.getString("Name") ?: "" + val teacherId = virtualClass.getJsonObject("Teacher")?.getLong("Id") ?: -1 + val code = "${data.schoolName}:$name" + + data.teamList.put(id, Team(profileId, id, name, 2, code, teacherId)) + } + + data.setSyncNext(ENDPOINT_LIBRUS_API_VIRTUAL_CLASSES, 4*DAY) + onSuccess() + } + } +}