diff options
author | Patrick Lang <72232737+patrickunterwegs@users.noreply.github.com> | 2022-09-17 19:10:51 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-17 19:10:51 +0300 |
commit | 73a3c70c3b4e62348efd882aad8798812db6ad37 (patch) | |
tree | ab868deb73a3ef618f1c41fdbe2dff06d35c685d | |
parent | 18e62f7b7efa69c6f4a3b0d7395b595ca9ef550d (diff) |
Added x-parameter to store filename and preserve it over sync (#51)
* Added x-parameter to store filename and preserve it over sync
* Minor update (setting flags as in other components)
Co-authored-by: Patrick Lang <patrick@techbee.at>
-rw-r--r-- | src/main/java/at/bitfire/ical4android/JtxICalObject.kt | 17 | ||||
-rw-r--r-- | src/main/java/at/techbee/jtx/JtxContract.kt | 21 |
2 files changed, 27 insertions, 11 deletions
diff --git a/src/main/java/at/bitfire/ical4android/JtxICalObject.kt b/src/main/java/at/bitfire/ical4android/JtxICalObject.kt index 43442d0..6c74078 100644 --- a/src/main/java/at/bitfire/ical4android/JtxICalObject.kt +++ b/src/main/java/at/bitfire/ical4android/JtxICalObject.kt @@ -196,12 +196,12 @@ open class JtxICalObject( companion object { const val X_PROP_COMPLETEDTIMEZONE = "X-COMPLETEDTIMEZONE" + const val X_PARAM_ATTACH_LABEL = "X-LABEL" // used for filename const val MAX_ATTACHMENT_SYNC_SIZE = 102400 // = 100KB /** - * Parses an iCalendar resource, applies [ICalPreprocessor] to increase compatibility - * and extracts the VTODOs and/or VJOURNALS. + * Parses an iCalendar resource and extracts the VTODOs and/or VJOURNALS. * * @param reader where the iCalendar is taken from * @@ -422,6 +422,10 @@ open class JtxICalObject( attachment.fmttype = it.value prop.parameters?.remove(it) } + prop.parameters?.getParameter<XParameter>(X_PARAM_ATTACH_LABEL)?.let { + attachment.filename = it.value + prop.parameters.remove(it) + } attachment.other = JtxContract.getJsonStringFromXParameters(prop.parameters) @@ -807,6 +811,7 @@ open class JtxICalObject( if(attachmentBytes.size <= MAX_ATTACHMENT_SYNC_SIZE) { // Sync only small attachments that are smaller than 100 KB, larger ones are ignored val att = Attach(attachmentBytes).apply { attachment.fmttype?.let { this.parameters.add(FmtType(it)) } + attachment.filename?.let { this.parameters.add(XParameter(X_PARAM_ATTACH_LABEL, it)) } } props += att } @@ -815,6 +820,7 @@ open class JtxICalObject( attachment.uri?.let { uri -> val att = Attach(URI(uri)).apply { attachment.fmttype?.let { this.parameters.add(FmtType(it)) } + attachment.filename?.let { this.parameters.add(XParameter(X_PARAM_ATTACH_LABEL, it)) } } props += att } @@ -1060,10 +1066,10 @@ duration?.let(props::add) var updateUri = JtxContract.JtxICalObject.CONTENT_URI.asSyncAdapter(collection.account) updateUri = Uri.withAppendedPath(updateUri, this.id.toString()) - val values = ContentValues() + val values = ContentValues(1) values.put(JtxContract.JtxICalObject.FLAGS, flags) - collection.client.update(updateUri, values, null, null) + this.flags = flags } /** @@ -1276,6 +1282,7 @@ duration?.let(props::add) put(JtxContract.JtxAttachment.URI, attachment.uri) put(JtxContract.JtxAttachment.FMTTYPE, attachment.fmttype) put(JtxContract.JtxAttachment.OTHER, attachment.other) + put(JtxContract.JtxAttachment.FILENAME, attachment.filename) } val newAttachment = collection.client.insert( JtxContract.JtxAttachment.CONTENT_URI.asSyncAdapter( @@ -1533,7 +1540,7 @@ duration?.let(props::add) attachmentValues.getAsString(JtxContract.JtxAttachment.BINARY)?.let { value -> this.binary = value } attachmentValues.getAsString(JtxContract.JtxAttachment.FMTTYPE)?.let { fmttype -> this.fmttype = fmttype } attachmentValues.getAsString(JtxContract.JtxAttachment.OTHER)?.let { other -> this.other = other } - + attachmentValues.getAsString(JtxContract.JtxAttachment.FILENAME)?.let { filename -> this.filename = filename } } attachments.add(attachment) } diff --git a/src/main/java/at/techbee/jtx/JtxContract.kt b/src/main/java/at/techbee/jtx/JtxContract.kt index ce1f42e..66ede8b 100644 --- a/src/main/java/at/techbee/jtx/JtxContract.kt +++ b/src/main/java/at/techbee/jtx/JtxContract.kt @@ -1,13 +1,16 @@ -/*************************************************************************************************** - * Copyright © All Contributors. See LICENSE and AUTHORS in the root directory for details. - **************************************************************************************************/ +/* + * Copyright (c) Techbee e.U. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Public License v3.0 + * which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/gpl.html + */ package at.techbee.jtx import android.accounts.Account import android.net.Uri import android.provider.BaseColumns -import android.util.Log import at.bitfire.ical4android.Ical4Android import net.fortuna.ical4j.model.ParameterList import net.fortuna.ical4j.model.Property @@ -39,7 +42,7 @@ object JtxContract { const val AUTHORITY = "at.techbee.jtx.provider" /** The version of this SyncContentProviderContract */ - const val VERSION = 1 + const val VERSION = 2 /** Constructs an Uri for the Jtx Sync Adapter with the given Account * @param [account] The account that should be appended to the Base Uri @@ -1218,6 +1221,13 @@ object JtxContract { const val FMTTYPE = "fmttype" /** + * Purpose: To specify the filename of the attachment. + * This is an X-PROPERTY that should be addressed as "X-LABEL" + * Type: [String] + */ + const val FILENAME = "filename" + + /** * Purpose: To specify other properties for the attachment. * see [https://tools.ietf.org/html/rfc5545#section-3.8.1.1] * The Parameters are stored as JSON. There are two helper functions provided: @@ -1405,5 +1415,4 @@ object JtxContract { */ const val UNKNOWN_VALUE = "value" } - }
\ No newline at end of file |