Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Audio message play in background WPB-11725 #3766

Open
wants to merge 3 commits into
base: feat/audio_messages_new_design
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading