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

View File

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

View File

@ -1205,8 +1205,10 @@ class ChatActivity :
}
}
private fun setUpWaveform(message: ChatMessage, thenPlay: Boolean = true,
backgroundPlayAllowed: Boolean = false) {
private fun setUpWaveform(
message: ChatMessage, thenPlay: Boolean = true,
backgroundPlayAllowed: Boolean = false
) {
val filename = message.selectedIndividualHashMap!!["name"]
val file = File(context.cacheDir, filename!!)
if (file.exists() && message.voiceMessageFloatArray == null) {
@ -1615,8 +1617,10 @@ class ChatActivity :
}
}
private fun startPlayback(message: ChatMessage, doPlay: Boolean = true,
backgroundPlayAllowed: Boolean = false) {
private fun startPlayback(
message: ChatMessage, doPlay: Boolean = true,
backgroundPlayAllowed: Boolean = false
) {
if (!active && !backgroundPlayAllowed) {
// 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.
@ -1657,12 +1661,15 @@ class ChatActivity :
curMsg.voiceMessageDuration = try {
val retriever = MediaMetadataRetriever()
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
(durationStr?.toIntOrNull() ?: 0) / 1000 // Convert to int (seconds)
} catch (e: Exception) {
Log.e(TAG, "An exception occurred while computing " +
"voice message duration for " + filename, e)
Log.e(
TAG, "An exception occurred while computing " +
"voice message duration for " + filename, e
)
0
}
adapter?.update(curMsg)
@ -1672,12 +1679,15 @@ class ChatActivity :
curMsg.voiceMessageDuration = try {
val retriever = MediaMetadataRetriever()
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
(durationStr?.toIntOrNull() ?: 0) / 1000 // Convert to int (seconds)
} catch (e: Exception) {
Log.e(TAG, "An exception occurred while computing " +
"voice message duration for " + filename, e)
Log.e(
TAG, "An exception occurred while computing " +
"voice message duration for " + filename, e
)
0
}
adapter?.update(curMsg)
@ -1723,8 +1733,10 @@ class ChatActivity :
adapter?.update(message)
stopMediaPlayer(message)
if (hasConsecutiveVoiceMessage) {
val defaultMediaPlayer = MediaPlayer.create(context, R.raw
.next_voice_message_doodle)
val defaultMediaPlayer = MediaPlayer.create(
context, R.raw
.next_voice_message_doodle
)
defaultMediaPlayer.setOnCompletionListener {
defaultMediaPlayer.release()
setUpWaveform(nextMessage as ChatMessage, doPlay, true)
@ -3724,6 +3736,7 @@ class ChatActivity :
callStarted = true
}
}
ChatMessage.SystemMessageType.CALL_ENDED,
ChatMessage.SystemMessageType.CALL_MISSED,
ChatMessage.SystemMessageType.CALL_TRIED,
@ -3731,6 +3744,7 @@ class ChatActivity :
callStarted = false
messageInputViewModel.showCallStartedIndicator(recent, false)
}
else -> {}
}
}

View File

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