Code cleanup

This commit is contained in:
ericdecanini 2022-03-21 19:57:18 +01:00
parent 5a819bbafa
commit c9946b6dd3
5 changed files with 28 additions and 31 deletions

View File

@ -155,8 +155,8 @@ import im.vector.app.features.home.room.detail.timeline.action.EventSharedAction
import im.vector.app.features.home.room.detail.timeline.action.MessageActionsBottomSheet
import im.vector.app.features.home.room.detail.timeline.action.MessageSharedActionViewModel
import im.vector.app.features.home.room.detail.timeline.edithistory.ViewEditHistoryBottomSheet
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
import im.vector.app.features.home.room.detail.timeline.helper.AudioMessagePlaybackTracker
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
import im.vector.app.features.home.room.detail.timeline.image.buildImageContentRendererData
import im.vector.app.features.home.room.detail.timeline.item.AbsMessageItem
import im.vector.app.features.home.room.detail.timeline.item.MessageFileItem
@ -164,6 +164,7 @@ import im.vector.app.features.home.room.detail.timeline.item.MessageImageVideoIt
import im.vector.app.features.home.room.detail.timeline.item.MessageInformationData
import im.vector.app.features.home.room.detail.timeline.item.MessageTextItem
import im.vector.app.features.home.room.detail.timeline.item.MessageAudioItem
import im.vector.app.features.home.room.detail.timeline.item.MessageVoiceItem
import im.vector.app.features.home.room.detail.timeline.item.ReadReceiptData
import im.vector.app.features.home.room.detail.timeline.reactions.ViewReactionsBottomSheet
import im.vector.app.features.home.room.detail.timeline.url.PreviewUrlRetriever
@ -1178,20 +1179,10 @@ class TimelineFragment @Inject constructor(
}
val messageContent: MessageContent? = event.getLastMessageContent()
val nonFormattedBody = when {
messageContent is MessageAudioContent -> {
getAudioContentBodyText(messageContent)
}
messageContent is MessageAudioContent && messageContent.voiceMessageIndicator != null -> {
val formattedDuration = DateUtils.formatElapsedTime(((messageContent.audioInfo?.duration ?: 0) / 1000).toLong())
getString(R.string.voice_message_reply_content, formattedDuration)
}
messageContent is MessagePollContent -> {
messageContent.getBestPollCreationInfo()?.question?.getBestQuestion()
}
else -> {
messageContent?.body ?: ""
}
val nonFormattedBody = when (messageContent) {
is MessageAudioContent -> getAudioContentBodyText(messageContent)
is MessagePollContent -> messageContent.getBestPollCreationInfo()?.question?.getBestQuestion()
else -> messageContent?.body ?: ""
}
var formattedBody: CharSequence? = null
if (messageContent is MessageTextContent && messageContent.format == MessageFormat.FORMAT_MATRIX_HTML) {
@ -1232,10 +1223,11 @@ class TimelineFragment @Inject constructor(
private fun getAudioContentBodyText(messageContent: MessageAudioContent): String {
val formattedDuration = DateUtils.formatElapsedTime(((messageContent.audioInfo?.duration ?: 0) / 1000).toLong())
return if (messageContent.voiceMessageIndicator != null)
return if (messageContent.voiceMessageIndicator != null) {
getString(R.string.voice_message_reply_content, formattedDuration)
else
} else {
getString(R.string.audio_message_reply_content, messageContent.body, formattedDuration)
}
}
override fun onResume() {
@ -1391,6 +1383,7 @@ class TimelineFragment @Inject constructor(
return when (model) {
is MessageFileItem,
is MessageAudioItem,
is MessageVoiceItem,
is MessageImageVideoItem,
is MessageTextItem -> {
return (model as AbsMessageItem).attributes.informationData.sendState == SendState.SYNCED

View File

@ -34,6 +34,7 @@ import im.vector.app.core.resources.StringProvider
import im.vector.app.core.utils.DimensionConverter
import im.vector.app.core.utils.containsOnlyEmojis
import im.vector.app.features.home.room.detail.timeline.TimelineEventController
import im.vector.app.features.home.room.detail.timeline.helper.AudioMessagePlaybackTracker
import im.vector.app.features.home.room.detail.timeline.helper.AvatarSizeProvider
import im.vector.app.features.home.room.detail.timeline.helper.ContentDownloadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder
@ -41,7 +42,6 @@ import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvid
import im.vector.app.features.home.room.detail.timeline.helper.MessageInformationDataFactory
import im.vector.app.features.home.room.detail.timeline.helper.MessageItemAttributesFactory
import im.vector.app.features.home.room.detail.timeline.helper.TimelineMediaSizeProvider
import im.vector.app.features.home.room.detail.timeline.helper.AudioMessagePlaybackTracker
import im.vector.app.features.home.room.detail.timeline.item.AbsMessageItem
import im.vector.app.features.home.room.detail.timeline.item.MessageAudioItem
import im.vector.app.features.home.room.detail.timeline.item.MessageAudioItem_
@ -189,13 +189,7 @@ class MessageItemFactory @Inject constructor(
is MessageNoticeContent -> buildNoticeMessageItem(messageContent, informationData, highlight, callback, attributes)
is MessageVideoContent -> buildVideoMessageItem(messageContent, informationData, highlight, callback, attributes)
is MessageFileContent -> buildFileMessageItem(messageContent, highlight, attributes)
is MessageAudioContent -> {
if (messageContent.voiceMessageIndicator != null) {
buildVoiceMessageItem(params, messageContent, informationData, highlight, attributes)
} else {
buildAudioMessageItem(params, messageContent, informationData, highlight, attributes)
}
}
is MessageAudioContent -> buildAudioContent(params, messageContent, informationData, highlight, attributes)
is MessageVerificationRequestContent -> buildVerificationRequestMessageItem(messageContent, informationData, highlight, callback, attributes)
is MessagePollContent -> buildPollItem(messageContent, informationData, highlight, callback, attributes)
is MessageLocationContent -> {
@ -435,6 +429,17 @@ class MessageItemFactory @Inject constructor(
.iconRes(R.drawable.ic_paperclip)
}
private fun buildAudioContent(params: TimelineItemFactoryParams,
messageContent: MessageAudioContent,
informationData: MessageInformationData,
highlight: Boolean,
attributes: AbsMessageItem.Attributes) =
if (messageContent.voiceMessageIndicator != null) {
buildVoiceMessageItem(params, messageContent, informationData, highlight, attributes)
} else {
buildAudioMessageItem(params, messageContent, informationData, highlight, attributes)
}
private fun buildNotHandledMessageItem(messageContent: MessageContent,
informationData: MessageInformationData,
highlight: Boolean,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 New Vector Ltd
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -82,11 +82,11 @@ abstract class MessageAudioItem : AbsMessageItem<MessageAudioItem.Holder>() {
}
private fun applyLayoutTint(holder: Holder) {
val backgroundTint = if (attributes.informationData.messageLayout is TimelineMessageLayout.Bubble)
val backgroundTint = if (attributes.informationData.messageLayout is TimelineMessageLayout.Bubble) {
Color.TRANSPARENT
else
} else {
ThemeUtils.getColor(holder.view.context, R.attr.vctr_content_quinary)
}
holder.mainLayout.backgroundTintList = ColorStateList.valueOf(backgroundTint)
}

View File

@ -29,9 +29,9 @@ import com.airbnb.epoxy.EpoxyModelClass
import com.visualizer.amplitude.AudioRecordView
import im.vector.app.R
import im.vector.app.core.epoxy.ClickListener
import im.vector.app.features.home.room.detail.timeline.helper.AudioMessagePlaybackTracker
import im.vector.app.features.home.room.detail.timeline.helper.ContentDownloadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.helper.ContentUploadStateTrackerBinder
import im.vector.app.features.home.room.detail.timeline.helper.AudioMessagePlaybackTracker
import im.vector.app.features.home.room.detail.timeline.style.TimelineMessageLayout
import im.vector.app.features.themes.ThemeUtils

View File

@ -2861,7 +2861,6 @@
<string name="a11y_play_audio_message">Play Audio Message</string>
<string name="a11y_pause_audio_message">Pause Audio Message</string>
<string name="error_audio_message_unable_to_play">Pause Audio Message</string>
<string name="error_audio_message_cannot_reply_or_edit">Cannot reply or edit while audio message is active</string>
<string name="audio_message_reply_content">%1$s (%2$s)</string>
<string name="upgrade_room_for_restricted">Anyone in %s will be able to find and join this room - no need to manually invite everyone. Youll be able to change this in room settings anytime.</string>