diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt index d6c2c770..328450cb 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/Vulcan.kt @@ -200,6 +200,14 @@ class Vulcan(val app: App, val profile: Profile?, val loginStore: LoginStore, va } override fun getEvent(eventFull: EventFull) { + if (loginStore.mode != LOGIN_MODE_VULCAN_API) { + eventFull.homeworkBody = "" + + EventBus.getDefault().postSticky(EventGetEvent(eventFull)) + completed() + return + } + login(LOGIN_METHOD_VULCAN_API) { val list = data.app.db.eventDao().getAllNow(data.profileId).filter { !it.addedManually } VulcanApiAttachments(data, list, eventFull, EventFull::class) { _ -> diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeHomework.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeHomework.kt index fb6f2d6d..cb792e2c 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeHomework.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeHomework.kt @@ -4,6 +4,7 @@ package pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.hebe +import pl.szczodrzynski.edziennik.asJsonObjectList import pl.szczodrzynski.edziennik.data.api.VULCAN_HEBE_ENDPOINT_HOMEWORK import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.DataVulcan import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.ENDPOINT_VULCAN_HEBE_HOMEWORK @@ -11,8 +12,10 @@ import pl.szczodrzynski.edziennik.data.api.edziennik.vulcan.data.VulcanHebe import pl.szczodrzynski.edziennik.data.db.entity.Event import pl.szczodrzynski.edziennik.data.db.entity.Metadata import pl.szczodrzynski.edziennik.data.db.entity.SYNC_ALWAYS +import pl.szczodrzynski.edziennik.getJsonArray import pl.szczodrzynski.edziennik.getLong import pl.szczodrzynski.edziennik.getString +import pl.szczodrzynski.edziennik.utils.Utils class VulcanHebeHomework( override val data: DataVulcan, @@ -56,6 +59,22 @@ class VulcanHebeHomework( teamId = teamId ) + val attachments = exam.getJsonArray("Attachments") + ?.asJsonObjectList() + ?: return@forEach + + for (attachment in attachments) { + val fileName = attachment.getString("Name") ?: continue + val url = attachment.getString("Link") ?: continue + val attachmentName = "$fileName:$url" + val attachmentId = Utils.crc32(attachmentName.toByteArray()) + + eventObject.addAttachment( + id = attachmentId, + name = attachmentName + ) + } + data.eventList.add(eventObject) data.metadataList.add( Metadata( diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt index 9d13e883..0dcaa83e 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/db/entity/Event.kt @@ -93,6 +93,25 @@ open class Event( var attachmentIds: MutableList? = null var attachmentNames: MutableList? = null + /** + * Add an attachment + * @param id attachment ID + * @param name file name incl. extension + * @return a Event to which the attachment has been added + */ + fun addAttachment(id: Long, name: String): Event { + if (attachmentIds == null) attachmentIds = mutableListOf() + if (attachmentNames == null) attachmentNames = mutableListOf() + attachmentIds?.add(id) + attachmentNames?.add(name) + return this + } + + fun clearAttachments() { + attachmentIds = null + attachmentNames = null + } + @Ignore var showAsUnseen: Boolean? = null