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