Fix issue with waveform rendering

This commit is contained in:
Benoit Marty 2021-07-13 18:48:59 +02:00
parent df795d1881
commit 0cf10b2f84
2 changed files with 9 additions and 2 deletions

View File

@ -80,7 +80,7 @@ internal class WaveFormSanitizer @Inject constructor() {
positiveList
}
Timber.d("Sanitize from ${waveForm.size} items to ${finalList.size} items")
Timber.d("Sanitize from ${waveForm.size} items to ${finalList.size} items. Max value was $max")
return finalList
}
}

View File

@ -257,7 +257,7 @@ class MessageItemFactory @Inject constructor(
return MessageVoiceItem_()
.attributes(attributes)
.duration(messageContent.audioWaveformInfo?.duration ?: 0)
.waveform(messageContent.audioWaveformInfo?.waveform ?: emptyList())
.waveform(messageContent.audioWaveformInfo?.waveform?.toFft().orEmpty())
.playbackControlButtonClickListener(playbackControlButtonClickListener)
.voiceMessagePlaybackTracker(voiceMessagePlaybackTracker)
.izLocalFile(localFilesHelper.isLocalFile(fileUrl))
@ -622,6 +622,13 @@ class MessageItemFactory @Inject constructor(
.highlighted(highlight)
}
private fun List<Int>?.toFft(): List<Int>? {
return this?.map {
// Value comes from AudioRecordView.maxReportableAmp, and 1024 is the max value in the Matrix spec
it * 22760 / 1024
}
}
companion object {
private const val MAX_NUMBER_OF_EMOJI_FOR_BIG_FONT = 5
}