mirror of
https://github.com/element-hq/element-android
synced 2024-10-23 03:06:33 +03:00
Append current time to the filename before saving.
This commit is contained in:
parent
550dcde9b8
commit
2b0051887a
2 changed files with 16 additions and 3 deletions
|
@ -15,6 +15,7 @@ Bugfix 🐛:
|
||||||
- Fix relative date time formatting (#822)
|
- Fix relative date time formatting (#822)
|
||||||
- Fix crash reported by RageShake
|
- Fix crash reported by RageShake
|
||||||
- Fix refreshing of sessions list when another session is logged out
|
- Fix refreshing of sessions list when another session is logged out
|
||||||
|
- Failed to build unique file (#1954)
|
||||||
|
|
||||||
Translations 🗣:
|
Translations 🗣:
|
||||||
- Add PlayStore description resources in the Triple-T format, to let Weblate handle them
|
- Add PlayStore description resources in the Triple-T format, to let Weblate handle them
|
||||||
|
|
|
@ -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) {
|
fun saveMedia(context: Context, file: File, title: String, mediaMimeType: String?, notificationUtils: NotificationUtils) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||||
|
val filename = appendTimeToFilename(title)
|
||||||
|
|
||||||
val values = ContentValues().apply {
|
val values = ContentValues().apply {
|
||||||
put(MediaStore.Images.Media.TITLE, title)
|
put(MediaStore.Images.Media.TITLE, filename)
|
||||||
put(MediaStore.Images.Media.DISPLAY_NAME, title)
|
put(MediaStore.Images.Media.DISPLAY_NAME, filename)
|
||||||
put(MediaStore.Images.Media.MIME_TYPE, mediaMimeType)
|
put(MediaStore.Images.Media.MIME_TYPE, mediaMimeType)
|
||||||
put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis())
|
put(MediaStore.Images.Media.DATE_ADDED, System.currentTimeMillis())
|
||||||
put(MediaStore.Images.Media.DATE_TAKEN, 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(
|
notificationUtils.buildDownloadFileNotification(
|
||||||
uri,
|
uri,
|
||||||
title,
|
filename,
|
||||||
mediaMimeType ?: "application/octet-stream"
|
mediaMimeType ?: "application/octet-stream"
|
||||||
).let { notification ->
|
).let { notification ->
|
||||||
notificationUtils.showNotificationMessage("DL", uri.hashCode(), notification)
|
notificationUtils.showNotificationMessage("DL", uri.hashCode(), notification)
|
||||||
|
|
Loading…
Reference in a new issue