From e3318d01d77a7e3cbb928875b06be5b9f851877d Mon Sep 17 00:00:00 2001 From: tibbi Date: Sat, 4 Nov 2017 16:47:54 +0100 Subject: [PATCH] use shareUri instead of shareUris when sharing a single item --- .../commons/extensions/Activity.kt | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt index b4c79fb57..7c0853dba 100644 --- a/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt +++ b/commons/src/main/kotlin/com/simplemobiletools/commons/extensions/Activity.kt @@ -120,21 +120,25 @@ fun Activity.shareUri(uri: Uri, applicationId: String) { } fun Activity.shareUris(uris: ArrayList, applicationId: String) { - val newUris = uris.map { ensurePublicUri(it, applicationId) } as ArrayList - Intent().apply { - action = Intent.ACTION_SEND_MULTIPLE - type = newUris.getMimeType() - addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) - putParcelableArrayListExtra(Intent.EXTRA_STREAM, newUris) + if (uris.size == 1) { + shareUri(uris.first(), applicationId) + } else { + val newUris = uris.map { ensurePublicUri(it, applicationId) } as ArrayList + Intent().apply { + action = Intent.ACTION_SEND_MULTIPLE + type = newUris.getMimeType() + addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) + putParcelableArrayListExtra(Intent.EXTRA_STREAM, newUris) - if (resolveActivity(packageManager) != null) { - try { - startActivity(Intent.createChooser(this, getString(R.string.share_via))) - } catch (e: TransactionTooLargeException) { - toast(R.string.maximum_share_reached) + if (resolveActivity(packageManager) != null) { + try { + startActivity(Intent.createChooser(this, getString(R.string.share_via))) + } catch (e: TransactionTooLargeException) { + toast(R.string.maximum_share_reached) + } + } else { + toast(R.string.no_app_found) } - } else { - toast(R.string.no_app_found) } } }