[Vulcan/Hebe] Add getting attachments in messages.

This commit is contained in:
Kacper Ziubryniewicz 2021-02-24 21:18:35 +01:00
parent 4c081c970e
commit a939d95ea3
2 changed files with 28 additions and 8 deletions

View File

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

View File

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