diff --git a/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt b/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt index 32c3061..ac69b6b 100644 --- a/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt +++ b/app/src/main/java/org/lineageos/glimpse/ext/Intent.kt @@ -6,13 +6,22 @@ package org.lineageos.glimpse.ext import android.content.Intent -import android.net.Uri import org.lineageos.glimpse.models.Media +import org.lineageos.glimpse.models.MediaType.IMAGE +import org.lineageos.glimpse.models.MediaType.VIDEO -fun Intent.shareIntent(vararg uris: Uri) = apply { +fun Intent.shareIntent(vararg medias: Media) = apply { action = Intent.ACTION_SEND_MULTIPLE - putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris.toCollection(ArrayList())) - type = "*/*" + putParcelableArrayListExtra( + Intent.EXTRA_STREAM, + medias.map { it.externalContentUri }.toCollection(ArrayList()) + ) + type = when { + medias.all { it.mediaType == IMAGE } -> "image/*" + medias.all { it.mediaType == VIDEO } -> "video/*" + else -> "*/*" + } + flags = Intent.FLAG_GRANT_READ_URI_PERMISSION } fun Intent.editIntent(media: Media) = apply { diff --git a/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt b/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt index cd7ea09..16cb8ea 100644 --- a/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt +++ b/app/src/main/java/org/lineageos/glimpse/fragments/MediaViewerFragment.kt @@ -280,7 +280,7 @@ class MediaViewerFragment : Fragment( shareButton.setOnClickListener { mediaViewerAdapter.getMediaFromMediaStore(viewPager.currentItem)?.let { - val intent = Intent().shareIntent(it.externalContentUri) + val intent = Intent().shareIntent(it) startActivity(Intent.createChooser(intent, null)) } }