diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeMessages.kt b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeMessages.kt index 1e9a3b09..eb4091e0 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeMessages.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/data/api/edziennik/vulcan/data/hebe/VulcanHebeMessages.kt @@ -17,6 +17,7 @@ import pl.szczodrzynski.edziennik.data.db.entity.* import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_DELETED import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_RECEIVED import pl.szczodrzynski.edziennik.data.db.entity.Message.Companion.TYPE_SENT +import pl.szczodrzynski.edziennik.utils.Utils import pl.szczodrzynski.navlib.crc16 import kotlin.text.replace @@ -110,6 +111,23 @@ class VulcanHebeMessages( data.messageRecipientList.add(messageRecipientObject) } + val attachments = message.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()) + + messageObject.addAttachment( + id = attachmentId, + name = attachmentName, + size = -1 + ) + } + data.messageList.add(messageObject) data.setSeenMetadataList.add( Metadata( diff --git a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/AttachmentsView.kt b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/AttachmentsView.kt index 482ab847..354a8921 100644 --- a/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/AttachmentsView.kt +++ b/app/src/main/java/pl/szczodrzynski/edziennik/ui/modules/views/AttachmentsView.kt @@ -121,19 +121,21 @@ class AttachmentsView @JvmOverloads constructor( // open file by name, or first part before ':' (Vulcan OneDrive) Utils.openFile(context, File(Utils.getStorageDir(), attachment.name.substringBefore(":"))) return - } + } else if (attachment.name.contains(":")) { + Utils.openUrl(context, attachment.name.substringAfter(":")) + } else { + attachment.isDownloading = true + (adapter as? AttachmentAdapter)?.let { + it.notifyItemChanged(it.items.indexOf(attachment)) + } - attachment.isDownloading = true - (adapter as? AttachmentAdapter)?.let { - it.notifyItemChanged(it.items.indexOf(attachment)) - } - - EdziennikTask.attachmentGet( + EdziennikTask.attachmentGet( attachment.profileId, attachment.owner, attachment.id, attachment.name - ).enqueue(context) + ).enqueue(context) + } } private val lastUpdate: Long = 0