ImageViewer, share image with description. (#3012)

This commit is contained in:
dima.avdeev
2023-04-08 15:46:25 +03:00
committed by GitHub
parent cc1ad2fe41
commit bb950bc91a
3 changed files with 14 additions and 1 deletions

View File

@@ -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())
}
}

View File

@@ -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
}

View File

@@ -57,7 +57,10 @@ fun getDependencies(ioScope: CoroutineScope, toastState: MutableState<ToastState
val window = UIApplication.sharedApplication.windows.last() as? UIWindow
val currentViewController = window?.rootViewController
val activityViewController = UIActivityViewController(
activityItems = listOf(UIImage(data = data)),
activityItems = listOf(
UIImage(data = data),
picture.description
),
applicationActivities = null
)
currentViewController?.presentViewController(