forked from github/szkolny
[Vulcan/Hebe] Add getting attendance.
This commit is contained in:
parent
e86b47fb1b
commit
621a7ac642
@ -133,6 +133,7 @@ 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"
|
||||
const val VULCAN_HEBE_ENDPOINT_ATTENDANCE = "api/mobile/lesson"
|
||||
const val VULCAN_HEBE_ENDPOINT_MESSAGES = "api/mobile/message"
|
||||
|
||||
const val EDUDZIENNIK_USER_AGENT = "Szkolny.eu/${BuildConfig.VERSION_NAME}"
|
||||
|
@ -26,6 +26,7 @@ const val ENDPOINT_VULCAN_HEBE_TIMETABLE = 3020
|
||||
const val ENDPOINT_VULCAN_HEBE_EXAMS = 3030
|
||||
const val ENDPOINT_VULCAN_HEBE_GRADES = 3040
|
||||
const val ENDPOINT_VULCAN_HEBE_HOMEWORK = 3060
|
||||
const val ENDPOINT_VULCAN_HEBE_ATTENDANCE = 3080
|
||||
const val ENDPOINT_VULCAN_HEBE_MESSAGES_INBOX = 3090
|
||||
const val ENDPOINT_VULCAN_HEBE_MESSAGES_SENT = 3100
|
||||
|
||||
@ -67,6 +68,9 @@ val VulcanFeatures = listOf(
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ATTENDANCE, listOf(
|
||||
ENDPOINT_VULCAN_API_ATTENDANCE to LOGIN_METHOD_VULCAN_API
|
||||
), listOf(LOGIN_METHOD_VULCAN_API)),
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_ATTENDANCE, listOf(
|
||||
ENDPOINT_VULCAN_HEBE_ATTENDANCE to LOGIN_METHOD_VULCAN_HEBE
|
||||
), listOf(LOGIN_METHOD_VULCAN_HEBE)),
|
||||
// messages
|
||||
Feature(LOGIN_TYPE_VULCAN, FEATURE_MESSAGES_INBOX, listOf(
|
||||
ENDPOINT_VULCAN_API_MESSAGES_INBOX to LOGIN_METHOD_VULCAN_API
|
||||
|
@ -134,6 +134,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_messages_outbox)
|
||||
VulcanHebeMessages(data, lastSync, onSuccess).getMessages(Message.TYPE_SENT)
|
||||
}
|
||||
ENDPOINT_VULCAN_HEBE_ATTENDANCE -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_attendance)
|
||||
VulcanHebeAttendance(data, lastSync, onSuccess)
|
||||
}
|
||||
else -> onSuccess(endpointId)
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright (c) Kacper Ziubryniewicz 2021-2-21
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe
|
||||
|
||||
import com.google.gson.JsonObject
|
||||
import pl.szczodrzynski.edziennik.*
|
||||
import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_ATTENDANCE
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan
|
||||
import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Attendance
|
||||
import pl.szczodrzynski.edziennik.data.db.entity.Metadata
|
||||
|
||||
class VulcanHebeAttendance(
|
||||
override val data: DataVulcan,
|
||||
override val lastSync: Long?,
|
||||
val onSuccess: (endpointId: Int) -> Unit
|
||||
) : VulcanHebe(data, lastSync) {
|
||||
|
||||
companion object {
|
||||
const val TAG = "VulcanHebeAttendance"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGetList(
|
||||
TAG,
|
||||
VULCAN_HEBE_ENDPOINT_ATTENDANCE,
|
||||
HebeFilterType.BY_PUPIL,
|
||||
lastSync = lastSync
|
||||
) { list, _ ->
|
||||
list.forEach { attendance ->
|
||||
val id = attendance.getLong("AuxPresenceId") ?: return@forEach
|
||||
val type = attendance.getJsonObject("PresenceType") ?: return@forEach
|
||||
val baseType = getBaseType(type)
|
||||
val typeName = type.getString("Name") ?: return@forEach
|
||||
val typeCategoryId = type.getLong("CategoryId") ?: return@forEach
|
||||
val typeSymbol = type.getString("Symbol") ?: return@forEach
|
||||
val typeShort = when (typeCategoryId.toInt()) {
|
||||
6, 8 -> typeSymbol
|
||||
else -> data.app.attendanceManager.getTypeShort(baseType)
|
||||
}
|
||||
val typeColor = when (typeCategoryId.toInt()) {
|
||||
1 -> 0xffffffff // obecność
|
||||
2 -> 0xffffa687 // nieobecność
|
||||
3 -> 0xfffcc150 // nieobecność usprawiedliwiona
|
||||
4 -> 0xffede049 // spóźnienie
|
||||
5 -> 0xffbbdd5f // spóźnienie usprawiedliwione
|
||||
6 -> 0xffa9c9fd // nieobecny z przyczyn szkolnych
|
||||
7 -> 0xffddbbe5 // zwolniony
|
||||
8 -> 0xffffffff // usunięty wpis
|
||||
else -> null
|
||||
}?.toInt()
|
||||
val date = getDate(attendance, "Day") ?: return@forEach
|
||||
val lessonRange = getLessonRange(attendance, "TimeSlot")
|
||||
val startTime = lessonRange?.startTime
|
||||
val semester = profile?.dateToSemester(date) ?: return@forEach
|
||||
val teacherId = attendance.getJsonObject("TeacherPrimary")?.getLong("Id") ?: -1
|
||||
val subjectId = attendance.getJsonObject("Subject")?.getLong("Id") ?: -1
|
||||
val addedDate = getDateTime(attendance, "DateModify")
|
||||
val lessonNumber = lessonRange?.lessonNumber
|
||||
val isCounted = attendance.getBoolean("CalculatePresence")
|
||||
?: (baseType != Attendance.TYPE_RELEASED)
|
||||
|
||||
val attendanceObject = Attendance(
|
||||
profileId = profileId,
|
||||
id = id,
|
||||
baseType = baseType,
|
||||
typeName = typeName,
|
||||
typeShort = typeShort,
|
||||
typeSymbol = typeSymbol,
|
||||
typeColor = typeColor,
|
||||
date = date,
|
||||
startTime = startTime,
|
||||
semester = semester,
|
||||
teacherId = teacherId,
|
||||
subjectId = subjectId,
|
||||
addedDate = addedDate
|
||||
).also {
|
||||
it.lessonNumber = lessonNumber
|
||||
it.isCounted = isCounted
|
||||
}
|
||||
|
||||
data.attendanceList.add(attendanceObject)
|
||||
if (baseType != Attendance.TYPE_PRESENT) {
|
||||
data.metadataList.add(
|
||||
Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_ATTENDANCE,
|
||||
attendanceObject.id,
|
||||
profile?.empty ?: true || baseType == Attendance.TYPE_PRESENT_CUSTOM || baseType == Attendance.TYPE_UNKNOWN,
|
||||
profile?.empty ?: true || baseType == Attendance.TYPE_PRESENT_CUSTOM || baseType == Attendance.TYPE_UNKNOWN
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getBaseType(attendanceType: JsonObject): Int {
|
||||
val absent = attendanceType.getBoolean("Absence") ?: false
|
||||
val excused = attendanceType.getBoolean("AbsenceJustified") ?: false
|
||||
return if (absent) {
|
||||
if (excused)
|
||||
Attendance.TYPE_ABSENT_EXCUSED
|
||||
else
|
||||
Attendance.TYPE_ABSENT
|
||||
} else {
|
||||
val belated = attendanceType.getBoolean("Late") ?: false
|
||||
val released = attendanceType.getBoolean("LegalAbsence") ?: false
|
||||
val present = attendanceType.getBoolean("Presence") ?: true
|
||||
if (belated)
|
||||
if (excused)
|
||||
Attendance.TYPE_BELATED_EXCUSED
|
||||
else
|
||||
Attendance.TYPE_BELATED
|
||||
else if (released)
|
||||
Attendance.TYPE_RELEASED
|
||||
else if (present)
|
||||
Attendance.TYPE_PRESENT
|
||||
else
|
||||
Attendance.TYPE_UNKNOWN
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user