This commit is contained in:
Vitor Pamplona
2025-03-17 13:55:18 -04:00
2 changed files with 16 additions and 11 deletions
@@ -55,10 +55,10 @@ object MediaSaverToDisk {
onSuccess: () -> Any?, onSuccess: () -> Any?,
onError: (Throwable) -> Any?, onError: (Throwable) -> Any?,
) { ) {
if (videoUri != null) { videoUri?.let { theVideoUri ->
if (!videoUri.startsWith("file")) { if (!theVideoUri.startsWith("file")) {
downloadAndSave( downloadAndSave(
url = videoUri, url = theVideoUri,
mimeType = mimeType, mimeType = mimeType,
context = localContext, context = localContext,
forceProxy = forceProxy, forceProxy = forceProxy,
@@ -67,7 +67,7 @@ object MediaSaverToDisk {
) )
} else { } else {
save( save(
localFile = videoUri.toUri().toFile(), localFile = theVideoUri.toUri().toFile(),
mimeType = mimeType, mimeType = mimeType,
context = localContext, context = localContext,
onSuccess = onSuccess, onSuccess = onSuccess,
@@ -124,8 +124,8 @@ object MediaSaverToDisk {
checkNotNull(contentType) { "Can't find out the content type" } checkNotNull(contentType) { "Can't find out the content type" }
val realType = val realType =
if (mimeType != null && contentType == "application/octet-stream") { if (contentType == "application/octet-stream") {
mimeType mimeType ?: getMimeTypeFromExtension(url)
} else { } else {
contentType contentType
} }
@@ -154,6 +154,11 @@ object MediaSaverToDisk {
) )
} }
private fun getMimeTypeFromExtension(fileName: String): String =
fileName.substringAfterLast('.', "").lowercase().let {
MimeTypeMap.getSingleton().getMimeTypeFromExtension(it).orEmpty()
}
fun save( fun save(
localFile: File, localFile: File,
mimeType: String?, mimeType: String?,
@@ -175,7 +180,7 @@ object MediaSaverToDisk {
) )
} else { } else {
saveContentDefault( saveContentDefault(
fileName = UUID.randomUUID().toString() + ".$extension", fileName = "${UUID.randomUUID()}.$extension",
contentSource = buffer, contentSource = buffer,
context = context, context = context,
) )
@@ -206,10 +211,9 @@ object MediaSaverToDisk {
} }
val masterUri = val masterUri =
if (contentType.startsWith("image")) { when {
MediaStore.Images.Media.EXTERNAL_CONTENT_URI contentType.startsWith("image") -> MediaStore.Images.Media.EXTERNAL_CONTENT_URI
} else { else -> MediaStore.Video.Media.EXTERNAL_CONTENT_URI
MediaStore.Video.Media.EXTERNAL_CONTENT_URI
} }
val uri = contentResolver.insert(masterUri, contentValues) val uri = contentResolver.insert(masterUri, contentValues)
@@ -20,6 +20,7 @@
<string name="impersonation">Podszywanie się</string> <string name="impersonation">Podszywanie się</string>
<string name="illegal_behavior">Antyspołeczne zachowanie</string> <string name="illegal_behavior">Antyspołeczne zachowanie</string>
<string name="other">Inne</string> <string name="other">Inne</string>
<string name="harassment">Nękanie</string>
<string name="unknown">Nieznani</string> <string name="unknown">Nieznani</string>
<string name="relay_icon">Ikona transmitera</string> <string name="relay_icon">Ikona transmitera</string>
<string name="unknown_author">Autor nieznany</string> <string name="unknown_author">Autor nieznany</string>