fix file name of voice recording

Signed-off-by: sowjanyakch <sowjanya.kch@gmail.com>
This commit is contained in:
sowjanyakch 2024-09-26 16:35:08 +02:00
parent f44885bd78
commit ce8c4b2b84
No known key found for this signature in database
GPG key ID: F7AA2A8B65B50220

View file

@ -140,14 +140,19 @@ class MediaRecorderManager : LifecycleAwareManager {
private fun setVoiceRecordFileName(context: Context, currentConversation: ConversationModel) { private fun setVoiceRecordFileName(context: Context, currentConversation: ConversationModel) {
val simpleDateFormat = SimpleDateFormat(FILE_DATE_PATTERN) val simpleDateFormat = SimpleDateFormat(FILE_DATE_PATTERN)
val date: String = simpleDateFormat.format(Date()) 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), context.resources.getString(R.string.nc_voice_message_filename),
date, date,
currentConversation.displayName validDisplayName
) )
if (fileNameWithoutSuffix.length > 146) {
fileNameWithoutSuffix = fileNameWithoutSuffix.substring(0, 146)
}
val fileName = fileNameWithoutSuffix + VOICE_MESSAGE_FILE_SUFFIX val fileName = fileNameWithoutSuffix + VOICE_MESSAGE_FILE_SUFFIX
currentVoiceRecordFile = "${context.cacheDir.absolutePath}/$fileName" currentVoiceRecordFile = "${context.cacheDir.absolutePath}/$fileName"
} }