From bb950bc91a70c95e97a51b2242c54f59914eb087 Mon Sep 17 00:00:00 2001 From: "dima.avdeev" <99798741+dima-avdeev-jb@users.noreply.github.com> Date: Sat, 8 Apr 2023 15:46:25 +0300 Subject: [PATCH] ImageViewer, share image with description. (#3012) --- .../example/imageviewer/storage/AndroidImageStorage.kt | 6 ++++++ .../kotlin/example/imageviewer/view/ImageViewer.android.kt | 4 ++++ .../iosMain/kotlin/example/imageviewer/ImageViewer.ios.kt | 5 ++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/storage/AndroidImageStorage.kt b/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/storage/AndroidImageStorage.kt index 5210b17a85..7484a1bb4d 100644 --- a/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/storage/AndroidImageStorage.kt +++ b/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/storage/AndroidImageStorage.kt @@ -106,6 +106,9 @@ class AndroidImageStorage( @OptIn(ExperimentalResourceApi::class) suspend fun getUri(context: Context, picture: PictureData): Uri = withContext(Dispatchers.IO) { + if (!sharedImagesDir.exists()) { + sharedImagesDir.mkdirs() + } val tempFileToShare: File = sharedImagesDir.resolve("share_picture.jpg") when (picture) { is PictureData.Camera -> { @@ -113,6 +116,9 @@ class AndroidImageStorage( } is PictureData.Resource -> { + if (!tempFileToShare.exists()) { + tempFileToShare.createNewFile() + } tempFileToShare.writeBytes(resource(picture.resource).readBytes()) } } diff --git a/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/ImageViewer.android.kt b/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/ImageViewer.android.kt index 4c6fac9344..23faf137a2 100755 --- a/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/ImageViewer.android.kt +++ b/examples/imageviewer/shared/src/androidMain/kotlin/example/imageviewer/view/ImageViewer.android.kt @@ -57,6 +57,10 @@ private fun getDependencies( Intent.EXTRA_STREAM, imageStorage.getUri(context.androidContext, picture) ) + putExtra( + Intent.EXTRA_TEXT, + picture.description + ) type = "image/jpeg" flags = Intent.FLAG_GRANT_READ_URI_PERMISSION } diff --git a/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/ImageViewer.ios.kt b/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/ImageViewer.ios.kt index d693b51a7d..1f40b9740a 100755 --- a/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/ImageViewer.ios.kt +++ b/examples/imageviewer/shared/src/iosMain/kotlin/example/imageviewer/ImageViewer.ios.kt @@ -57,7 +57,10 @@ fun getDependencies(ioScope: CoroutineScope, toastState: MutableState