simplify the uri getter at sharing media

This commit is contained in:
tibbi 2017-08-31 09:35:18 +02:00
parent f3255ac1fa
commit fe09961c61

View file

@ -48,6 +48,7 @@ fun Activity.shareMedium(medium: Medium) {
val shareTitle = resources.getString(R.string.share_via) val shareTitle = resources.getString(R.string.share_via)
val file = File(medium.path) val file = File(medium.path)
val uri = Uri.fromFile(file) val uri = Uri.fromFile(file)
Intent().apply { Intent().apply {
action = Intent.ACTION_SEND action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_STREAM, uri) putExtra(Intent.EXTRA_STREAM, uri)
@ -59,14 +60,12 @@ fun Activity.shareMedium(medium: Medium) {
fun Activity.shareMedia(media: List<Medium>) { fun Activity.shareMedia(media: List<Medium>) {
val shareTitle = resources.getString(R.string.share_via) val shareTitle = resources.getString(R.string.share_via)
val uris = ArrayList<Uri>(media.size) val uris = media.map { Uri.fromFile(File(it.path)) } as ArrayList
Intent().apply { Intent().apply {
action = Intent.ACTION_SEND_MULTIPLE action = Intent.ACTION_SEND_MULTIPLE
type = "image/* video/*" type = "image/* video/*"
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
media.map { File(it.path) }
.mapTo(uris) { Uri.fromFile(it) }
putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris) putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris)
startActivity(Intent.createChooser(this, shareTitle)) startActivity(Intent.createChooser(this, shareTitle))
} }