Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/develop' into feat/…
Browse files Browse the repository at this point in the history
…add-query-profiling-and-cached-conv-list

# Conflicts:
#	kalium
  • Loading branch information
saleniuk committed Dec 10, 2024
2 parents cdeccfd + e6d8091 commit 5b38cbd
Show file tree
Hide file tree
Showing 33 changed files with 1,057 additions and 252 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,9 @@ class ConversationModule {
@Provides
fun provideRemoveConversationFromFavoritesUseCase(conversationScope: ConversationScope) =
conversationScope.removeConversationFromFavorites

@ViewModelScoped
@Provides
fun provideObserveUserFoldersUseCase(conversationScope: ConversationScope) =
conversationScope.observeUserFolders
}
27 changes: 27 additions & 0 deletions app/src/main/kotlin/com/wire/android/navigation/FolderNavArgs.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.navigation

import android.os.Parcelable
import kotlinx.parcelize.Parcelize

@Parcelize
data class FolderNavArgs(
val folderId: String,
val folderName: String
) : Parcelable
70 changes: 45 additions & 25 deletions app/src/main/kotlin/com/wire/android/navigation/HomeDestination.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,88 +19,109 @@
package com.wire.android.navigation

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import androidx.navigation.NavBackStackEntry
import com.ramcosta.composedestinations.spec.Direction
import com.wire.android.R
import com.wire.android.ui.destinations.AllConversationsScreenDestination
import com.wire.android.ui.destinations.ArchiveScreenDestination
import com.wire.android.ui.destinations.FavoritesConversationsScreenDestination
import com.wire.android.ui.destinations.FolderConversationsScreenDestination
import com.wire.android.ui.destinations.GroupConversationsScreenDestination
import com.wire.android.ui.destinations.OneOnOneConversationsScreenDestination
import com.wire.android.ui.destinations.SettingsScreenDestination
import com.wire.android.ui.destinations.VaultScreenDestination
import com.wire.android.ui.destinations.WhatsNewScreenDestination
import com.wire.android.util.ui.UIText
import com.wire.kalium.logic.data.conversation.ConversationFilter
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf

