Signed-off-by: Giacomo Pacini <giacomopacini98@gmail.com>
This commit is contained in:
Giacomo Pacini 2024-12-19 14:04:31 +01:00
parent 20a94f0ef3
commit fce785c734
No known key found for this signature in database
GPG Key ID: 2FBC97406B43D889
5 changed files with 60 additions and 36 deletions

View File

@ -155,10 +155,12 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) :
isBound = true isBound = true
} }
private fun showVoiceMessageDuration(message: ChatMessage) { private fun showVoiceMessageDuration(message: ChatMessage) {
if (message.voiceMessageDuration > 0) { if (message.voiceMessageDuration > 0) {
binding.voiceMessageDuration.text = android.text.format.DateUtils.formatElapsedTime( binding.voiceMessageDuration.text = android.text.format.DateUtils.formatElapsedTime(
message.voiceMessageDuration.toLong()) message.voiceMessageDuration.toLong()
)
binding.voiceMessageDuration.visibility = View.VISIBLE binding.voiceMessageDuration.visibility = View.VISIBLE
} else { } else {
binding.voiceMessageDuration.visibility = View.INVISIBLE binding.voiceMessageDuration.visibility = View.INVISIBLE
@ -291,8 +293,10 @@ class IncomingVoiceMessageViewHolder(incomingView: View, payload: Any) :
} }
private fun colorizeMessageBubble(message: ChatMessage) { private fun colorizeMessageBubble(message: ChatMessage) {
viewThemeUtils.talk.themeIncomingMessageBubble(bubble, message.isGrouped, viewThemeUtils.talk.themeIncomingMessageBubble(
message.isDeleted, message.wasPlayedVoiceMessage) bubble, message.isGrouped,
message.isDeleted, message.wasPlayedVoiceMessage
)
} }
@Suppress("Detekt.TooGenericExceptionCaught") @Suppress("Detekt.TooGenericExceptionCaught")

View File

@ -199,7 +199,8 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) :
private fun showVoiceMessageDuration(message: ChatMessage) { private fun showVoiceMessageDuration(message: ChatMessage) {
if (message.voiceMessageDuration > 0) { if (message.voiceMessageDuration > 0) {
binding.voiceMessageDuration.text = android.text.format.DateUtils.formatElapsedTime( binding.voiceMessageDuration.text = android.text.format.DateUtils.formatElapsedTime(
message.voiceMessageDuration.toLong()) message.voiceMessageDuration.toLong()
)
binding.voiceMessageDuration.visibility = View.VISIBLE binding.voiceMessageDuration.visibility = View.VISIBLE
} else { } else {
binding.voiceMessageDuration.visibility = View.INVISIBLE binding.voiceMessageDuration.visibility = View.INVISIBLE
@ -356,8 +357,10 @@ class OutcomingVoiceMessageViewHolder(outcomingView: View) :
} }
private fun colorizeMessageBubble(message: ChatMessage) { private fun colorizeMessageBubble(message: ChatMessage) {
viewThemeUtils.talk.themeOutgoingMessageBubble(bubble, message.isGrouped, viewThemeUtils.talk.themeOutgoingMessageBubble(
message.isDeleted, message.wasPlayedVoiceMessage) bubble, message.isGrouped,
message.isDeleted, message.wasPlayedVoiceMessage
)
} }
fun assignVoiceMessageInterface(voiceMessageInterface: VoiceMessageInterface) { fun assignVoiceMessageInterface(voiceMessageInterface: VoiceMessageInterface) {

View File

@ -1205,8 +1205,10 @@ class ChatActivity :
} }
} }
private fun setUpWaveform(message: ChatMessage, thenPlay: Boolean = true, private fun setUpWaveform(
backgroundPlayAllowed: Boolean = false) { message: ChatMessage, thenPlay: Boolean = true,
backgroundPlayAllowed: Boolean = false
) {
val filename = message.selectedIndividualHashMap!!["name"] val filename = message.selectedIndividualHashMap!!["name"]
val file = File(context.cacheDir, filename!!) val file = File(context.cacheDir, filename!!)
if (file.exists() && message.voiceMessageFloatArray == null) { if (file.exists() && message.voiceMessageFloatArray == null) {
@ -1615,8 +1617,10 @@ class ChatActivity :
} }
} }
private fun startPlayback(message: ChatMessage, doPlay: Boolean = true, private fun startPlayback(
backgroundPlayAllowed: Boolean = false) { message: ChatMessage, doPlay: Boolean = true,
backgroundPlayAllowed: Boolean = false
) {
if (!active && !backgroundPlayAllowed) { if (!active && !backgroundPlayAllowed) {
// don't begin to play voice message if screen is not visible anymore. // don't begin to play voice message if screen is not visible anymore.
// this situation might happen if file is downloading but user already left the chatview. // this situation might happen if file is downloading but user already left the chatview.
@ -1657,12 +1661,15 @@ class ChatActivity :
curMsg.voiceMessageDuration = try { curMsg.voiceMessageDuration = try {
val retriever = MediaMetadataRetriever() val retriever = MediaMetadataRetriever()
retriever.setDataSource(file.absolutePath) // Set the audio file as the data source retriever.setDataSource(file.absolutePath) // Set the audio file as the data source
val durationStr = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION) val durationStr =
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
retriever.release() // Always release the retriever to free resources retriever.release() // Always release the retriever to free resources
(durationStr?.toIntOrNull() ?: 0) / 1000 // Convert to int (seconds) (durationStr?.toIntOrNull() ?: 0) / 1000 // Convert to int (seconds)
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "An exception occurred while computing " + Log.e(
"voice message duration for " + filename, e) TAG, "An exception occurred while computing " +
"voice message duration for " + filename, e
)
0 0
} }
adapter?.update(curMsg) adapter?.update(curMsg)
@ -1672,12 +1679,15 @@ class ChatActivity :
curMsg.voiceMessageDuration = try { curMsg.voiceMessageDuration = try {
val retriever = MediaMetadataRetriever() val retriever = MediaMetadataRetriever()
retriever.setDataSource(file.absolutePath) // Set the audio file as the data source retriever.setDataSource(file.absolutePath) // Set the audio file as the data source
val durationStr = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION) val durationStr =
retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION)
retriever.release() // Always release the retriever to free resources retriever.release() // Always release the retriever to free resources
(durationStr?.toIntOrNull() ?: 0) / 1000 // Convert to int (seconds) (durationStr?.toIntOrNull() ?: 0) / 1000 // Convert to int (seconds)
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "An exception occurred while computing " + Log.e(
"voice message duration for " + filename, e) TAG, "An exception occurred while computing " +
"voice message duration for " + filename, e
)
0 0
} }
adapter?.update(curMsg) adapter?.update(curMsg)
@ -1723,8 +1733,10 @@ class ChatActivity :
adapter?.update(message) adapter?.update(message)
stopMediaPlayer(message) stopMediaPlayer(message)
if (hasConsecutiveVoiceMessage) { if (hasConsecutiveVoiceMessage) {
val defaultMediaPlayer = MediaPlayer.create(context, R.raw val defaultMediaPlayer = MediaPlayer.create(
.next_voice_message_doodle) context, R.raw
.next_voice_message_doodle
)
defaultMediaPlayer.setOnCompletionListener { defaultMediaPlayer.setOnCompletionListener {
defaultMediaPlayer.release() defaultMediaPlayer.release()
setUpWaveform(nextMessage as ChatMessage, doPlay, true) setUpWaveform(nextMessage as ChatMessage, doPlay, true)
@ -3724,6 +3736,7 @@ class ChatActivity :
callStarted = true callStarted = true
} }
} }
ChatMessage.SystemMessageType.CALL_ENDED, ChatMessage.SystemMessageType.CALL_ENDED,
ChatMessage.SystemMessageType.CALL_MISSED, ChatMessage.SystemMessageType.CALL_MISSED,
ChatMessage.SystemMessageType.CALL_TRIED, ChatMessage.SystemMessageType.CALL_TRIED,
@ -3731,6 +3744,7 @@ class ChatActivity :
callStarted = false callStarted = false
messageInputViewModel.showCallStartedIndicator(recent, false) messageInputViewModel.showCallStartedIndicator(recent, false)
} }
else -> {} else -> {}
} }
} }

View File

@ -296,9 +296,11 @@ data class ChatMessage(
activeUser == null -> { activeUser == null -> {
null null
} }
actorType == "users" -> { actorType == "users" -> {
ApiUtils.getUrlForAvatar(activeUser!!.baseUrl!!, actorId, true) ApiUtils.getUrlForAvatar(activeUser!!.baseUrl!!, actorId, true)
} }
actorType == "bridged" -> { actorType == "bridged" -> {
ApiUtils.getUrlForAvatar( ApiUtils.getUrlForAvatar(
activeUser!!.baseUrl!!, activeUser!!.baseUrl!!,
@ -306,6 +308,7 @@ data class ChatMessage(
true true
) )
} }
else -> { else -> {
var apiId: String? = sharedApplication!!.getString(R.string.nc_guest) var apiId: String? = sharedApplication!!.getString(R.string.nc_guest)
if (!TextUtils.isEmpty(actorDisplayName)) { if (!TextUtils.isEmpty(actorDisplayName)) {