feat: Simplify tint color handling for icons in FileAttachment component
This commit is contained in:
@@ -1477,38 +1477,42 @@ fun FileAttachment(
|
||||
try {
|
||||
downloadStatus = DownloadStatus.DOWNLOADING
|
||||
|
||||
val encryptedContent = TransportManager.downloadFile(attachment.id, downloadTag)
|
||||
downloadProgress = 0.6f
|
||||
// Streaming: скачиваем во temp file, не в память
|
||||
val tempFile = TransportManager.downloadFileRaw(attachment.id, downloadTag)
|
||||
downloadProgress = 0.5f
|
||||
|
||||
downloadStatus = DownloadStatus.DECRYPTING
|
||||
|
||||
val decryptedKeyAndNonce =
|
||||
MessageCrypto.decryptKeyFromSender(chachaKey, privateKey)
|
||||
downloadProgress = 0.6f
|
||||
|
||||
val decrypted =
|
||||
MessageCrypto.decryptAttachmentBlobWithPlainKey(
|
||||
encryptedContent,
|
||||
decryptedKeyAndNonce
|
||||
// Streaming decrypt: tempFile → AES → inflate → base64 → savedFile
|
||||
// Пиковое потребление памяти ~128KB вместо ~200MB
|
||||
val success = withContext(Dispatchers.IO) {
|
||||
try {
|
||||
MessageCrypto.decryptAttachmentFileStreaming(
|
||||
tempFile,
|
||||
decryptedKeyAndNonce,
|
||||
savedFile
|
||||
)
|
||||
downloadProgress = 0.9f
|
||||
|
||||
if (decrypted != null) {
|
||||
withContext(Dispatchers.IO) {
|
||||
// Декодим base64 в байты (обработка data URL и plain base64)
|
||||
val base64Data = if (decrypted.contains(",")) {
|
||||
decrypted.substringAfter(",")
|
||||
} else {
|
||||
decrypted
|
||||
}
|
||||
val bytes = Base64.decode(base64Data, Base64.DEFAULT)
|
||||
savedFile.writeBytes(bytes)
|
||||
} finally {
|
||||
tempFile.delete()
|
||||
}
|
||||
}
|
||||
downloadProgress = 0.95f
|
||||
|
||||
if (success) {
|
||||
downloadProgress = 1f
|
||||
downloadStatus = DownloadStatus.DOWNLOADED
|
||||
} else {
|
||||
downloadStatus = DownloadStatus.ERROR
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
downloadStatus = DownloadStatus.ERROR
|
||||
} catch (_: OutOfMemoryError) {
|
||||
System.gc()
|
||||
downloadStatus = DownloadStatus.ERROR
|
||||
}
|
||||
}
|
||||
@@ -1707,15 +1711,13 @@ fun FileAttachment(
|
||||
Icon(
|
||||
painter = TelegramIcons.Done,
|
||||
contentDescription = null,
|
||||
tint =
|
||||
if (isDarkTheme) Color.White else Color(0xFF4FC3F7),
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(14.dp)
|
||||
)
|
||||
Icon(
|
||||
painter = TelegramIcons.Done,
|
||||
contentDescription = null,
|
||||
tint =
|
||||
if (isDarkTheme) Color.White else Color(0xFF4FC3F7),
|
||||
tint = Color.White,
|
||||
modifier = Modifier.size(14.dp).offset(x = 4.dp)
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user