Append current time to the filename before saving.

This commit is contained in:
Onuray Sahin 2020-08-18 18:54:59 +03:00
parent 550dcde9b8
commit 2b0051887a
2 changed files with 16 additions and 3 deletions

View File

@ -15,6 +15,7 @@ Bugfix 🐛:
- Fix relative date time formatting (#822)
- Fix crash reported by RageShake
- Fix refreshing of sessions list when another session is logged out
- Failed to build unique file (#1954)
Translations 🗣:
- Add PlayStore description resources in the Triple-T format, to let Weblate handle them

View File

@ -310,11 +310,23 @@ fun shareMedia(context: Context, file: File, mediaMimeType: String?) {
}
}
private fun appendTimeToFilename(name: String): String {
val dateExtension = SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault()).format(Date())
if (!name.contains(".")) return name + "_" + dateExtension
val filename = name.substringBeforeLast(".")
val fileExtension = name.substringAfterLast(".")
return """${filename}_${dateExtension}.$fileExtension"""
}
fun saveMedia(context: Context, file: File, title: String, mediaMimeType: String?, notificationUtils: NotificationUtils) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
val filename = appendTimeToFilename(title)
val values = ContentValues().apply {
put(MediaStore.Images.Media.TITLE, title)
put(MediaStore.Images.Media.DISPLAY_NAME, title)
put(MediaStore.Images.Media.TITLE, filename)
put(MediaStore.Images.Media.DISPLAY_NAME, filename)
put(MediaStore.Images.Media.MIME_TYPE, mediaMimeType)
put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis())
put(MediaStore.Images.Media.DATE_TAKEN, System.currentTimeMillis())
@ -340,7 +352,7 @@ fun saveMedia(context: Context, file: File, title: String, mediaMimeType: String
}
notificationUtils.buildDownloadFileNotification(
uri,
title,
filename,
mediaMimeType ?: "application/octet-stream"
).let { notification ->
notificationUtils.showNotificationMessage("DL", uri.hashCode(), notification)