mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 21:06:44 -06:00
[APIv2/Idziennik] Fix getting subject and rewrite getting proposed grades.
This commit is contained in:
parent
c2e7931ea6
commit
ca3b6d0705
@ -59,13 +59,14 @@ class IdziennikWebExams(override val data: DataIdziennik,
|
||||
json.getJsonArray("ListK")?.asJsonObjectList()?.forEach { exam ->
|
||||
val id = exam.getLong("_recordId") ?: return@forEach
|
||||
val examDate = Date.fromY_m_d(exam.getString("data") ?: return@forEach)
|
||||
val subjectId = data.getSubject(exam.getString("przedmiot") ?: return@forEach,
|
||||
-1, "").id
|
||||
val teacherId = data.getTeacherByLastFirst(exam.getString("wpisal")
|
||||
?: return@forEach).id
|
||||
val subjectName = exam.getString("przedmiot") ?: return@forEach
|
||||
val subjectId = data.getSubject(subjectName, null, subjectName).id
|
||||
val teacherName = exam.getString("wpisal") ?: return@forEach
|
||||
val teacherId = data.getTeacherByLastFirst(teacherName).id
|
||||
val topic = exam.getString("zakres") ?: ""
|
||||
|
||||
val lessonList = data.db.timetableDao().getForDateNow(profileId, examDate)
|
||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.startTime
|
||||
val topic = exam.getString("zakres") ?: ""
|
||||
|
||||
val eventType = when (exam.getString("rodzaj")) {
|
||||
"sprawdzian/praca klasowa" -> Event.TYPE_EXAM
|
||||
|
@ -50,10 +50,10 @@ class IdziennikWebHomework(override val data: DataIdziennik,
|
||||
json.getJsonArray("ListK")?.asJsonObjectList()?.forEach { homework ->
|
||||
val id = homework.getLong("_recordId") ?: return@forEach
|
||||
val eventDate = Date.fromY_m_d(homework.getString("dataO") ?: return@forEach)
|
||||
val subjectId = data.getSubject(homework.getString("przed") ?: return@forEach,
|
||||
-1, "").id
|
||||
val teacherId = data.getTeacherByLastFirst(homework.getString("usr")
|
||||
?: return@forEach).id
|
||||
val subjectName = homework.getString("przed") ?: return@forEach
|
||||
val subjectId = data.getSubject(subjectName, null, subjectName).id
|
||||
val teacherName = homework.getString("usr") ?: return@forEach
|
||||
val teacherId = data.getTeacherByLastFirst(teacherName).id
|
||||
val lessonList = data.db.timetableDao().getForDateNow(profileId, eventDate)
|
||||
val startTime = lessonList.firstOrNull { it.subjectId == subjectId }?.displayStartTime
|
||||
val topic = homework.getString("tytul") ?: ""
|
||||
|
@ -10,21 +10,24 @@ import pl.szczodrzynski.edziennik.api.v2.idziennik.DataIdziennik
|
||||
import pl.szczodrzynski.edziennik.api.v2.idziennik.ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES
|
||||
import pl.szczodrzynski.edziennik.api.v2.idziennik.data.IdziennikWeb
|
||||
import pl.szczodrzynski.edziennik.api.v2.models.ApiError
|
||||
import pl.szczodrzynski.edziennik.asJsonObjectList
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_SEMESTER1_PROPOSED
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.grades.Grade.TYPE_YEAR_PROPOSED
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.Utils.getWordGradeValue
|
||||
|
||||
class IdziennikWebProposedGrades(override val data: DataIdziennik,
|
||||
val onSuccess: () -> Unit) : IdziennikWeb(data) {
|
||||
val onSuccess: () -> Unit) : IdziennikWeb(data) {
|
||||
companion object {
|
||||
private const val TAG = "IdziennikWebProposedGrades"
|
||||
}
|
||||
|
||||
init {
|
||||
init { data.profile?.also { profile ->
|
||||
webApiGet(TAG, IDZIENNIK_WEB_MISSING_GRADES, mapOf(
|
||||
"idPozDziennika" to data.registerId
|
||||
)) { result ->
|
||||
@ -34,17 +37,17 @@ class IdziennikWebProposedGrades(override val data: DataIdziennik,
|
||||
return@webApiGet
|
||||
}
|
||||
|
||||
val jSubjects = json.getAsJsonArray("Przedmioty")
|
||||
for (jSubjectEl in jSubjects) {
|
||||
val jSubject = jSubjectEl.getAsJsonObject()
|
||||
// jSubject
|
||||
val rSubject = data.getSubject(jSubject.get("Przedmiot").getAsString(), -1, jSubject.get("Przedmiot").getAsString())
|
||||
val semester1Proposed = jSubject.get("OcenaSem1").getAsString()
|
||||
val semester2Proposed = jSubject.get("OcenaSem2").getAsString()
|
||||
json.getJsonArray("Przedmioty")?.asJsonObjectList()?.forEach { subject ->
|
||||
val subjectName = subject.getString("Przedmiot") ?: return@forEach
|
||||
val subjectObject = data.getSubject(subjectName, null, subjectName)
|
||||
|
||||
val semester1Proposed = subject.getString("OcenaSem1") ?: ""
|
||||
val semester1Value = getWordGradeValue(semester1Proposed)
|
||||
val semester1Id = subjectObject.id * (-100) - 1
|
||||
|
||||
val semester2Proposed = subject.getString("OcenaSem2") ?: ""
|
||||
val semester2Value = getWordGradeValue(semester2Proposed)
|
||||
val semester1Id = rSubject.id * -100 - 1
|
||||
val semester2Id = rSubject.id * -100 - 2
|
||||
val semester2Id = subjectObject.id * (-100) - 2
|
||||
|
||||
if (semester1Proposed != "") {
|
||||
val gradeObject = Grade(
|
||||
@ -58,17 +61,18 @@ class IdziennikWebProposedGrades(override val data: DataIdziennik,
|
||||
0f,
|
||||
1,
|
||||
-1,
|
||||
rSubject.id)
|
||||
|
||||
gradeObject.type = TYPE_SEMESTER1_PROPOSED
|
||||
subjectObject.id
|
||||
).apply {
|
||||
type = TYPE_SEMESTER1_PROPOSED
|
||||
}
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
gradeObject.id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
}
|
||||
@ -85,17 +89,18 @@ class IdziennikWebProposedGrades(override val data: DataIdziennik,
|
||||
0f,
|
||||
2,
|
||||
-1,
|
||||
rSubject.id)
|
||||
|
||||
gradeObject.type = TYPE_YEAR_PROPOSED
|
||||
subjectObject.id
|
||||
).apply {
|
||||
type = TYPE_YEAR_PROPOSED
|
||||
}
|
||||
|
||||
data.gradeList.add(gradeObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_GRADE,
|
||||
gradeObject.id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
profile.empty,
|
||||
profile.empty,
|
||||
System.currentTimeMillis()
|
||||
))
|
||||
}
|
||||
@ -104,5 +109,5 @@ class IdziennikWebProposedGrades(override val data: DataIdziennik,
|
||||
data.setSyncNext(ENDPOINT_IDZIENNIK_WEB_PROPOSED_GRADES, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user