[Vulcan/Hebe] Add getting attachments in homework.

This commit is contained in:
Kacper Ziubryniewicz 2021-02-24 23:44:59 +01:00
parent d0baf02750
commit 459bbf78b2
3 changed files with 46 additions and 0 deletions

View File

@ -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) { _ ->

View File

@ -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(

View File

@ -93,6 +93,25 @@ open class Event(
var attachmentIds: MutableList<Long>? = null
var attachmentNames: MutableList<String>? = 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