mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 12:56:45 -06:00
[APIv2/Librus] Move some code
This commit is contained in:
parent
e138ca6eab
commit
b32ebe4479
@ -31,10 +31,11 @@ class LibrusApiAnnouncements(override val data: DataLibrus,
|
|||||||
?: return@forEach).toLong()
|
?: return@forEach).toLong()
|
||||||
val subject = announcement.getString("Subject") ?: ""
|
val subject = announcement.getString("Subject") ?: ""
|
||||||
val text = announcement.getString("Content") ?: ""
|
val text = announcement.getString("Content") ?: ""
|
||||||
val startDate = Date.fromY_m_d(announcement.getString("StartDate")
|
val startDate = Date.fromY_m_d(announcement.getString("StartDate"))
|
||||||
?: return@forEach)
|
val endDate = Date.fromY_m_d(announcement.getString("EndDate"))
|
||||||
val endDate = Date.fromY_m_d(announcement.getString("EndDate") ?: return@forEach)
|
|
||||||
val teacherId = announcement.getJsonObject("AddedBy")?.getLong("Id") ?: -1
|
val teacherId = announcement.getJsonObject("AddedBy")?.getLong("Id") ?: -1
|
||||||
|
val addedDate = Date.fromIso(announcement.getString("CreationDate"))
|
||||||
|
val read = announcement.getBoolean("WasRead") ?: false
|
||||||
|
|
||||||
val announcementObject = Announcement(
|
val announcementObject = Announcement(
|
||||||
profileId,
|
profileId,
|
||||||
@ -46,10 +47,6 @@ class LibrusApiAnnouncements(override val data: DataLibrus,
|
|||||||
teacherId
|
teacherId
|
||||||
)
|
)
|
||||||
|
|
||||||
val addedDate = Date.fromIso(announcement.getString("CreationDate")
|
|
||||||
?: return@forEach)
|
|
||||||
val read = announcement.getBoolean("WasRead") ?: false
|
|
||||||
|
|
||||||
data.announcementList.add(announcementObject)
|
data.announcementList.add(announcementObject)
|
||||||
data.metadataList.add(Metadata(
|
data.metadataList.add(Metadata(
|
||||||
profileId,
|
profileId,
|
||||||
|
@ -27,22 +27,20 @@ class LibrusApiAttendances(override val data: DataLibrus,
|
|||||||
attendances?.forEach { attendanceEl ->
|
attendances?.forEach { attendanceEl ->
|
||||||
val attendance = attendanceEl.asJsonObject
|
val attendance = attendanceEl.asJsonObject
|
||||||
|
|
||||||
|
val id = Utils.strToInt((attendance.getString("Id") ?: return@forEach)
|
||||||
|
.replace("[^\\d.]".toRegex(), "")).toLong()
|
||||||
val teacherId = attendance.getJsonObject("AddedBy")?.getLong("Id") ?: -1
|
val teacherId = attendance.getJsonObject("AddedBy")?.getLong("Id") ?: -1
|
||||||
val lessonNo = attendance.getInt("LessonNo") ?: return@forEach
|
val lessonNo = attendance.getInt("LessonNo") ?: return@forEach
|
||||||
val startTime = data.lessonRanges.get(lessonNo).startTime
|
val startTime = data.lessonRanges.get(lessonNo).startTime
|
||||||
val lessonDate = Date.fromY_m_d(attendance.getString("Date") ?: return@forEach)
|
val lessonDate = Date.fromY_m_d(attendance.getString("Date"))
|
||||||
|
val subjectId = data.lessonList.singleOrNull {
|
||||||
|
it.weekDay == lessonDate.weekDay && it.startTime.value == startTime.value
|
||||||
|
}?.subjectId ?: -1
|
||||||
val semester = attendance.getInt("Semester") ?: return@forEach
|
val semester = attendance.getInt("Semester") ?: return@forEach
|
||||||
var type = attendance.getJsonObject("Type")?.getInt("Id") ?: return@forEach
|
var type = attendance.getJsonObject("Type")?.getInt("Id") ?: return@forEach
|
||||||
val attendanceType = data.attendanceTypes.get(type)
|
val attendanceType = data.attendanceTypes.get(type)
|
||||||
val topic = attendanceType.second
|
val topic = attendanceType.second
|
||||||
|
|
||||||
val id = Utils.strToInt((attendance.getString("Id") ?: return@forEach)
|
|
||||||
.replace("[^\\d.]".toRegex(), "")).toLong()
|
|
||||||
|
|
||||||
val subjectId = data.lessonList.singleOrNull {
|
|
||||||
it.weekDay == lessonDate.weekDay && it.startTime.value == startTime.value
|
|
||||||
}?.subjectId ?: -1
|
|
||||||
|
|
||||||
type = when(type) {
|
type = when(type) {
|
||||||
1 -> Attendance.TYPE_ABSENT
|
1 -> Attendance.TYPE_ABSENT
|
||||||
2 -> Attendance.TYPE_BELATED
|
2 -> Attendance.TYPE_BELATED
|
||||||
|
@ -46,7 +46,7 @@ class LibrusApiClasses(override val data: DataLibrus,
|
|||||||
?: return@apply)
|
?: return@apply)
|
||||||
dateYearEnd = Date.fromY_m_d(studentClass.getString("EndSchoolYear")
|
dateYearEnd = Date.fromY_m_d(studentClass.getString("EndSchoolYear")
|
||||||
?: return@apply)
|
?: return@apply)
|
||||||
if (unitId != null) putStudentData("unitId", unitId)
|
unitId?.let { putStudentData("unitId", it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,8 +28,8 @@ class LibrusApiEvents(override val data: DataLibrus,
|
|||||||
val event = eventEl.asJsonObject
|
val event = eventEl.asJsonObject
|
||||||
|
|
||||||
val id = event.getLong("Id") ?: return@forEach
|
val id = event.getLong("Id") ?: return@forEach
|
||||||
val eventDate = Date.fromY_m_d(event.getString("Date") ?: return@forEach)
|
val eventDate = Date.fromY_m_d(event.getString("Date"))
|
||||||
val topic = event.getString("Content") ?: return@forEach
|
val topic = event.getString("Content") ?: ""
|
||||||
val type = event.getJsonObject("Category")?.getInt("Id") ?: -1
|
val type = event.getJsonObject("Category")?.getInt("Id") ?: -1
|
||||||
val teacherId = event.getJsonObject("CreatedBy")?.getLong("Id") ?: -1
|
val teacherId = event.getJsonObject("CreatedBy")?.getLong("Id") ?: -1
|
||||||
val subjectId = event.getJsonObject("Subject")?.getLong("Id") ?: -1
|
val subjectId = event.getJsonObject("Subject")?.getLong("Id") ?: -1
|
||||||
@ -37,8 +37,8 @@ class LibrusApiEvents(override val data: DataLibrus,
|
|||||||
|
|
||||||
val lessonNo = event.getInt("LessonNo")
|
val lessonNo = event.getInt("LessonNo")
|
||||||
val lessonRange = data.lessonRanges.singleOrNull { it.lessonNumber == lessonNo }
|
val lessonRange = data.lessonRanges.singleOrNull { it.lessonNumber == lessonNo }
|
||||||
val startTime = lessonRange?.startTime
|
val startTime = lessonRange?.startTime ?: Time.fromH_m(event.getString("TimeFrom"))
|
||||||
?: Time.fromH_m(event.getString("TimeFrom") ?: return@forEach)
|
val addedDate = Date.fromIso(event.getString("AddDate"))
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId,
|
||||||
@ -54,8 +54,6 @@ class LibrusApiEvents(override val data: DataLibrus,
|
|||||||
teamId
|
teamId
|
||||||
)
|
)
|
||||||
|
|
||||||
val addedDate = Date.fromIso(event.getString("AddDate") ?: return@forEach)
|
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
data.metadataList.add(
|
data.metadataList.add(
|
||||||
Metadata(
|
Metadata(
|
||||||
|
@ -25,11 +25,12 @@ class LibrusApiGrades(override val data: DataLibrus,
|
|||||||
val grade = gradeEl.asJsonObject
|
val grade = gradeEl.asJsonObject
|
||||||
|
|
||||||
val id = grade.getLong("Id") ?: return@forEach
|
val id = grade.getLong("Id") ?: return@forEach
|
||||||
val categoryId = grade.getJsonObject("Category")?.getLong("Id") ?: return@forEach
|
val categoryId = grade.getJsonObject("Category")?.getLong("Id") ?: -1
|
||||||
val name = grade.getString("Grade") ?: return@forEach
|
val name = grade.getString("Grade") ?: ""
|
||||||
val semester = grade.getInt("Semester") ?: return@forEach
|
val semester = grade.getInt("Semester") ?: return@forEach
|
||||||
val teacherId = grade.getJsonObject("AddedBy")?.getLong("Id") ?: -1
|
val teacherId = grade.getJsonObject("AddedBy")?.getLong("Id") ?: -1
|
||||||
val subjectId = grade.getJsonObject("Subject")?.getLong("Id") ?: -1
|
val subjectId = grade.getJsonObject("Subject")?.getLong("Id") ?: -1
|
||||||
|
val addedDate = Date.fromIso(grade.getString("AddDate"))
|
||||||
|
|
||||||
val category = data.gradeCategories.singleOrNull { it.categoryId == categoryId }
|
val category = data.gradeCategories.singleOrNull { it.categoryId == categoryId }
|
||||||
val categoryName = category?.text ?: ""
|
val categoryName = category?.text ?: ""
|
||||||
@ -80,8 +81,6 @@ class LibrusApiGrades(override val data: DataLibrus,
|
|||||||
gradeObject.isImprovement = true
|
gradeObject.isImprovement = true
|
||||||
}
|
}
|
||||||
|
|
||||||
val addedDate = Date.fromIso(grade.get("AddDate").asString)
|
|
||||||
|
|
||||||
data.gradeList.add(gradeObject)
|
data.gradeList.add(gradeObject)
|
||||||
data.metadataList.add(
|
data.metadataList.add(
|
||||||
Metadata(
|
Metadata(
|
||||||
|
@ -30,10 +30,10 @@ class LibrusApiHomework(override val data: DataLibrus,
|
|||||||
val homework = homeworkEl.asJsonObject
|
val homework = homeworkEl.asJsonObject
|
||||||
|
|
||||||
val id = homework.getLong("Id") ?: return@forEach
|
val id = homework.getLong("Id") ?: return@forEach
|
||||||
val eventDate = Date.fromY_m_d(homework.getString("DueDate") ?: return@forEach)
|
val eventDate = Date.fromY_m_d(homework.getString("DueDate"))
|
||||||
val topic = (homework.getString("Topic") ?: "") + "\n" +
|
val topic = homework.getString("Topic") + "\n" + homework.getString("Text")
|
||||||
(homework.getString("Text") ?: "")
|
|
||||||
val teacherId = homework.getJsonObject("Teacher")?.getLong("Id") ?: -1
|
val teacherId = homework.getJsonObject("Teacher")?.getLong("Id") ?: -1
|
||||||
|
val addedDate = Date.fromY_m_d(homework.getString("Date"))
|
||||||
|
|
||||||
val eventObject = Event(
|
val eventObject = Event(
|
||||||
profileId,
|
profileId,
|
||||||
@ -49,8 +49,6 @@ class LibrusApiHomework(override val data: DataLibrus,
|
|||||||
-1
|
-1
|
||||||
)
|
)
|
||||||
|
|
||||||
val addedDate = Date.fromY_m_d(homework.getString("Date") ?: return@forEach)
|
|
||||||
|
|
||||||
data.eventList.add(eventObject)
|
data.eventList.add(eventObject)
|
||||||
data.metadataList.add(Metadata(
|
data.metadataList.add(Metadata(
|
||||||
profileId,
|
profileId,
|
||||||
|
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
|||||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS
|
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS
|
||||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||||
|
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||||
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsence
|
import pl.szczodrzynski.edziennik.data.db.modules.teachers.TeacherAbsence
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
import pl.szczodrzynski.edziennik.utils.models.Time
|
import pl.szczodrzynski.edziennik.utils.models.Time
|
||||||
@ -49,6 +50,14 @@ class LibrusApiTeacherFreeDays(override val data: DataLibrus,
|
|||||||
)
|
)
|
||||||
|
|
||||||
data.teacherAbsenceList.add(teacherAbsenceObject)
|
data.teacherAbsenceList.add(teacherAbsenceObject)
|
||||||
|
data.metadataList.add(Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_TEACHER_ABSENCE,
|
||||||
|
id,
|
||||||
|
profile?.empty ?: false,
|
||||||
|
profile?.empty ?: false,
|
||||||
|
System.currentTimeMillis()
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
data.setSyncNext(ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS, SYNC_ALWAYS)
|
data.setSyncNext(ENDPOINT_LIBRUS_API_TEACHER_FREE_DAYS, SYNC_ALWAYS)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user