mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 12:56:45 -06:00
[Vulcan/Hebe] Add getting teacher list and addressbook.
This commit is contained in:
parent
8fc57cd3f5
commit
f49e39e858
@ -129,6 +129,7 @@ const val VULCAN_HEBE_ENDPOINT_REGISTER_NEW = "api/mobile/register/new"
|
||||
const val VULCAN_HEBE_ENDPOINT_MAIN = "api/mobile/register/hebe"
|
||||
const val VULCAN_HEBE_ENDPOINT_TIMETABLE = "api/mobile/schedule"
|
||||
const val VULCAN_HEBE_ENDPOINT_TIMETABLE_CHANGES = "api/mobile/schedule/changes"
|
||||
const val VULCAN_HEBE_ENDPOINT_ADDRESSBOOK = "api/mobile/addressbook"
|
||||
const val VULCAN_HEBE_ENDPOINT_EXAMS = "api/mobile/exam"
|
||||
const val VULCAN_HEBE_ENDPOINT_GRADES = "api/mobile/grade"
|
||||
const val VULCAN_HEBE_ENDPOINT_HOMEWORK = "api/mobile/homework"
|
||||
|
@ -21,6 +21,7 @@ const val ENDPOINT_VULCAN_API_MESSAGES_INBOX = 1090
|
||||
const val ENDPOINT_VULCAN_API_MESSAGES_SENT = 1100
|
||||
const val ENDPOINT_VULCAN_WEB_LUCKY_NUMBERS = 2010
|
||||
const val ENDPOINT_VULCAN_HEBE_MAIN = 3000
|
||||
const val ENDPOINT_VULCAN_HEBE_ADDRESSBOOK = 3010
|
||||
const val ENDPOINT_VULCAN_HEBE_TIMETABLE = 3020
|
||||
const val ENDPOINT_VULCAN_HEBE_EXAMS = 3030
|
||||
const val ENDPOINT_VULCAN_HEBE_GRADES = 3040
|
||||
@ -89,7 +90,11 @@ val VulcanFeatures = listOf(
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ALWAYS_NEEDED, listOf(
|
||||
ENDPOINT_VULCAN_API_UPDATE_SEMESTER to LOGIN_METHOD_VULCAN_API,
|
||||
ENDPOINT_VULCAN_API_DICTIONARIES to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API))
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ALWAYS_NEEDED, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_MAIN to LOGIN_METHOD_VULCAN_HEBE,
|
||||
ENDPOINT_VULCAN_HEBE_ADDRESSBOOK to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE))
|
||||
/*Feature(LOGIN_TYPE_VULCAN, FEATURE_STUDENT_INFO, listOf(
|
||||
ENDPOINT_VULCAN_API to LOGIN_METHOD_VULCAN_WEB
|
||||
), listOf(LOGIN_METHOD_VULCAN_WEB)),
|
||||
|
@ -7,10 +7,7 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.api.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeExams
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeGrades
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeHomework
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.VulcanHebeTimetable
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe.*
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.web.VulcanWebLuckyNumber
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
|
||||
@ -95,6 +92,23 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_lucky_number)
|
||||
VulcanWebLuckyNumber(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_MAIN -> {
|
||||
if (data.profile == null) {
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_MAIN)
|
||||
return
|
||||
}
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_student_info)
|
||||
VulcanHebeMain(data, lastSync).getStudents(
|
||||
profile = data.profile,
|
||||
profileList = null
|
||||
) {
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_MAIN)
|
||||
}
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_ADDRESSBOOK -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_teachers)
|
||||
VulcanHebeAddressbook(data, lastSync, onSuccess)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_TIMETABLE -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_timetable)
|
||||
VulcanHebeTimetable(data, lastSync, onSuccess)
|
||||
|
@ -0,0 +1,118 @@
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import androidx.core.util.set
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_ADDRESSBOOK
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_ADDRESSBOOK
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher.Companion.TYPE_EDUCATOR
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher.Companion.TYPE_OTHER
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher.Companion.TYPE_PARENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher.Companion.TYPE_PARENTS_COUNCIL
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher.Companion.TYPE_STUDENT
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Teacher.Companion.TYPE_TEACHER
|
||||
import kotlin.text.replace
|
||||
|
||||
class VulcanHebeAddressbook(
|
||||
override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
companion object {
|
||||
const val TAG = "VulcanHebeAddressbook"
|
||||
}
|
||||
|
||||
private fun String.removeUnitName(unitName: String?): String {
|
||||
return (unitName ?: data.schoolShort)?.let {
|
||||
this.replace("($it)", "").trim()
|
||||
} ?: this
|
||||
}
|
||||
|
||||
init {
|
||||
apiGetList(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_ADDRESSBOOK,
|
||||
HebeFilterType.BY_PERSON,
|
||||
lastSync = lastSync,
|
||||
includeFilterType = false
|
||||
) { list, _ ->
|
||||
list.forEach { person ->
|
||||
val id = person.getString("Id") ?: return@forEach
|
||||
val loginId = person.getString("LoginId") ?: return@forEach
|
||||
|
||||
val idType = id.split("-")
|
||||
.getOrNull(0)
|
||||
val idLong = id.split("-")
|
||||
.getOrNull(1)
|
||||
?.toLongOrNull()
|
||||
?: return@forEach
|
||||
|
||||
val typeBase = when (idType) {
|
||||
"e" -> TYPE_TEACHER
|
||||
"c" -> TYPE_PARENT
|
||||
"p" -> TYPE_STUDENT
|
||||
else -> TYPE_OTHER
|
||||
}
|
||||
|
||||
val name = person.getString("Name") ?: ""
|
||||
val surname = person.getString("Surname") ?: ""
|
||||
val namePrefix = "$surname $name - "
|
||||
|
||||
val teacher = data.teacherList[idLong] ?: Teacher(
|
||||
data.profileId,
|
||||
idLong,
|
||||
name,
|
||||
surname,
|
||||
loginId
|
||||
).also {
|
||||
data.teacherList[idLong] = it
|
||||
}
|
||||
|
||||
person.getJsonArray("Roles")?.asJsonObjectList()?.onEach { role ->
|
||||
var roleText: String? = null
|
||||
val unitName = role.getString("ConstituentUnitSymbol")
|
||||
|
||||
val personType = when (role.getInt("RoleOrder")) {
|
||||
0 -> { /* Wychowawca */
|
||||
roleText = role.getString("ClassSymbol")
|
||||
?.removeUnitName(unitName)
|
||||
TYPE_EDUCATOR
|
||||
}
|
||||
1 -> TYPE_TEACHER /* Nauczyciel */
|
||||
2 -> return@onEach /* Pracownik */
|
||||
3 -> { /* Rada rodziców */
|
||||
roleText = role.getString("Address")
|
||||
?.removeUnitName(unitName)
|
||||
?.removePrefix(namePrefix)
|
||||
?.trim()
|
||||
TYPE_PARENTS_COUNCIL
|
||||
}
|
||||
5 -> {
|
||||
roleText = role.getString("RoleName")
|
||||
?.plus(" - ")
|
||||
?.plus(
|
||||
role.getString("Address")
|
||||
?.removeUnitName(unitName)
|
||||
?.removePrefix(namePrefix)
|
||||
?.trim()
|
||||
)
|
||||
TYPE_STUDENT
|
||||
}
|
||||
else -> TYPE_OTHER
|
||||
}
|
||||
|
||||
teacher.setTeacherType(personType)
|
||||
teacher.typeDescription = roleText
|
||||
}
|
||||
|
||||
if (teacher.type == 0)
|
||||
teacher.setTeacherType(typeBase)
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_VULCAN_HEBE_ADDRESSBOOK, 2 * DAY)
|
||||
onSuccess(ENDPOINT_VULCAN_HEBE_ADDRESSBOOK)
|
||||
}
|
||||
}
|
||||
}
|
@ -76,7 +76,7 @@ class VulcanHebeMain(
|
||||
}
|
||||
|
||||
val schoolSymbol = unit.getString("Symbol") ?: return@forEach
|
||||
val schoolShort = unit.getString("Short") ?: return@forEach
|
||||
val schoolShort = constituentUnit.getString("Short") ?: return@forEach
|
||||
val schoolCode = "${data.symbol}_$schoolSymbol"
|
||||
|
||||
val studentUnitId = unit.getInt("Id") ?: return@forEach
|
||||
|
Loading…
x
Reference in New Issue
Block a user