feat: enhance file opening logic in OtherProfileScreen to support local, downloaded, and blob files
This commit is contained in:
@@ -1402,11 +1402,24 @@ private fun openUriInExternalApp(context: android.content.Context, uri: Uri, mim
|
||||
|
||||
private fun openSharedFile(context: android.content.Context, file: SharedFileItem): Boolean {
|
||||
val mimeType = inferMimeType(file.fileName)
|
||||
|
||||
// 1. Попробовать localUri
|
||||
if (file.localUri.isNotBlank()) {
|
||||
val local = runCatching { Uri.parse(file.localUri) }.getOrNull()
|
||||
if (local != null && openUriInExternalApp(context, local, mimeType)) return true
|
||||
}
|
||||
|
||||
// 2. Проверить rosetta_downloads (файлы скачанные через CDN в чате)
|
||||
val downloadsDir = File(context.filesDir, "rosetta_downloads")
|
||||
val downloadedFile = File(downloadsDir, file.fileName)
|
||||
if (downloadedFile.exists() && downloadedFile.length() > 0) {
|
||||
val uri = runCatching {
|
||||
FileProvider.getUriForFile(context, "${context.packageName}.provider", downloadedFile)
|
||||
}.getOrNull()
|
||||
if (uri != null && openUriInExternalApp(context, uri, mimeType)) return true
|
||||
}
|
||||
|
||||
// 3. Попробовать blob (inline-файлы)
|
||||
val bytes = decodeBlobPayload(file.blob) ?: return false
|
||||
val extension = file.fileName.substringAfterLast('.', "").lowercase(Locale.getDefault())
|
||||
val suffix = if (extension.isBlank()) ".bin" else ".$extension"
|
||||
|
||||
Reference in New Issue
Block a user