@Suppress("LongParameterList")
sealed class HomeDestination(
@StringRes val title: Int,
val title: UIText,
@DrawableRes val icon: Int,
val isSearchable: Boolean = false,
val withNewConversationFab: Boolean = false,
val withUserAvatar: Boolean = true,
val direction: Direction
) {

internal fun NavBackStackEntry.baseRouteMatches(): Boolean = direction.route.getBaseRoute() == destination.route?.getBaseRoute()
open fun entryMatches(entry: NavBackStackEntry): Boolean = entry.baseRouteMatches()

data object Conversations : HomeDestination(
title = R.string.conversations_screen_title,
title = UIText.StringResource(R.string.conversations_screen_title),
icon = R.drawable.ic_conversation,
isSearchable = true,
withNewConversationFab = true,
direction = AllConversationsScreenDestination
)

data object Favorites : HomeDestination(
title = R.string.label_filter_favorites,
title = UIText.StringResource(R.string.label_filter_favorites),
icon = R.drawable.ic_conversation,
isSearchable = true,
withNewConversationFab = true,
direction = FavoritesConversationsScreenDestination
)

data class Folder(
val folderNavArgs: FolderNavArgs
) : HomeDestination(
title = UIText.DynamicString(folderNavArgs.folderName),
icon = R.drawable.ic_conversation,
isSearchable = true,
withNewConversationFab = true,
direction = FolderConversationsScreenDestination(folderNavArgs)
) {
override fun entryMatches(entry: NavBackStackEntry): Boolean =
entry.baseRouteMatches() && FolderConversationsScreenDestination.argsFrom(entry).folderId == folderNavArgs.folderId
}

data object Group : HomeDestination(
title = R.string.label_filter_group,
title = UIText.StringResource(R.string.label_filter_group),
icon = R.drawable.ic_conversation,
isSearchable = true,
withNewConversationFab = true,
direction = GroupConversationsScreenDestination
)

data object OneOnOne : HomeDestination(
title = R.string.label_filter_one_on_one,
title = UIText.StringResource(R.string.label_filter_one_on_one),
icon = R.drawable.ic_conversation,
isSearchable = true,
withNewConversationFab = true,
direction = OneOnOneConversationsScreenDestination
)

data object Settings : HomeDestination(
title = R.string.settings_screen_title,
title = UIText.StringResource(R.string.settings_screen_title),
icon = R.drawable.ic_settings,
withUserAvatar = false,
direction = SettingsScreenDestination
)

data object Vault : HomeDestination(
title = R.string.vault_screen_title,
title = UIText.StringResource(R.string.vault_screen_title),
icon = R.drawable.ic_vault,
direction = VaultScreenDestination
)

data object Archive : HomeDestination(
title = R.string.archive_screen_title,
title = UIText.StringResource(R.string.archive_screen_title),
icon = R.drawable.ic_archive,
isSearchable = true,
direction = ArchiveScreenDestination
)

data object Support : HomeDestination(
title = R.string.support_screen_title,
title = UIText.StringResource(R.string.support_screen_title),
icon = R.drawable.ic_support,
direction = SupportScreenDestination
)

data object WhatsNew : HomeDestination(
title = R.string.whats_new_screen_title,
title = UIText.StringResource(R.string.whats_new_screen_title),
icon = R.drawable.ic_star,
direction = WhatsNewScreenDestination
)
Expand All @@ -109,33 +130,32 @@ sealed class HomeDestination(

companion object {
private const val ITEM_NAME_PREFIX = "HomeNavigationItem."
fun fromRoute(fullRoute: String): HomeDestination? =
values().find { it.direction.route.getBaseRoute() == fullRoute.getBaseRoute() }

fun values(): Array<HomeDestination> =
arrayOf(Conversations, Favorites, Group, OneOnOne, Settings, Vault, Archive, Support, WhatsNew)
fun values(): PersistentList<HomeDestination> =
persistentListOf(Conversations, Favorites, Group, OneOnOne, Settings, Vault, Archive, Support, WhatsNew)
}
}

fun HomeDestination.currentFilter(): ConversationFilter {
return when (this) {
HomeDestination.Conversations -> ConversationFilter.ALL
HomeDestination.Favorites -> ConversationFilter.FAVORITES
HomeDestination.Group -> ConversationFilter.GROUPS
HomeDestination.OneOnOne -> ConversationFilter.ONE_ON_ONE
HomeDestination.Conversations -> ConversationFilter.All
HomeDestination.Favorites -> ConversationFilter.Favorites
HomeDestination.Group -> ConversationFilter.Groups
HomeDestination.OneOnOne -> ConversationFilter.OneOnOne
is HomeDestination.Folder -> ConversationFilter.Folder(folderName = folderNavArgs.folderName, folderId = folderNavArgs.folderId)
HomeDestination.Archive,
HomeDestination.Settings,
HomeDestination.Support,
HomeDestination.Vault,
HomeDestination.WhatsNew -> ConversationFilter.ALL
HomeDestination.WhatsNew -> ConversationFilter.All
}
}

fun ConversationFilter.toDestination(): HomeDestination {
return when (this) {
ConversationFilter.ALL -> HomeDestination.Conversations
ConversationFilter.FAVORITES -> HomeDestination.Favorites
ConversationFilter.GROUPS -> HomeDestination.Group
ConversationFilter.ONE_ON_ONE -> HomeDestination.OneOnOne
ConversationFilter.All -> HomeDestination.Conversations
ConversationFilter.Favorites -> HomeDestination.Favorites
ConversationFilter.Groups -> HomeDestination.Group
ConversationFilter.OneOnOne -> HomeDestination.OneOnOne
is ConversationFilter.Folder -> HomeDestination.Folder(FolderNavArgs(folderId, folderName))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,17 @@ import androidx.core.app.NotificationManagerCompat
import androidx.core.app.Person
import com.wire.android.R
import com.wire.android.appLogger
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.notification.NotificationConstants.INCOMING_CALL_ID_PREFIX
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.call.Call
import com.wire.kalium.logic.data.call.CallStatus
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.id.QualifiedID
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -54,9 +57,10 @@ import javax.inject.Singleton
@Singleton
@Suppress("TooManyFunctions")
class CallNotificationManager @Inject constructor(
private val context: Context,
context: Context,
dispatcherProvider: DispatcherProvider,
val builder: CallNotificationBuilder,
@KaliumCoreLogic private val coreLogic: CoreLogic,
) {

private val notificationManager = NotificationManagerCompat.from(context)
Expand All @@ -83,8 +87,19 @@ class CallNotificationManager @Inject constructor(
hideOutdatedIncomingCallNotifications(allCurrentCalls)
// show current incoming call notifications
appLogger.i("$TAG: showing ${newCalls.size} new incoming calls (all incoming calls: ${allCurrentCalls.size})")

val currentSessionId = (coreLogic.getGlobalScope().session.currentSession() as? CurrentSessionResult.Success)?.let {
if (it.accountInfo.isValid()) it.accountInfo.userId else null
}
newCalls.forEach { data ->
showIncomingCallNotification(data)
/**
* For now only show full screen intent for current session, as if shown for another session it will switch to that
* session and the user won't know that he/she is receiving a call as a different account.
* For calls that are not for the current session it will show the notification as a heads up notification.
* In the future we can implement showing on the incoming call screen as what account the user will answer
* or even give them the option to change it themselves on that screen.
*/
showIncomingCallNotification(data = data, asFullScreenIntent = currentSessionId == data.userId)
}
}
}
Expand Down Expand Up @@ -139,14 +154,14 @@ class CallNotificationManager @Inject constructor(

@SuppressLint("MissingPermission")
@VisibleForTesting
internal fun showIncomingCallNotification(data: CallNotificationData) {
internal fun showIncomingCallNotification(data: CallNotificationData, asFullScreenIntent: Boolean) {
appLogger.i(
"$TAG: showing incoming call notification for user ${data.userId.toLogString()}" +
" and conversation ${data.conversationId.toLogString()}"
)
val tag = NotificationConstants.getIncomingCallTag(data.userId.toString())
val id = NotificationConstants.getIncomingCallId(data.userId.toString(), data.conversationId.toString())
val notification = builder.getIncomingCallNotification(data)
val notification = builder.getIncomingCallNotification(data, asFullScreenIntent)
notificationManager.notify(tag, id, notification)
}

Expand Down Expand Up @@ -189,12 +204,11 @@ class CallNotificationBuilder @Inject constructor(
)
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setFullScreenIntent(outgoingCallPendingIntent(context, conversationIdString), true)
.setContentIntent(outgoingCallPendingIntent(context, conversationIdString))
.build()
}

fun getIncomingCallNotification(data: CallNotificationData): Notification {
fun getIncomingCallNotification(data: CallNotificationData, asFullScreenIntent: Boolean): Notification {
val conversationIdString = data.conversationId.toString()
val userIdString = data.userId.toString()
val title = getNotificationTitle(data)
Expand All @@ -220,8 +234,14 @@ class CallNotificationBuilder @Inject constructor(
)
.setVibrate(VIBRATE_PATTERN)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setFullScreenIntent(fullScreenIncomingCallPendingIntent(context, conversationIdString, userIdString), true)
.setContentIntent(fullScreenIncomingCallPendingIntent(context, conversationIdString, userIdString))
.let {
if (asFullScreenIntent) {
it.setFullScreenIntent(fullScreenIncomingCallPendingIntent(context, conversationIdString, userIdString), true)
} else {
it
}
}
.build()

// Added FLAG_INSISTENT so the ringing sound repeats itself until an action is done.
Expand Down Expand Up @@ -255,7 +275,6 @@ class CallNotificationBuilder @Inject constructor(
)
)
.setForegroundServiceBehavior(NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE)
.setFullScreenIntent(openOngoingCallPendingIntent(context, conversationIdString), true)
.setContentIntent(openOngoingCallPendingIntent(context, conversationIdString))
.build()
}
Expand Down
17 changes: 17 additions & 0 deletions app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ import com.wire.android.ui.userprofile.self.dialog.LogoutOptionsDialog
import com.wire.android.ui.userprofile.self.dialog.LogoutOptionsDialogState
import com.wire.android.util.CurrentScreenManager
import com.wire.android.util.LocalSyncStateObserver
import com.wire.android.util.SwitchAccountObserver
import com.wire.android.util.SyncStateObserver
import com.wire.android.util.debug.FeatureVisibilityFlags
import com.wire.android.util.debug.LocalFeatureVisibilityFlags
Expand All @@ -135,6 +136,9 @@ class WireActivity : AppCompatActivity() {
@Inject
lateinit var lockCodeTimeManager: Lazy<LockCodeTimeManager>

@Inject
lateinit var switchAccountObserver: SwitchAccountObserver

private val viewModel: WireActivityViewModel by viewModels()

private val featureFlagNotificationViewModel: FeatureFlagNotificationViewModel by viewModels()
Expand Down Expand Up @@ -346,6 +350,19 @@ class WireActivity : AppCompatActivity() {
navigator.navController.removeOnDestinationChangedListener(currentScreenManager)
}
}

DisposableEffect(switchAccountObserver, navigator) {
NavigationSwitchAccountActions {
lifecycleScope.launch(Dispatchers.Main) {
navigator.navigate(it)
}
}.let {
switchAccountObserver.register(it)
onDispose {
switchAccountObserver.unregister(it)
}
}
}
}

@Composable
Expand Down
Loading

0 comments on commit 5b38cbd

Please sign in to comment.