Skip to content

Commit

Permalink
优化Android图片分享逻辑,优先把LocalImagePath以最大限度保证图片质量
Browse files Browse the repository at this point in the history
  • Loading branch information
JarvanMo committed Oct 30, 2024
1 parent 164b0c1 commit a803f63
Showing 1 changed file with 33 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}


Expand Down

0 comments on commit a803f63

Please sign in to comment.