Commit 7b9aa89d authored by moezbhatti's avatar moezbhatti

Allow saving multiple attachments with same name

Closes #1518
parent 76c89dfe
......@@ -146,7 +146,12 @@ class MessageRepositoryImpl @Inject constructor(
val dir = File(Environment.getExternalStorageDirectory(), "QKSMS/Media").apply { mkdirs() }
val fileName = part.name?.takeIf { name -> name.endsWith(extension) }
?: "${part.type.split("/").last()}_$date.$extension"
val file = File(dir, fileName)
var file: File
var index = 0
do {
file = File(dir, if (index == 0) fileName else fileName.replace(".$extension", " ($index).$extension"))
index++
} while (file.exists())
try {
FileOutputStream(file).use { outputStream ->
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment