Use ShareIntentHandler early to avoid distributing the whole intent (#6274)
* Use `ShareIntentHandler` early to avoid distributing the whole intent This would make the intent be serialized as part of `NavTarget` and could potentially lead to `TransactionTooLargeException`s. We now pass a new `ShareIntentData` class around, containing the minimum amount of data needed. We also have a new `OnSharedData` post-processor to revoke uri access after they've been shared. * Move `UriToShare` next to `ShareIntentData` and add docs
This commit is contained in:
parent
2b04c4bfc0
commit
ae6ea76794
20 changed files with 285 additions and 141 deletions
|
|
@ -0,0 +1,15 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.share.api
|
||||
|
||||
/**
|
||||
* Post-processing to be done once a [ShareIntentData] has been consumed.
|
||||
*/
|
||||
fun interface OnSharedData {
|
||||
operator fun invoke(data: ShareIntentData)
|
||||
}
|
||||
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
package io.element.android.features.share.api
|
||||
|
||||
import android.content.Intent
|
||||
import com.bumble.appyx.core.modality.BuildContext
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import com.bumble.appyx.core.plugin.Plugin
|
||||
|
|
@ -16,7 +15,7 @@ import io.element.android.libraries.architecture.FeatureEntryPoint
|
|||
import io.element.android.libraries.matrix.api.core.RoomId
|
||||
|
||||
interface ShareEntryPoint : FeatureEntryPoint {
|
||||
data class Params(val intent: Intent)
|
||||
data class Params(val shareIntentData: ShareIntentData)
|
||||
|
||||
fun createNode(
|
||||
parentNode: Node,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.share.api
|
||||
|
||||
import android.net.Uri
|
||||
import android.os.Parcelable
|
||||
import kotlinx.parcelize.Parcelize
|
||||
|
||||
/**
|
||||
* Share intent data, mapped from the original [android.content.Intent].
|
||||
*/
|
||||
sealed interface ShareIntentData : Parcelable {
|
||||
/**
|
||||
* A list of [Uri]s to share and their mime types, with an optional [text] to be used as caption.
|
||||
*/
|
||||
@Parcelize
|
||||
data class Uris(val text: String?, val uris: List<UriToShare>) : ShareIntentData
|
||||
|
||||
/**
|
||||
* A plain text to share.
|
||||
*/
|
||||
@Parcelize
|
||||
data class PlainText(val content: String) : ShareIntentData
|
||||
}
|
||||
|
||||
/**
|
||||
* A [Uri] coming from an external share intent, with its associated [mimeType].
|
||||
*/
|
||||
@Parcelize
|
||||
data class UriToShare(
|
||||
val uri: Uri,
|
||||
val mimeType: String,
|
||||
) : Parcelable
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2026 Element Creations Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.features.share.api
|
||||
|
||||
import android.content.Intent
|
||||
|
||||
interface ShareIntentHandler {
|
||||
/**
|
||||
* This methods aims to handle incoming share intents and parse its data.
|
||||
*
|
||||
* @return the [ShareIntentData] if it could be resolved, or null.
|
||||
*/
|
||||
fun handleIncomingShareIntent(
|
||||
intent: Intent
|
||||
): ShareIntentData?
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue