mirror of
https://github.com/nextcloud/talk-android
synced 2025-02-07 15:13:01 +00:00
Merge pull request #4281 from nextcloud/file_name_audio_recordings
fix file name of voice recording
This commit is contained in:
commit
b0f0ef5c0c
@ -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"
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user