Skip to content

Commit

Permalink
Fixed code style
Browse files Browse the repository at this point in the history
  • Loading branch information
borichellow committed Dec 9, 2024
1 parent 0e2dd74 commit c79f7ef
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ data class AudioState(
}
}

@Suppress("MagicNumber")
enum class AudioSpeed(val value: Float, @StringRes val titleRes: Int) {
NORMAL(1f, R.string.audio_speed_1),
FAST(1.5f, R.string.audio_speed_1_5),
Expand All @@ -60,9 +61,9 @@ enum class AudioSpeed(val value: Float, @StringRes val titleRes: Int) {

companion object {
fun fromFloat(speed: Float): AudioSpeed = when {
(speed > 1.6) -> MAX
(speed > 1) -> FAST
else -> NORMAL
(speed < FAST.value) -> NORMAL
(speed < MAX.value) -> FAST
else -> MAX
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AudioWavesMaskHelper @Inject constructor(

private fun List<Int>.averageWavesMask(): List<Double> {
val wavesSize = size
val sectionSize = (wavesSize.toFloat() / 75).roundToInt()
val sectionSize = (wavesSize.toFloat() / WAVES_AMOUNT).roundToInt()

if (wavesSize < WAVES_AMOUNT || sectionSize == 1) return map { it.toDouble() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ class ConversationAudioMessagePlayerProvider

@Synchronized
fun provide(): ConversationAudioMessagePlayer {
val player = player ?: ConversationAudioMessagePlayer(context, audioMediaPlayer, wavesMaskHelper, coreLogic).also { player = it }
val player = player ?: ConversationAudioMessagePlayer(context, audioMediaPlayer, wavesMaskHelper, coreLogic).also {
player = it
}
usageCount++

return player
Expand Down Expand Up @@ -255,16 +257,10 @@ internal constructor(
if (currentAccountResult is CurrentSessionResult.Failure) return@launch

audioMessageStateUpdate.emit(
AudioMediaPlayerStateUpdate.AudioMediaPlayingStateUpdate(
messageId,
AudioMediaPlayingState.Fetching
)
AudioMediaPlayerStateUpdate.AudioMediaPlayingStateUpdate(messageId, AudioMediaPlayingState.Fetching)
)

val assetMessage = coreLogic
.getSessionScope((currentAccountResult as CurrentSessionResult.Success).accountInfo.userId)
.messages
.getAssetMessage(conversationId, messageId)
val assetMessage = getAssetMessage(currentAccountResult, conversationId, messageId)

when (val result = assetMessage.await()) {
is MessageAssetResult.Success -> {
Expand All @@ -278,10 +274,7 @@ internal constructor(
val isFetchedAudioCurrentlyQueuedToPlay = messageId == currentAudioMessageId

if (isFetchedAudioCurrentlyQueuedToPlay) {
audioMediaPlayer.setDataSource(
context,
Uri.parse(result.decodedAssetPath.toString())
)
audioMediaPlayer.setDataSource(context, Uri.parse(result.decodedAssetPath.toString()))
audioMediaPlayer.prepare()

audioMessageStateUpdate.emit(
Expand All @@ -298,27 +291,18 @@ internal constructor(
updateSpeedFlow()

audioMessageStateUpdate.emit(
AudioMediaPlayerStateUpdate.AudioMediaPlayingStateUpdate(
messageId,
AudioMediaPlayingState.Playing
)
AudioMediaPlayerStateUpdate.AudioMediaPlayingStateUpdate(messageId, AudioMediaPlayingState.Playing)
)

audioMessageStateUpdate.emit(
AudioMediaPlayerStateUpdate.TotalTimeUpdate(
messageId,
audioMediaPlayer.duration
)
AudioMediaPlayerStateUpdate.TotalTimeUpdate(messageId, audioMediaPlayer.duration)
)
}
}

is MessageAssetResult.Failure -> {
audioMessageStateUpdate.emit(
AudioMediaPlayerStateUpdate.AudioMediaPlayingStateUpdate(
messageId,
AudioMediaPlayingState.Failed
)
AudioMediaPlayerStateUpdate.AudioMediaPlayingStateUpdate(messageId, AudioMediaPlayingState.Failed)
)
}
}
Expand Down Expand Up @@ -360,6 +344,15 @@ internal constructor(
}
}

private suspend fun getAssetMessage(
currentAccountResult: CurrentSessionResult,
conversationId: ConversationId,
messageId: String
) = coreLogic
.getSessionScope((currentAccountResult as CurrentSessionResult.Success).accountInfo.userId)
.messages
.getAssetMessage(conversationId, messageId)

private suspend fun resumeAudio(messageId: String) {
audioMediaPlayer.start()
updateSpeedFlow()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import androidx.compose.ui.res.stringResource
import androidx.hilt.navigation.compose.hiltViewModel
import com.ramcosta.composedestinations.annotation.RootNavGraph
import com.wire.android.R
import com.wire.android.media.audiomessage.AudioState
import com.wire.android.navigation.NavigationCommand
import com.wire.android.navigation.Navigator
import com.wire.android.navigation.WireDestination
Expand Down Expand Up @@ -79,8 +78,6 @@ import com.wire.android.util.ui.SnackBarMessageHandler
import com.wire.android.util.ui.UIText
import com.wire.android.util.ui.openDownloadFolder
import com.wire.kalium.logic.data.id.ConversationId
import kotlinx.collections.immutable.PersistentMap
import kotlinx.collections.immutable.persistentMapOf
import kotlinx.coroutines.launch

@RootNavGraph
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,8 @@ private fun getPlayOrPauseIcon(audioMediaPlayingState: AudioMediaPlayingState):
else -> R.drawable.ic_play to R.string.content_description_play_audio
}

private fun getDefaultWaveMask(): List<Int> {
val result = mutableListOf<Int>()
for (i in 0..75) {
result.add(1)
}
return result
}
@Suppress("MagicNumber")
private fun getDefaultWaveMask(): List<Int> = List(75) { 1 }

// helper wrapper class to format the time that is left
private data class AudioDuration(val totalDurationInMs: AudioState.TotalTimeInMs, val currentPositionInMs: Int) {
Expand Down

0 comments on commit c79f7ef

Please sign in to comment.