Created
August 11, 2017 08:58
-
-
Save vihuela/ee973db7b43e085a1c197a4621847b65 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getTargetFile(context: Context, uri: Uri, getFile: (f: File?) -> Unit) { | |
val targetPath = when (uri.authority) { | |
//拍照 | |
AUTHORITY -> "${Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)}/${uri.path.substring(uri.path.lastIndexOf("/") + 1, uri.path.length)}" | |
//图库选择 | |
"media" -> PhotoMetadataUtils.getPath(context.contentResolver, uri) | |
else -> { | |
getFile.invoke(null) | |
null | |
} | |
} | |
//异步压缩 | |
Luban.with(context) | |
.load(File(targetPath ?: return)) | |
.setCompressListener(object : OnCompressListener { | |
override fun onSuccess(f: File?) { | |
getFile.invoke(f) | |
} | |
override fun onError(e: Throwable?) { | |
getFile.invoke(null) | |
} | |
override fun onStart() { | |
} | |
}).launch() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment