Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop' into fix/r…
Browse files Browse the repository at this point in the history
…esolve-custom-colors

# Conflicts:
#	app/src/main/kotlin/com/wire/android/ui/home/conversations/details/GroupConversationDetailsScreen.kt
#	app/src/main/kotlin/com/wire/android/ui/userprofile/self/CreateTeamInfoCard.kt
  • Loading branch information
saleniuk committed Nov 26, 2024
2 parents 5e0b11c + 29830bd commit a577c4a
Show file tree
Hide file tree
Showing 43 changed files with 553 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish-test-results.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: actions/checkout@v4

- name: Download and Extract Artifacts
uses: dawidd6/action-download-artifact@v4
uses: dawidd6/action-download-artifact@v6
with:
run_id: ${{ github.event.workflow_run.id }}
path: artifacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,14 @@ class ConversationModule {
@Provides
fun provideGetFavoriteFolderUseCase(conversationScope: ConversationScope) =
conversationScope.getFavoriteFolder

@ViewModelScoped
@Provides
fun provideAddConversationToFavoritesUseCase(conversationScope: ConversationScope) =
conversationScope.addConversationToFavorites

@ViewModelScoped
@Provides
fun provideRemoveConversationFromFavoritesUseCase(conversationScope: ConversationScope) =
conversationScope.removeConversationFromFavorites
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ fun ConversationDetailsWithEvents.toConversationItem(
proteusVerificationStatus = conversationDetails.conversation.proteusVerificationStatus,
hasNewActivitiesToShow = hasNewActivitiesToShow,
searchQuery = searchQuery,
isFavorite = conversationDetails.isFavorite
)
}

Expand Down Expand Up @@ -101,6 +102,7 @@ fun ConversationDetailsWithEvents.toConversationItem(
proteusVerificationStatus = conversationDetails.conversation.proteusVerificationStatus,
hasNewActivitiesToShow = hasNewActivitiesToShow,
searchQuery = searchQuery,
isFavorite = conversationDetails.isFavorite
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import android.content.Context
import android.media.MediaPlayer
import android.media.MediaPlayer.SEEK_CLOSEST_SYNC
import android.net.Uri
import com.wire.android.di.KaliumCoreLogic
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.feature.asset.GetMessageAssetUseCase
import com.wire.kalium.logic.feature.asset.MessageAssetResult
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.delay
Expand All @@ -34,14 +36,44 @@ import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.merge
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton

class ConversationAudioMessagePlayer
@Singleton
class ConversationAudioMessagePlayerProvider
@Inject constructor(
private val context: Context,
private val audioMediaPlayer: MediaPlayer,
private val getMessageAsset: GetMessageAssetUseCase
@KaliumCoreLogic private val coreLogic: CoreLogic,
) {
private var player: ConversationAudioMessagePlayer? = null
private var usageCount: Int = 0

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

return player
}

@Synchronized
fun onCleared() {
usageCount--
if (usageCount <= 0) {
player?.close()
player = null
}
}
}

class ConversationAudioMessagePlayer
internal constructor(
private val context: Context,
private val audioMediaPlayer: MediaPlayer,
@KaliumCoreLogic private val coreLogic: CoreLogic,
) {
private companion object {
const val UPDATE_POSITION_INTERVAL_IN_MS = 1000L
Expand Down Expand Up @@ -137,7 +169,7 @@ class ConversationAudioMessagePlayer
}

audioMessageStateHistory
}
}.onStart { emit(audioMessageStateHistory) }

private var currentAudioMessageId: String? = null

Expand Down Expand Up @@ -169,10 +201,10 @@ class ConversationAudioMessagePlayer
}

