android, desktop: fix presenting large images (#4139)

* android, desktop: fix presenting large images

* 4320 px limitation

* revert line

* onClick

* onClick
This commit is contained in:
Stanislav Dmitrenko
2024-05-09 16:39:49 +07:00
committed by GitHub
parent bc5af35a3e
commit 93a7ddb128
6 changed files with 90 additions and 35 deletions
@@ -9,6 +9,7 @@ import java.io.File
import java.net.URI
import java.net.URLEncoder
import chat.simplex.res.MR
import java.awt.Desktop
actual fun UriHandler.sendEmail(subject: String, body: CharSequence) {
val subjectEncoded = URLEncoder.encode(subject, "UTF-8").replace("+", "%20")
@@ -41,3 +42,30 @@ actual fun shareFile(text: String, fileSource: CryptoFile) {
}.launch(fileSource.filePath)
}
}
actual fun openFile(fileSource: CryptoFile) {
try {
val filePath = filePathForShare(fileSource) ?: return
Desktop.getDesktop().open(File(filePath))
} catch (e: Exception) {
Log.e(TAG, "Unable to open the file: " + e.stackTraceToString())
AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.error), text = e.stackTraceToString())
}
}
fun filePathForShare(fileSource: CryptoFile): String? {
return if (fileSource.cryptoArgs != null) {
val tmpFile = File(tmpDir, fileSource.filePath)
tmpFile.deleteOnExit()
try {
decryptCryptoFile(getAppFilePath(fileSource.filePath), fileSource.cryptoArgs ?: return null, tmpFile.absolutePath)
} catch (e: Exception) {
Log.e(TAG, "Unable to decrypt crypto file: " + e.stackTraceToString())
AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.error), text = e.stackTraceToString())
return null
}
tmpFile.absolutePath
} else {
getAppFilePath(fileSource.filePath)
}
}
@@ -59,20 +59,7 @@ actual fun copyItemToClipboard(cItem: ChatItem, clipboard: ClipboardManager) = w
}
if (fileSource != null) {
val filePath: String = if (fileSource.cryptoArgs != null) {
val tmpFile = File(tmpDir, fileSource.filePath)
tmpFile.deleteOnExit()
try {
decryptCryptoFile(getAppFilePath(fileSource.filePath), fileSource.cryptoArgs ?: return@withLongRunningApi, tmpFile.absolutePath)
} catch (e: Exception) {
Log.e(TAG, "Unable to decrypt crypto file: " + e.stackTraceToString())
AlertManager.shared.showAlertMsg(title = generalGetString(MR.strings.error), text = e.stackTraceToString())
return@withLongRunningApi
}
tmpFile.absolutePath
} else {
getAppFilePath(fileSource.filePath)
}
val filePath = filePathForShare(fileSource) ?: return@withLongRunningApi
when {
desktopPlatform.isWindows() -> clipboard.setText(AnnotatedString("\"${File(filePath).absolutePath}\""))
else -> clipboard.setText(AnnotatedString(filePath))