mirror of
https://github.com/szkolny-eu/szkolny-android.git
synced 2024-11-24 10:54:36 -06:00
[Vulcan/Hebe] Add getting attachments in messages.
This commit is contained in:
parent
4c081c970e
commit
a939d95ea3
@ -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(
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user