Skip to content

Commit

Permalink
feat: Audio message play in background
Browse files Browse the repository at this point in the history
  • Loading branch information
borichellow committed Dec 23, 2024
1 parent 6c29136 commit 4be2efe
Show file tree
Hide file tree
Showing 19 changed files with 634 additions and 351 deletions.
32 changes: 29 additions & 3 deletions app/src/main/kotlin/com/wire/android/mapper/ConversationMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package com.wire.android.mapper

import com.wire.android.media.audiomessage.AudioMediaPlayingState
import com.wire.android.media.audiomessage.PlayingAudioMessage
import com.wire.android.model.ImageAsset.UserAvatarAsset
import com.wire.android.model.NameBasedAvatar
import com.wire.android.model.UserAvatarData
Expand All @@ -25,7 +27,9 @@ import com.wire.android.ui.home.conversationslist.model.BadgeEventType
import com.wire.android.ui.home.conversationslist.model.BlockState
import com.wire.android.ui.home.conversationslist.model.ConversationInfo
import com.wire.android.ui.home.conversationslist.model.ConversationItem
import com.wire.android.ui.home.conversationslist.model.PlayingAudioInConversation
import com.wire.android.ui.home.conversationslist.showLegalHoldIndicator
import com.wire.kalium.logic.data.conversation.ConversationDetails
import com.wire.kalium.logic.data.conversation.ConversationDetails.Connection
import com.wire.kalium.logic.data.conversation.ConversationDetails.Group
import com.wire.kalium.logic.data.conversation.ConversationDetails.OneOne
Expand All @@ -42,7 +46,8 @@ import com.wire.kalium.logic.data.user.UserAvailabilityStatus
fun ConversationDetailsWithEvents.toConversationItem(
userTypeMapper: UserTypeMapper,
searchQuery: String,
selfUserTeamId: TeamId?
selfUserTeamId: TeamId?,
playingAudioMessage: PlayingAudioMessage
): ConversationItem = when (val conversationDetails = this.conversationDetails) {
is Group -> {
ConversationItem.GroupConversation(
Expand All @@ -65,7 +70,8 @@ fun ConversationDetailsWithEvents.toConversationItem(
proteusVerificationStatus = conversationDetails.conversation.proteusVerificationStatus,
hasNewActivitiesToShow = hasNewActivitiesToShow,
searchQuery = searchQuery,
isFavorite = conversationDetails.isFavorite
isFavorite = conversationDetails.isFavorite,
playingAudio = getPlayingAudioInConversation(playingAudioMessage, conversationDetails)
)
}

Expand Down Expand Up @@ -103,7 +109,8 @@ fun ConversationDetailsWithEvents.toConversationItem(
proteusVerificationStatus = conversationDetails.conversation.proteusVerificationStatus,
hasNewActivitiesToShow = hasNewActivitiesToShow,
searchQuery = searchQuery,
isFavorite = conversationDetails.isFavorite
isFavorite = conversationDetails.isFavorite,
playingAudio = getPlayingAudioInConversation(playingAudioMessage, conversationDetails)
)
}

Expand Down Expand Up @@ -140,6 +147,25 @@ fun ConversationDetailsWithEvents.toConversationItem(
}
}

private fun getPlayingAudioInConversation(
playingAudioMessage: PlayingAudioMessage,
conversationDetails: ConversationDetails
): PlayingAudioInConversation? =
if (playingAudioMessage is PlayingAudioMessage.Some
&& playingAudioMessage.conversationId == conversationDetails.conversation.id
) {
if (playingAudioMessage.state.isPlaying()) {
PlayingAudioInConversation(playingAudioMessage.messageId, false)
} else if (playingAudioMessage.state.audioMediaPlayingState is AudioMediaPlayingState.Paused) {
PlayingAudioInConversation(playingAudioMessage.messageId, true)
} else {
// states Fetching, Completed, Stopped, etc. should not be shown in ConversationItem
null
}
} else {
null
}

private fun parseConnectionEventType(connectionState: ConnectionState) =
if (connectionState == ConnectionState.SENT) {
BadgeEventType.SentConnectRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ package com.wire.android.media.audiomessage

import androidx.annotation.StringRes
import com.wire.android.R
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.data.id.ConversationId

data class AudioState(
val audioMediaPlayingState: AudioMediaPlayingState,
Expand All @@ -40,13 +42,27 @@ data class AudioState(
return totalTimeInMs
}

fun isPlaying() = audioMediaPlayingState is AudioMediaPlayingState.Playing
fun isPlayingOrPaused() = audioMediaPlayingState is AudioMediaPlayingState.Playing
|| audioMediaPlayingState is AudioMediaPlayingState.Paused

sealed class TotalTimeInMs {
object NotKnown : TotalTimeInMs()

data class Known(val value: Int) : TotalTimeInMs()
}
}

sealed class PlayingAudioMessage {
data object None : PlayingAudioMessage()
data class Some(
val conversationId: ConversationId,
val messageId: String,
val authorName: UIText,
val state: AudioState
) : PlayingAudioMessage()
}

@Suppress("MagicNumber")
enum class AudioSpeed(val value: Float, @StringRes val titleRes: Int) {
NORMAL(1f, R.string.audio_speed_1),
Expand Down Expand Up @@ -84,27 +100,32 @@ sealed class AudioMediaPlayingState {
}

sealed class AudioMediaPlayerStateUpdate(
open val conversationId: ConversationId,
open val messageId: String
) {
data class AudioMediaPlayingStateUpdate(
override val conversationId: ConversationId,
override val messageId: String,
val audioMediaPlayingState: AudioMediaPlayingState
) : AudioMediaPlayerStateUpdate(messageId)
) : AudioMediaPlayerStateUpdate(conversationId, messageId)

data class PositionChangeUpdate(
override val conversationId: ConversationId,
override val messageId: String,
val position: Int
) : AudioMediaPlayerStateUpdate(messageId)
) : AudioMediaPlayerStateUpdate(conversationId, messageId)

data class TotalTimeUpdate(
override val conversationId: ConversationId,
override val messageId: String,
val totalTimeInMs: Int
) : AudioMediaPlayerStateUpdate(messageId)
) : AudioMediaPlayerStateUpdate(conversationId, messageId)

data class WaveMaskUpdate(
override val conversationId: ConversationId,
override val messageId: String,
val waveMask: List<Int>
) : AudioMediaPlayerStateUpdate(messageId)
) : AudioMediaPlayerStateUpdate(conversationId, messageId)
}

sealed class RecordAudioMediaPlayerStateUpdate {
Expand Down
Loading

0 comments on commit 4be2efe

Please sign in to comment.