fix saving multiple attachments as draft (#2670)

This commit is contained in:
Konrad Pozniak 2022-08-16 20:07:49 +02:00 committed by GitHub
parent 94ae64b52d
commit edbc624625
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -78,11 +78,11 @@ class DraftHelper @Inject constructor(
val uris = mediaUris.map { uriString ->
uriString.toUri()
}.mapNotNull { uri ->
}.mapIndexedNotNull { index, uri ->
if (uri.isInFolder(draftDirectory)) {
uri
} else {
uri.copyToFolder(draftDirectory)
uri.copyToFolder(draftDirectory, index)
}
}
@ -155,7 +155,7 @@ class DraftHelper @Inject constructor(
return File(filePath).parentFile == folder
}
private fun Uri.copyToFolder(folder: File): Uri? {
private fun Uri.copyToFolder(folder: File, index: Int): Uri? {
val contentResolver = context.contentResolver
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(Date())
@ -167,7 +167,7 @@ class DraftHelper @Inject constructor(
map.getExtensionFromMimeType(mimeType)
}
val filename = String.format("Tusky_Draft_Media_%s.%s", timeStamp, fileExtension)
val filename = String.format("Tusky_Draft_Media_%s_%d.%s", timeStamp, index, fileExtension)
val file = File(folder, filename)
if (scheme == "https") {