Merge pull request #4281 from nextcloud/file_name_audio_recordings

fix file name of voice recording
This commit is contained in:
Sowjanya Kota 2024-09-27 14:21:39 +02:00 committed by GitHub
commit b0f0ef5c0c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,6 +31,7 @@ class MediaRecorderManager : LifecycleAwareManager {
private const val VOICE_MESSAGE_CHANNELS = 1
private const val FILE_DATE_PATTERN = "yyyy-MM-dd HH-mm-ss"
private const val VOICE_MESSAGE_FILE_SUFFIX = ".mp3"
private const val VOICE_MESSAGE_PREFIX_MAX_LENGTH = 146
}
var currentVoiceRecordFile: String = ""
@ -140,14 +141,19 @@ class MediaRecorderManager : LifecycleAwareManager {
private fun setVoiceRecordFileName(context: Context, currentConversation: ConversationModel) {
val simpleDateFormat = SimpleDateFormat(FILE_DATE_PATTERN)
val date: String = simpleDateFormat.format(Date())
val regex = "[/\\\\:%]".toRegex()
val displayName = currentConversation.displayName.replace(regex, " ")
val validDisplayName = displayName.replace("\\s+".toRegex(), " ")
val fileNameWithoutSuffix = String.format(
var fileNameWithoutSuffix = String.format(
context.resources.getString(R.string.nc_voice_message_filename),
date,
currentConversation.displayName
validDisplayName
)
if (fileNameWithoutSuffix.length > VOICE_MESSAGE_PREFIX_MAX_LENGTH) {
fileNameWithoutSuffix = fileNameWithoutSuffix.substring(0, VOICE_MESSAGE_PREFIX_MAX_LENGTH)
}
val fileName = fileNameWithoutSuffix + VOICE_MESSAGE_FILE_SUFFIX
currentVoiceRecordFile = "${context.cacheDir.absolutePath}/$fileName"
}