Glimpse: Try to set proper mime type when sharing media
We also have to grant read URI permission in case the receiving end doesn't have the read media permission. Change-Id: I28b77b680bdff123a0c737eb41ddcdbe34dba1cb
This commit is contained in:
parent
568bd417f2
commit
1cb30ec8bb
|
@ -6,13 +6,22 @@
|
||||||
package org.lineageos.glimpse.ext
|
package org.lineageos.glimpse.ext
|
||||||
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
|
||||||
import org.lineageos.glimpse.models.Media
|
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
|
action = Intent.ACTION_SEND_MULTIPLE
|
||||||
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris.toCollection(ArrayList()))
|
putParcelableArrayListExtra(
|
||||||
type = "*/*"
|
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 {
|
fun Intent.editIntent(media: Media) = apply {
|
||||||
|
|
|
@ -280,7 +280,7 @@ class MediaViewerFragment : Fragment(
|
||||||
|
|
||||||
shareButton.setOnClickListener {
|
shareButton.setOnClickListener {
|
||||||
mediaViewerAdapter.getMediaFromMediaStore(viewPager.currentItem)?.let {
|
mediaViewerAdapter.getMediaFromMediaStore(viewPager.currentItem)?.let {
|
||||||
val intent = Intent().shareIntent(it.externalContentUri)
|
val intent = Intent().shareIntent(it)
|
||||||
startActivity(Intent.createChooser(intent, null))
|
startActivity(Intent.createChooser(intent, null))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue