-
Notifications
You must be signed in to change notification settings - Fork 31
fix media extension #1925
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix media extension #1925
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -307,7 +307,22 @@ private fun mediaPresenter( | |||||||||||||||||||||||||||
| scope.launch { | ||||||||||||||||||||||||||||
| context.imageLoader.diskCache?.openSnapshot(uri)?.use { | ||||||||||||||||||||||||||||
| val byteArray = it.data.toFile().readBytes() | ||||||||||||||||||||||||||||
| val fileName = uri.substringAfterLast("/") | ||||||||||||||||||||||||||||
| var fileName = uri.substringBefore("?").substringBefore("#").substringAfterLast("/") | ||||||||||||||||||||||||||||
| val lastAt = fileName.lastIndexOf('@') | ||||||||||||||||||||||||||||
| val lastDot = fileName.lastIndexOf('.') | ||||||||||||||||||||||||||||
| if (lastAt > lastDot && lastAt < fileName.length - 1) { | ||||||||||||||||||||||||||||
| fileName = fileName.substring(0, lastAt) + "." + fileName.substring(lastAt + 1) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| if (fileName.isEmpty()) { | ||||||||||||||||||||||||||||
| fileName = "image" | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| if (!fileName.contains(".")) { | ||||||||||||||||||||||||||||
| val extension = | ||||||||||||||||||||||||||||
| android.webkit.MimeTypeMap | ||||||||||||||||||||||||||||
| .getSingleton() | ||||||||||||||||||||||||||||
| .getExtensionFromMimeType(getMimeType(byteArray)) ?: "jpg" | ||||||||||||||||||||||||||||
| fileName = "$fileName.$extension" | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| saveByteArrayToDownloads(context, byteArray, fileName) | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| withContext(Dispatchers.Main) { | ||||||||||||||||||||||||||||
|
Comment on lines
+324
to
328
|
||||||||||||||||||||||||||||
|
|
@@ -325,10 +340,28 @@ private fun mediaPresenter( | |||||||||||||||||||||||||||
| scope.launch { | ||||||||||||||||||||||||||||
| context.imageLoader.diskCache?.openSnapshot(uri)?.use { | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
| context.imageLoader.diskCache?.openSnapshot(uri)?.use { | |
| val snapshot = | |
| context.imageLoader.diskCache?.openSnapshot(uri) | |
| ?: run { | |
| Toast.makeText( | |
| context, | |
| "Unable to share image. Please try again after it has finished loading.", | |
| Toast.LENGTH_SHORT, | |
| ).show() | |
| return@launch | |
| } | |
| snapshot.use { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The filename normalization logic (strip query/fragment, convert Bluesky
@jpegsuffix, add fallback extension) is duplicated in bothsave()andshare(). Please extract this into a small helper (e.g.,fun normalizeFileNameFromUri(uri, fallbackBaseName, mimeType?)) so the two paths can’t drift and future fixes only need to be made once.