forked from github/szkolny
[APIv2/Librus] Add getting homework
This commit is contained in:
parent
0875d13737
commit
3b273440cc
@ -5,15 +5,8 @@
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data
|
||||
|
||||
import pl.szczodrzynski.edziennik.R
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_EVENTS
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_ME
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_NORMAL_GRADES
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_SCHOOLS
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.api.LibrusApiEvents
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.api.LibrusApiGrades
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.api.LibrusApiMe
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.api.LibrusApiSchools
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.*
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.api.*
|
||||
import pl.szczodrzynski.edziennik.utils.Utils
|
||||
|
||||
class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
@ -43,21 +36,25 @@ class LibrusData(val data: DataLibrus, val onSuccess: () -> Unit) {
|
||||
Utils.d(TAG, "Using endpoint $endpointId")
|
||||
when (endpointId) {
|
||||
ENDPOINT_LIBRUS_API_ME -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_student_info)
|
||||
data.startProgress(R.string.sync_action_getting_account)
|
||||
LibrusApiMe(data) { onSuccess() }
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_SCHOOLS -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_school_info)
|
||||
data.startProgress(R.string.sync_action_syncing_school_info)
|
||||
LibrusApiSchools(data) { onSuccess() }
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_NORMAL_GRADES -> {
|
||||
data.startProgress(R.string.edziennik_progress_endpoint_grades)
|
||||
data.startProgress(R.string.sync_action_syncing_grades)
|
||||
LibrusApiGrades(data) { onSuccess() }
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_EVENTS -> {
|
||||
data.startProgress(R.string.sync_action_syncing_events)
|
||||
LibrusApiEvents(data) { onSuccess() }
|
||||
}
|
||||
ENDPOINT_LIBRUS_API_HOMEWORK -> {
|
||||
data.startProgress(R.string.sync_action_syncing_homework)
|
||||
LibrusApiHomework(data) { onSuccess() }
|
||||
}
|
||||
else -> onSuccess()
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class LibrusApiEvents(override val data: DataLibrus,
|
||||
teamId
|
||||
)
|
||||
|
||||
val addedDate = Date.fromIso(event.get("AddDate").asString)
|
||||
val addedDate = Date.fromIso(event.getString("AddDate") ?: return@forEach)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) Kuba Szczodrzyński 2019-10-12.
|
||||
*/
|
||||
|
||||
package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.ENDPOINT_LIBRUS_API_HOMEWORK
|
||||
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.events.Event
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.metadata.Metadata
|
||||
import pl.szczodrzynski.edziennik.getJsonArray
|
||||
import pl.szczodrzynski.edziennik.getJsonObject
|
||||
import pl.szczodrzynski.edziennik.getLong
|
||||
import pl.szczodrzynski.edziennik.getString
|
||||
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||
|
||||
class LibrusApiHomework(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
companion object {
|
||||
const val TAG = "LibrusApiHomework"
|
||||
}
|
||||
|
||||
init {
|
||||
apiGet(TAG, "HomeWorkAssignments") { json ->
|
||||
val homeworkList = json.getJsonArray("HomeWorkAssignments")
|
||||
|
||||
homeworkList?.forEach { homeworkEl ->
|
||||
val homework = homeworkEl.asJsonObject
|
||||
|
||||
val id = homework.getLong("Id") ?: return@forEach
|
||||
val eventDate = Date.fromY_m_d(homework.getString("DueDate") ?: return@forEach)
|
||||
val topic = (homework.getString("Topic") ?: "") + "\n" +
|
||||
(homework.getString("Text") ?: "")
|
||||
val teacherId = homework.getJsonObject("Teacher")?.getLong("Id") ?: -1
|
||||
|
||||
val eventObject = Event(
|
||||
profileId,
|
||||
id,
|
||||
eventDate,
|
||||
null,
|
||||
topic,
|
||||
-1,
|
||||
-1,
|
||||
false,
|
||||
teacherId,
|
||||
-1,
|
||||
-1
|
||||
)
|
||||
|
||||
val addedDate = Date.fromY_m_d(homework.getString("Date") ?: return@forEach)
|
||||
|
||||
data.eventList.add(eventObject)
|
||||
data.metadataList.add(Metadata(
|
||||
profileId,
|
||||
Metadata.TYPE_HOMEWORK,
|
||||
id,
|
||||
profile?.empty ?: false,
|
||||
profile?.empty ?: false,
|
||||
addedDate.inMillis
|
||||
))
|
||||
}
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_HOMEWORK, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}
|
||||
}
|
||||
}
|
@ -6,6 +6,7 @@ package pl.szczodrzynski.edziennik.api.v2.librus.data.api
|
||||
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.DataLibrus
|
||||
import pl.szczodrzynski.edziennik.api.v2.librus.data.LibrusApi
|
||||
import pl.szczodrzynski.edziennik.data.db.modules.api.SYNC_ALWAYS
|
||||
|
||||
class LibrusApiTemplate(override val data: DataLibrus,
|
||||
val onSuccess: () -> Unit) : LibrusApi(data) {
|
||||
@ -14,13 +15,10 @@ class LibrusApiTemplate(override val data: DataLibrus,
|
||||
}
|
||||
|
||||
init {
|
||||
/*apiGet(LibrusApiMe.TAG, "") { json ->
|
||||
/*apiGet(TAG, "") { json ->
|
||||
|
||||
// on error
|
||||
data.error(TAG, ERROR_LIBRUS_API_, response, json)
|
||||
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_, 2 * DAY)
|
||||
data.setSyncNext(ENDPOINT_LIBRUS_API_, SYNC_ALWAYS)
|
||||
onSuccess()
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user