From d37cf33a94732b6e31227393d1eea36043471b45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Saleniuk?= <30429749+saleniuk@users.noreply.github.com> Date: Mon, 16 Dec 2024 10:34:26 +0100 Subject: [PATCH] fix: retain filters and simplify navigation [WPB-14518] (#3737) --- .../android/navigation/HomeDestination.kt | 78 +---------------- .../ui/calling/CallActivityViewModel.kt | 3 +- .../topappbar/ConversationFilterState.kt | 53 ++++++++++++ .../com/wire/android/ui/home/HomeScreen.kt | 21 ++--- .../wire/android/ui/home/HomeStateHolder.kt | 53 ++++++++---- .../com/wire/android/ui/home/HomeTopBar.kt | 17 +++- .../all/AllConversationsScreen.kt | 86 ++++--------------- .../filter/ConversationFilterSheetContent.kt | 5 +- .../model/ConversationsSource.kt | 10 +++ 9 files changed, 143 insertions(+), 183 deletions(-) create mode 100644 app/src/main/kotlin/com/wire/android/ui/common/topappbar/ConversationFilterState.kt diff --git a/app/src/main/kotlin/com/wire/android/navigation/HomeDestination.kt b/app/src/main/kotlin/com/wire/android/navigation/HomeDestination.kt index 42aed03d34a..24c30a17b74 100644 --- a/app/src/main/kotlin/com/wire/android/navigation/HomeDestination.kt +++ b/app/src/main/kotlin/com/wire/android/navigation/HomeDestination.kt @@ -19,22 +19,14 @@ package com.wire.android.navigation import androidx.annotation.DrawableRes -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( @@ -45,10 +37,6 @@ sealed class HomeDestination( 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 = UIText.StringResource(R.string.conversations_screen_title), icon = R.drawable.ic_conversation, @@ -57,43 +45,6 @@ sealed class HomeDestination( direction = AllConversationsScreenDestination ) - data object Favorites : HomeDestination( - 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 = UIText.StringResource(R.string.label_filter_group), - icon = R.drawable.ic_conversation, - isSearchable = true, - withNewConversationFab = true, - direction = GroupConversationsScreenDestination - ) - - data object OneOnOne : HomeDestination( - 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 = UIText.StringResource(R.string.settings_screen_title), icon = R.drawable.ic_settings, @@ -130,32 +81,11 @@ sealed class HomeDestination( companion object { private const val ITEM_NAME_PREFIX = "HomeNavigationItem." - fun values(): PersistentList = - 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.OneOnOne - is HomeDestination.Folder -> ConversationFilter.Folder(folderName = folderNavArgs.folderName, folderId = folderNavArgs.folderId) - HomeDestination.Archive, - HomeDestination.Settings, - HomeDestination.Support, - HomeDestination.Vault, - HomeDestination.WhatsNew -> ConversationFilter.All - } -} + fun fromRoute(fullRoute: String): HomeDestination? = + values().find { it.direction.route.getBaseRoute() == fullRoute.getBaseRoute() } -fun ConversationFilter.toDestination(): HomeDestination { - return when (this) { - ConversationFilter.All -> HomeDestination.Conversations - ConversationFilter.Favorites -> HomeDestination.Favorites - ConversationFilter.Groups -> HomeDestination.Group - ConversationFilter.OneOnOne -> HomeDestination.OneOnOne - is ConversationFilter.Folder -> HomeDestination.Folder(FolderNavArgs(folderId, folderName)) + fun values(): Array = + arrayOf(Conversations, Settings, Vault, Archive, Support, WhatsNew) } } diff --git a/app/src/main/kotlin/com/wire/android/ui/calling/CallActivityViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/calling/CallActivityViewModel.kt index 0dd6344b588..004667bb057 100644 --- a/app/src/main/kotlin/com/wire/android/ui/calling/CallActivityViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/calling/CallActivityViewModel.kt @@ -30,7 +30,6 @@ import com.wire.kalium.logic.feature.session.CurrentSessionUseCase import com.wire.kalium.logic.feature.user.screenshotCensoring.ObserveScreenshotCensoringConfigResult import dagger.hilt.android.lifecycle.HiltViewModel import kotlinx.coroutines.Deferred -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.async import kotlinx.coroutines.flow.first import kotlinx.coroutines.flow.map @@ -61,7 +60,7 @@ class CallActivityViewModel @Inject constructor( } fun switchAccountIfNeeded(userId: UserId, actions: SwitchAccountActions) { - viewModelScope.launch(Dispatchers.IO) { + viewModelScope.launch(dispatchers.io()) { val shouldSwitchAccount = when (val result = currentSession()) { is CurrentSessionResult.Failure.Generic -> true CurrentSessionResult.Failure.SessionNotFound -> true diff --git a/app/src/main/kotlin/com/wire/android/ui/common/topappbar/ConversationFilterState.kt b/app/src/main/kotlin/com/wire/android/ui/common/topappbar/ConversationFilterState.kt new file mode 100644 index 00000000000..f9bb13e28fc --- /dev/null +++ b/app/src/main/kotlin/com/wire/android/ui/common/topappbar/ConversationFilterState.kt @@ -0,0 +1,53 @@ +/* + * 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.topappbar + +import android.os.Bundle +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.saveable.Saver +import androidx.compose.runtime.saveable.rememberSaveable +import androidx.compose.runtime.setValue +import com.wire.kalium.logic.data.conversation.ConversationFilter +import dev.ahmedmourad.bundlizer.Bundlizer + +@Composable +fun rememberConversationFilterState(): ConversationFilterState = rememberSaveable(saver = ConversationFilterState.saver()) { + ConversationFilterState() +} + +class ConversationFilterState(initialValue: ConversationFilter = ConversationFilter.All) { + var filter: ConversationFilter by mutableStateOf(initialValue) + private set + + fun changeFilter(newFilter: ConversationFilter) { + filter = newFilter + } + + companion object { + fun saver(): Saver = Saver( + save = { + Bundlizer.bundle(ConversationFilter.serializer(), it.filter) + }, + restore = { + ConversationFilterState(Bundlizer.unbundle(ConversationFilter.serializer(), it)) + } + ) + } +} diff --git a/app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt b/app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt index 32907047c6e..3b48dd13629 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt @@ -38,7 +38,6 @@ import androidx.compose.material3.ModalNavigationDrawer import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.runtime.LaunchedEffect -import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.ColorFilter @@ -64,13 +63,11 @@ import com.ramcosta.composedestinations.result.ResultRecipient import com.wire.android.R import com.wire.android.appLogger import com.wire.android.di.hiltViewModelScoped -import com.wire.android.navigation.FolderNavArgs import com.wire.android.navigation.HomeDestination import com.wire.android.navigation.NavigationCommand import com.wire.android.navigation.Navigator import com.wire.android.navigation.WireDestination import com.wire.android.navigation.handleNavigation -import com.wire.android.navigation.toDestination import com.wire.android.ui.NavGraphs import com.wire.android.ui.analytics.AnalyticsUsageViewModel import com.wire.android.ui.common.CollapsingTopBarScaffold @@ -121,14 +118,8 @@ fun HomeScreen( ) ) { homeViewModel.checkRequirements { it.navigate(navigator::navigate) } - val homeDestinations = remember(foldersViewModel.state().folders) { - HomeDestination.values() - .plus( - foldersViewModel.state().folders.map { HomeDestination.Folder(FolderNavArgs(it.id, it.name)) } - ) - } - val homeScreenState = rememberHomeScreenState(navigator, homeDestinations = homeDestinations) + val homeScreenState = rememberHomeScreenState(navigator) val notificationsPermissionDeniedDialogState = rememberVisibilityState() val showNotificationsPermissionDeniedDialog = { notificationsPermissionDeniedDialogState.show( @@ -318,6 +309,8 @@ fun HomeContent( exit = shrinkVertically() + fadeOut(), ) { HomeTopBar( + title = currentTitle.asString(), + currentFilter = currentConversationFilter, navigationItem = currentNavigationItem, userAvatarData = homeState.userAvatarData, elevation = dimensions().spacing0x, // CollapsingTopBarScaffold manages applied elevation @@ -347,7 +340,7 @@ fun HomeContent( } }, collapsingEnabled = !searchBarState.isSearchActive, - contentLazyListState = homeStateHolder.nullAbleLazyListStateFor(currentNavigationItem), + contentLazyListState = homeStateHolder.lazyListStateFor(currentNavigationItem), content = { /** * This "if" is a workaround, otherwise it can crash because of the SubcomposeLayout's nature. @@ -407,11 +400,7 @@ fun HomeContent( ConversationFilterSheetContent( onChangeFilter = { filter -> filterSheetState.hide() - openHomeDestination(filter.toDestination()) - }, - onChangeFolder = { - filterSheetState.hide() - openHomeDestination(it.toDestination()) + homeStateHolder.changeFilter(filter) }, filterSheetState = sheetContentState ) diff --git a/app/src/main/kotlin/com/wire/android/ui/home/HomeStateHolder.kt b/app/src/main/kotlin/com/wire/android/ui/home/HomeStateHolder.kt index f6e802ce309..ed39cb797a8 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/HomeStateHolder.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/HomeStateHolder.kt @@ -19,7 +19,6 @@ package com.wire.android.ui.home import androidx.compose.foundation.lazy.LazyListState -import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.DrawerState import androidx.compose.material3.DrawerValue import androidx.compose.material3.rememberDrawerState @@ -34,10 +33,13 @@ import androidx.navigation.compose.currentBackStackEntryAsState import com.wire.android.navigation.HomeDestination import com.wire.android.navigation.HomeDestination.Conversations import com.wire.android.navigation.Navigator -import com.wire.android.navigation.getBaseRoute import com.wire.android.navigation.rememberTrackingAnimatedNavController +import com.wire.android.ui.common.topappbar.ConversationFilterState +import com.wire.android.ui.common.topappbar.rememberConversationFilterState import com.wire.android.ui.common.topappbar.search.SearchBarState import com.wire.android.ui.common.topappbar.search.rememberSearchbarState +import com.wire.android.ui.home.conversationslist.filter.uiText +import com.wire.kalium.logic.data.conversation.ConversationFilter import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.launch @@ -49,18 +51,34 @@ class HomeStateHolder( val searchBarState: SearchBarState, val navigator: Navigator, private val currentNavigationItemState: State, - private val lazyListStates: Map, + private val conversationFilterState: ConversationFilterState, ) { val currentNavigationItem get() = currentNavigationItemState.value - fun lazyListStateFor(destination: HomeDestination): LazyListState { - return lazyListStates[destination] ?: error("No LazyListState found for $destination") - } + val currentConversationFilter + get() = conversationFilterState.filter - fun nullAbleLazyListStateFor(destination: HomeDestination): LazyListState? { - return lazyListStates[destination] - } + val currentTitle + get() = when (currentNavigationItemState.value) { + Conversations -> conversationFilterState.filter.uiText() + else -> currentNavigationItemState.value.title + } + + private val lazyListStatesMap = mutableMapOf() + + fun lazyListStateFor( + destination: HomeDestination, + conversationFilter: ConversationFilter = ConversationFilter.All, + ): LazyListState = + lazyListStatesMap.getOrPut( + key = destination.itemName + when (destination) { + Conversations -> ":$conversationFilter" // each filter has its own scroll state + else -> "" // other destinations shouldn't care about the conversation filter + } + ) { + LazyListState() + } fun closeDrawer() { coroutineScope.launch { @@ -73,15 +91,16 @@ class HomeStateHolder( drawerState.open() } } + + fun changeFilter(filter: ConversationFilter) = conversationFilterState.changeFilter(filter) } @Composable fun rememberHomeScreenState( navigator: Navigator, - homeDestinations: List, coroutineScope: CoroutineScope = rememberCoroutineScope(), - navController: NavHostController = rememberTrackingAnimatedNavController { route -> - homeDestinations.find { it.direction.route.getBaseRoute() == route }?.itemName + navController: NavHostController = rememberTrackingAnimatedNavController { + HomeDestination.fromRoute(it)?.itemName }, drawerState: DrawerState = rememberDrawerState(DrawerValue.Closed) ): HomeStateHolder { @@ -89,14 +108,14 @@ fun rememberHomeScreenState( val searchBarState = rememberSearchbarState() val navBackStackEntry by navController.currentBackStackEntryAsState() - val currentNavigationItemState = remember(homeDestinations) { + val currentNavigationItemState = remember { derivedStateOf { - navBackStackEntry?.let { entry -> homeDestinations.find { it.entryMatches(entry) } } ?: Conversations + navBackStackEntry?.destination?.route?.let { HomeDestination.fromRoute(it) } ?: Conversations } } - val lazyListStates = homeDestinations.associateWith { rememberLazyListState() } + val conversationFilterState = rememberConversationFilterState() - return remember(homeDestinations) { + return remember { HomeStateHolder( coroutineScope = coroutineScope, navController = navController, @@ -104,7 +123,7 @@ fun rememberHomeScreenState( searchBarState = searchBarState, navigator = navigator, currentNavigationItemState = currentNavigationItemState, - lazyListStates = lazyListStates + conversationFilterState = conversationFilterState, ) } } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/HomeTopBar.kt b/app/src/main/kotlin/com/wire/android/ui/home/HomeTopBar.kt index 28039c3ea12..cc0ea36b60d 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/HomeTopBar.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/HomeTopBar.kt @@ -28,7 +28,6 @@ import com.wire.android.model.Clickable import com.wire.android.model.NameBasedAvatar import com.wire.android.model.UserAvatarData import com.wire.android.navigation.HomeDestination -import com.wire.android.navigation.currentFilter import com.wire.android.ui.common.avatar.UserProfileAvatar import com.wire.android.ui.common.avatar.UserProfileAvatarType import com.wire.android.ui.common.button.WireButtonState @@ -42,6 +41,8 @@ import com.wire.kalium.logic.data.user.UserAvailabilityStatus @Composable fun HomeTopBar( + title: String, + currentFilter: ConversationFilter, navigationItem: HomeDestination, userAvatarData: UserAvatarData, elevation: Dp, @@ -52,7 +53,7 @@ fun HomeTopBar( onOpenConversationFilter: (filter: ConversationFilter) -> Unit ) { WireCenterAlignedTopAppBar( - title = navigationItem.title.asString(), + title = title, onNavigationPressed = onHamburgerMenuClick, navigationIconType = NavigationIconType.Menu, actions = { @@ -60,12 +61,12 @@ fun HomeTopBar( WireTertiaryIconButton( iconResource = R.drawable.ic_filter, contentDescription = R.string.label_filter_conversations, - state = if (navigationItem.currentFilter() == ConversationFilter.All) { + state = if (currentFilter == ConversationFilter.All) { WireButtonState.Default } else { WireButtonState.Selected }, - onButtonClicked = { onOpenConversationFilter(navigationItem.currentFilter()) } + onButtonClicked = { onOpenConversationFilter(currentFilter) } ) } if (navigationItem.withUserAvatar) { @@ -100,7 +101,9 @@ fun HomeTopBar( fun PreviewTopBar() { WireTheme { HomeTopBar( + title = "Conversations", navigationItem = HomeDestination.Conversations, + currentFilter = ConversationFilter.All, userAvatarData = UserAvatarData(null, UserAvailabilityStatus.AVAILABLE), elevation = 0.dp, withLegalHoldIndicator = false, @@ -117,7 +120,9 @@ fun PreviewTopBar() { fun PreviewSettingsTopBarWithoutAvatar() { WireTheme { HomeTopBar( + title = "Settings", navigationItem = HomeDestination.Settings, + currentFilter = ConversationFilter.All, userAvatarData = UserAvatarData(null, UserAvailabilityStatus.AVAILABLE), elevation = 0.dp, withLegalHoldIndicator = false, @@ -134,7 +139,9 @@ fun PreviewSettingsTopBarWithoutAvatar() { fun PreviewTopBarWithNameBasedAvatar() { WireTheme { HomeTopBar( + title = "Conversations", navigationItem = HomeDestination.Conversations, + currentFilter = ConversationFilter.All, userAvatarData = UserAvatarData( asset = null, availabilityStatus = UserAvailabilityStatus.AVAILABLE, @@ -155,7 +162,9 @@ fun PreviewTopBarWithNameBasedAvatar() { fun PreviewTopBarWithLegalHold() { WireTheme { HomeTopBar( + title = "Archive", navigationItem = HomeDestination.Archive, + currentFilter = ConversationFilter.All, userAvatarData = UserAvatarData(null, UserAvailabilityStatus.AVAILABLE), elevation = 0.dp, withLegalHoldIndicator = true, diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/all/AllConversationsScreen.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/all/AllConversationsScreen.kt index 03318926dc3..3f9ff8fe23a 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/all/AllConversationsScreen.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/all/AllConversationsScreen.kt @@ -18,9 +18,9 @@ package com.wire.android.ui.home.conversationslist.all +import androidx.compose.animation.Crossfade import androidx.compose.foundation.text.input.TextFieldState import androidx.compose.runtime.Composable -import com.wire.android.navigation.FolderNavArgs import com.wire.android.navigation.HomeDestination import com.wire.android.navigation.HomeNavGraph import com.wire.android.navigation.WireDestination @@ -41,72 +41,24 @@ import kotlinx.coroutines.flow.flowOf @Composable fun AllConversationsScreen(homeStateHolder: HomeStateHolder) { with(homeStateHolder) { - ConversationsScreenContent( - navigator = navigator, - searchBarState = searchBarState, - conversationsSource = ConversationsSource.MAIN, - lazyListState = lazyListStateFor(HomeDestination.Conversations), - emptyListContent = { ConversationsEmptyContent(filter = ConversationFilter.All) } - ) - } -} - -@HomeNavGraph -@WireDestination -@Composable -fun FavoritesConversationsScreen(homeStateHolder: HomeStateHolder) { - with(homeStateHolder) { - ConversationsScreenContent( - navigator = navigator, - searchBarState = searchBarState, - conversationsSource = ConversationsSource.FAVORITES, - lazyListState = lazyListStateFor(HomeDestination.Favorites), - emptyListContent = { ConversationsEmptyContent(filter = ConversationFilter.Favorites) } - ) - } -} - -@HomeNavGraph -@WireDestination(navArgsDelegate = FolderNavArgs::class) -@Composable -fun FolderConversationsScreen(homeStateHolder: HomeStateHolder, args: FolderNavArgs) { - with(homeStateHolder) { - ConversationsScreenContent( - navigator = navigator, - searchBarState = searchBarState, - conversationsSource = ConversationsSource.FOLDER(args.folderId, args.folderName), - emptyListContent = { ConversationsEmptyContent(filter = ConversationFilter.Folder(args.folderId, args.folderName)) } - ) - } -} - -@HomeNavGraph -@WireDestination -@Composable -fun GroupConversationsScreen(homeStateHolder: HomeStateHolder) { - with(homeStateHolder) { - ConversationsScreenContent( - navigator = navigator, - searchBarState = searchBarState, - conversationsSource = ConversationsSource.GROUPS, - lazyListState = lazyListStateFor(HomeDestination.Group), - emptyListContent = { ConversationsEmptyContent(filter = ConversationFilter.Groups) } - ) - } -} - -@HomeNavGraph -@WireDestination -@Composable -fun OneOnOneConversationsScreen(homeStateHolder: HomeStateHolder) { - with(homeStateHolder) { - ConversationsScreenContent( - navigator = navigator, - searchBarState = searchBarState, - conversationsSource = ConversationsSource.ONE_ON_ONE, - lazyListState = lazyListStateFor(HomeDestination.OneOnOne), - emptyListContent = { ConversationsEmptyContent(filter = ConversationFilter.OneOnOne, domain = it) } - ) + Crossfade( + targetState = homeStateHolder.currentConversationFilter, + label = "Conversation filter change animation", + ) { filter -> + ConversationsScreenContent( + navigator = navigator, + searchBarState = searchBarState, + conversationsSource = when (filter) { + is ConversationFilter.All -> ConversationsSource.MAIN + is ConversationFilter.Favorites -> ConversationsSource.FAVORITES + is ConversationFilter.Groups -> ConversationsSource.GROUPS + is ConversationFilter.OneOnOne -> ConversationsSource.ONE_ON_ONE + is ConversationFilter.Folder -> ConversationsSource.FOLDER(filter.folderId, filter.folderName) + }, + lazyListState = lazyListStateFor(HomeDestination.Conversations, filter), + emptyListContent = { ConversationsEmptyContent(filter = ConversationFilter.All) } + ) + } } } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/filter/ConversationFilterSheetContent.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/filter/ConversationFilterSheetContent.kt index 0dcb4da607f..4ae6fca2f91 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/filter/ConversationFilterSheetContent.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/filter/ConversationFilterSheetContent.kt @@ -28,7 +28,6 @@ import com.wire.kalium.logic.data.conversation.ConversationFilter fun ConversationFilterSheetContent( filterSheetState: ConversationFilterSheetState, onChangeFilter: (ConversationFilter) -> Unit, - onChangeFolder: (ConversationFilter.Folder) -> Unit, isBottomSheetVisible: () -> Boolean = { true } ) { when (filterSheetState.currentData.tab) { @@ -45,7 +44,7 @@ fun ConversationFilterSheetContent( FilterTab.FOLDERS -> { ConversationFoldersSheetContent( sheetData = filterSheetState.currentData, - onChangeFolder = onChangeFolder, + onChangeFolder = onChangeFilter, onBackClick = { filterSheetState.toFilters() } @@ -77,5 +76,5 @@ fun ConversationFilter.uiText(): UIText = when (this) { ConversationFilter.Favorites -> UIText.StringResource(R.string.label_filter_favorites) ConversationFilter.Groups -> UIText.StringResource(R.string.label_filter_group) ConversationFilter.OneOnOne -> UIText.StringResource(R.string.label_filter_one_on_one) - is ConversationFilter.Folder -> UIText.StringResource(R.string.label_filter_folders, this.folderName) + is ConversationFilter.Folder -> UIText.DynamicString(this.folderName) } diff --git a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/model/ConversationsSource.kt b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/model/ConversationsSource.kt index 45a7aad4391..4efe537856a 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/model/ConversationsSource.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/conversationslist/model/ConversationsSource.kt @@ -22,11 +22,21 @@ import kotlinx.serialization.Serializable @Serializable sealed class ConversationsSource { + @Serializable data object MAIN : ConversationsSource() + + @Serializable data object ARCHIVE : ConversationsSource() + + @Serializable data object FAVORITES : ConversationsSource() + + @Serializable data object GROUPS : ConversationsSource() + + @Serializable data object ONE_ON_ONE : ConversationsSource() + @Serializable data class FOLDER(val folderId: String, val folderName: String) : ConversationsSource() }