cleaner code saveDownloadingIfNeeded: refactor to use when and remove unnecessary null-safe calls
This commit is contained in:
@@ -55,25 +55,25 @@ object MediaSaverToDisk {
|
|||||||
onSuccess: () -> Any?,
|
onSuccess: () -> Any?,
|
||||||
onError: (Throwable) -> Any?,
|
onError: (Throwable) -> Any?,
|
||||||
) {
|
) {
|
||||||
videoUri?.let { theVideoUri ->
|
when {
|
||||||
if (!theVideoUri.startsWith("file")) {
|
videoUri.isNullOrBlank() -> return
|
||||||
downloadAndSave(
|
videoUri.startsWith("file") ->
|
||||||
url = theVideoUri,
|
|
||||||
mimeType = mimeType,
|
|
||||||
context = localContext,
|
|
||||||
forceProxy = forceProxy,
|
|
||||||
onSuccess = onSuccess,
|
|
||||||
onError = onError,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
save(
|
save(
|
||||||
localFile = theVideoUri.toUri().toFile(),
|
localFile = videoUri.toUri().toFile(),
|
||||||
mimeType = mimeType,
|
mimeType = mimeType,
|
||||||
context = localContext,
|
context = localContext,
|
||||||
onSuccess = onSuccess,
|
onSuccess = onSuccess,
|
||||||
onError = onError,
|
onError = onError,
|
||||||
)
|
)
|
||||||
}
|
else ->
|
||||||
|
downloadAndSave(
|
||||||
|
url = videoUri,
|
||||||
|
mimeType = mimeType,
|
||||||
|
forceProxy = forceProxy,
|
||||||
|
context = localContext,
|
||||||
|
onSuccess = onSuccess,
|
||||||
|
onError = onError,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user