mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2025-01-18 12:56:45 -06:00
[APIv2/Vulcan] Add getting notices
This commit is contained in:
parent
36c810fdbe
commit
bbf8f05d3c
@ -9,6 +9,7 @@ import pl.szczodrzynski.edziennik.api.v2.vulcan.*
|
|||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiDictionaries
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiDictionaries
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiEvents
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiEvents
|
||||||
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiGrades
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiGrades
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.api.VulcanApiNotices
|
||||||
import pl.szczodrzynski.edziennik.utils.Utils
|
import pl.szczodrzynski.edziennik.utils.Utils
|
||||||
|
|
||||||
class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
||||||
@ -55,6 +56,10 @@ class VulcanData(val data: DataVulcan, val onSuccess: () -> Unit) {
|
|||||||
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
data.startProgress(R.string.edziennik_progress_endpoint_homework)
|
||||||
VulcanApiEvents(data, isHomework = true) { onSuccess() }
|
VulcanApiEvents(data, isHomework = true) { onSuccess() }
|
||||||
}
|
}
|
||||||
|
ENDPOINT_VULCAN_API_NOTICES -> {
|
||||||
|
data.startProgress(R.string.edziennik_progress_endpoint_notices)
|
||||||
|
VulcanApiNotices(data) { onSuccess() }
|
||||||
|
}
|
||||||
else -> onSuccess()
|
else -> onSuccess()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) Kacper Ziubryniewicz 2019-10-23
|
||||||
|
*/
|
||||||
|
|
||||||
|
package pl.szczodrzynski.edziennik.api.v2.vulcan.data.api
|
||||||
|
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.VULCAN_API_ENDPOINT_NOTICES
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.DataVulcan
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.ENDPOINT_VULCAN_API_NOTICES
|
||||||
|
import pl.szczodrzynski.edziennik.api.v2.vulcan.data.VulcanApi
|
||||||
|
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.notices.Notice
|
||||||
|
import pl.szczodrzynski.edziennik.getJsonArray
|
||||||
|
import pl.szczodrzynski.edziennik.getLong
|
||||||
|
import pl.szczodrzynski.edziennik.getString
|
||||||
|
import pl.szczodrzynski.edziennik.utils.models.Date
|
||||||
|
|
||||||
|
class VulcanApiNotices(override val data: DataVulcan, val onSuccess: () -> Unit) : VulcanApi(data) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "VulcanApi"
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
apiGet(TAG, VULCAN_API_ENDPOINT_NOTICES) { json, _ ->
|
||||||
|
json.getJsonArray("Data")?.forEach { noticeEl ->
|
||||||
|
val notice = noticeEl.asJsonObject
|
||||||
|
|
||||||
|
val id = notice.getLong("Id") ?: return@forEach
|
||||||
|
val text = notice.getString("TrescUwagi") ?: return@forEach
|
||||||
|
val teacherId = notice.getLong("IdPracownik") ?: -1
|
||||||
|
val addedDate = Date.fromY_m_d(notice.getString("DataWpisuTekst")).inMillis
|
||||||
|
|
||||||
|
val noticeObject = Notice(
|
||||||
|
profileId,
|
||||||
|
id,
|
||||||
|
text,
|
||||||
|
profile!!.currentSemester,
|
||||||
|
Notice.TYPE_NEUTRAL,
|
||||||
|
teacherId
|
||||||
|
)
|
||||||
|
|
||||||
|
data.noticeList.add(noticeObject)
|
||||||
|
data.metadataList.add(Metadata(
|
||||||
|
profileId,
|
||||||
|
Metadata.TYPE_NOTICE,
|
||||||
|
id,
|
||||||
|
profile?.empty ?: false,
|
||||||
|
profile?.empty ?: false,
|
||||||
|
addedDate
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
data.setSyncNext(ENDPOINT_VULCAN_API_NOTICES, SYNC_ALWAYS)
|
||||||
|
onSuccess()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -954,4 +954,5 @@
|
|||||||
<string name="edziennik_progress_endpoint_dictionaries">Pobieranie słowników...</string>
|
<string name="edziennik_progress_endpoint_dictionaries">Pobieranie słowników...</string>
|
||||||
<string name="toolbar_subtitle_syncing">Synchronizuję...</string>
|
<string name="toolbar_subtitle_syncing">Synchronizuję...</string>
|
||||||
<string name="toolbar_subtitle_syncing_format">[%d%%] %s</string>
|
<string name="toolbar_subtitle_syncing_format">[%d%%] %s</string>
|
||||||
|
<string name="edziennik_progress_endpoint_notices">Pobieranie uwag...</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user