Skip to content

Commit

Permalink
Merge pull request #4281 from nextcloud/file_name_audio_recordings
Browse files Browse the repository at this point in the history
fix file name of voice recording
  • Loading branch information
sowjanyakch authored Sep 27, 2024
2 parents f44885b + de582f8 commit b0f0ef5
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ""
Expand Down Expand Up @@ -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"
}

Expand Down

0 comments on commit b0f0ef5

Please sign in to comment.