提交 a803f634 authored 作者: JarvanMo's avatar JarvanMo

优化Android图片分享逻辑,优先把LocalImagePath以最大限度保证图片质量

上级 164b0c13
......@@ -106,44 +106,47 @@ internal interface FluwxShareHandler : CoroutineScope {
val map: Map<String, Any> = call.argument("source") ?: mapOf()
val imgHash = call.argument<String?>("imgDataHash")
val uint8List = map["uint8List"] as? ByteArray
val imageObject = uint8List?.let {
val localImagePath = map["localImagePath"] as? String
val imageObject = localImagePath?.let {
WXImageObject().apply {
imageData = it
imgDataHash = imgHash
}
} ?: run {
WXImageObject().apply {
val localImagePath = map["localImagePath"] as? String
localImagePath?.also {
if (supportFileProvider && targetHigherThanN) {
if (localImagePath.startsWith("content://")) {
imagePath = localImagePath
} else {
val tempFile = File(localImagePath)
val ecd = context.externalCacheDir ?: return@also
val desPath =
ecd.absolutePath + File.separator + cachePathName
if (tempFile.exists()) {
val target = if (isFileInDirectory(
file = tempFile,
directory = File(desPath)
)
) {
tempFile
} else {
withContext(Dispatchers.IO) {
copyFile(tempFile.absolutePath, desPath)
}
if (supportFileProvider && targetHigherThanN) {
if (localImagePath.startsWith("content://")) {
imagePath = localImagePath
} else {
val tempFile = File(localImagePath)
val ecd = context.externalCacheDir ?: return@apply
val desPath =
ecd.absolutePath + File.separator + cachePathName
if (tempFile.exists()) {
val target = if (isFileInDirectory(
file = tempFile,
directory = File(desPath)
)
) {
tempFile
} else {
withContext(Dispatchers.IO) {
copyFile(tempFile.absolutePath, desPath)
}
imagePath = getFileContentUri(target)
}
imagePath = getFileContentUri(target)
}
}
} else {
imagePath = localImagePath
}
imgDataHash = imgHash
}
} ?: run {
WXImageObject().apply {
val uint8List = map["uint8List"] as? ByteArray
uint8List?.let {
imageData = it
imgDataHash = imgHash
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论