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

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

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