private suspend fun stopCurrentlyPlayingAudioMessage() {
if (currentAudioMessageId != null) {
val currentAudioState = audioMessageStateHistory[currentAudioMessageId]
currentAudioMessageId?.let {
val currentAudioState = audioMessageStateHistory[it]
if (currentAudioState?.audioMediaPlayingState != AudioMediaPlayingState.Fetching) {
stop(currentAudioMessageId!!)
stop(it)
}
}
}
Expand All @@ -194,14 +226,22 @@ class ConversationAudioMessagePlayer

coroutineScope {
launch {
val currentAccountResult = coreLogic.getGlobalScope().session.currentSession()
if (currentAccountResult is CurrentSessionResult.Failure) return@launch

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

when (val result = getMessageAsset(conversationId, messageId).await()) {
val assetMessage = coreLogic
.getSessionScope((currentAccountResult as CurrentSessionResult.Success).accountInfo.userId)
.messages
.getAssetMessage(conversationId, messageId)

when (val result = assetMessage.await()) {
is MessageAssetResult.Success -> {
audioMessageStateUpdate.emit(
AudioMediaPlayerStateUpdate.AudioMediaPlayingStateUpdate(
Expand All @@ -219,9 +259,7 @@ class ConversationAudioMessagePlayer
)
audioMediaPlayer.prepare()

if (position != null) {
audioMediaPlayer.seekTo(position)
}
if (position != null) audioMediaPlayer.seekTo(position)

audioMediaPlayer.start()

Expand Down Expand Up @@ -292,7 +330,7 @@ class ConversationAudioMessagePlayer
)
}

fun close() {
audioMediaPlayer.release()
internal fun close() {
audioMediaPlayer.reset()
}
}
7 changes: 7 additions & 0 deletions app/src/main/kotlin/com/wire/android/model/SnackBarMessage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,10 @@ interface SnackBarMessage {
val uiText: UIText
val actionLabel: UIText? get() = null
}

data class DefaultSnackBarMessage(
override val uiText: UIText,
override val actionLabel: UIText? = null
) : SnackBarMessage

fun UIText.asSnackBarMessage(actionLabel: UIText? = null): SnackBarMessage = DefaultSnackBarMessage(this, actionLabel)
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import com.wire.kalium.logic.data.user.UserId
fun ConversationSheetContent(
conversationSheetState: ConversationSheetState,
onMutingConversationStatusChange: () -> Unit,
addConversationToFavourites: () -> Unit,
changeFavoriteState: (GroupDialogState, addToFavorite: Boolean) -> Unit,
moveConversationToFolder: () -> Unit,
updateConversationArchiveStatus: (DialogState) -> Unit,
clearConversationContent: (DialogState) -> Unit,
Expand All @@ -54,9 +54,8 @@ fun ConversationSheetContent(
ConversationOptionNavigation.Home -> {
ConversationMainSheetContent(
conversationSheetContent = conversationSheetState.conversationSheetContent!!,
changeFavoriteState = changeFavoriteState,
// TODO(profile): enable when implemented
//
// addConversationToFavourites = addConversationToFavourites,
// moveConversationToFolder = moveConversationToFolder,
updateConversationArchiveStatus = updateConversationArchiveStatus,
clearConversationContent = clearConversationContent,
Expand Down Expand Up @@ -125,6 +124,7 @@ data class ConversationSheetContent(
val mlsVerificationStatus: Conversation.VerificationStatus,
val proteusVerificationStatus: Conversation.VerificationStatus,
val isUnderLegalHold: Boolean,
val isFavorite: Boolean?
) {

private val isSelfUserMember: Boolean get() = selfRole != null
Expand All @@ -147,9 +147,9 @@ data class ConversationSheetContent(
fun canUnblockUser(): Boolean =
conversationTypeDetail is ConversationTypeDetail.Private && conversationTypeDetail.blockingState == BlockingState.BLOCKED

fun canAddToFavourite(): Boolean =
(conversationTypeDetail is ConversationTypeDetail.Private && conversationTypeDetail.blockingState != BlockingState.BLOCKED)
|| conversationTypeDetail is ConversationTypeDetail.Group
fun canAddToFavourite(): Boolean = isFavorite != null &&
((conversationTypeDetail is ConversationTypeDetail.Private && conversationTypeDetail.blockingState != BlockingState.BLOCKED)
|| conversationTypeDetail is ConversationTypeDetail.Group)

fun isAbandonedOneOnOneConversation(participantsCount: Int): Boolean = title.isEmpty() && participantsCount == 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ fun rememberConversationSheetState(
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.VERIFIED,
isUnderLegalHold = showLegalHoldIndicator
isUnderLegalHold = showLegalHoldIndicator,
isFavorite = isFavorite
)
}
}
Expand All @@ -102,7 +103,8 @@ fun rememberConversationSheetState(
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.VERIFIED,
isUnderLegalHold = showLegalHoldIndicator
isUnderLegalHold = showLegalHoldIndicator,
isFavorite = isFavorite
)
}
}
Expand All @@ -122,7 +124,8 @@ fun rememberConversationSheetState(
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.VERIFIED,
isUnderLegalHold = showLegalHoldIndicator
isUnderLegalHold = showLegalHoldIndicator,
isFavorite = null
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,14 @@ import com.wire.android.ui.theme.wireTypography
import com.wire.kalium.logic.data.conversation.MutedConversationStatus
import com.wire.kalium.logic.data.user.ConnectionState

// items cannot be simplified
@Suppress("CyclomaticComplexMethod")
@Composable
internal fun ConversationMainSheetContent(
conversationSheetContent: ConversationSheetContent,
// TODO(profile): enable when implemented
// addConversationToFavourites: () -> Unit,
// moveConversationToFolder: () -> Unit,
changeFavoriteState: (dialogState: GroupDialogState, addToFavorite: Boolean) -> Unit,
// TODO(profile): enable when implemented
// moveConversationToFolder: () -> Unit,
updateConversationArchiveStatus: (DialogState) -> Unit,
clearConversationContent: (DialogState) -> Unit,
blockUserClick: (BlockUserDialogState) -> Unit,
Expand Down Expand Up @@ -108,21 +110,38 @@ internal fun ConversationMainSheetContent(
)
}
}

if (conversationSheetContent.canAddToFavourite() && !conversationSheetContent.isArchived) {
conversationSheetContent.isFavorite?.let { isFavorite ->
add {
MenuBottomSheetItem(
title = stringResource(
if (isFavorite) {
R.string.label_remove_from_favourites
} else {
R.string.label_add_to_favourites
}
),
leading = {
MenuItemIcon(
id = R.drawable.ic_favourite,
contentDescription = null
)
},
onItemClick = {
changeFavoriteState(
GroupDialogState(
conversationSheetContent.conversationId,
conversationSheetContent.title
),
!isFavorite
)
}
)
}
}
}
// TODO(profile): enable when implemented
//
// if (conversationSheetContent.canAddToFavourite())
// add {
// MenuBottomSheetItem(
// title = stringResource(R.string.label_add_to_favourites),
// icon = {
// MenuItemIcon(
// id = R.drawable.ic_favourite,
// contentDescription = stringResource(R.string.content_description_add_to_favourite),
// )
// },
// onItemClick = addConversationToFavourites
// )
// }
// add {
// MenuBottomSheetItem(
// icon = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Wire
* Copyright (C) 2024 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.ui.common.bottomsheet.folder

import com.wire.android.di.ScopedArgs
import kotlinx.serialization.Serializable

@Serializable
object ChangeConversationFavoriteStateArgs : ScopedArgs {
override val key = "ConnectionActionButtonArgsKey"
}
Loading

0 comments on commit a577c4a

Please sign in to comment.