Skip to content

Commit

Permalink
feat: filter conversation list [WPB-11638] (#3555)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas authored Oct 29, 2024
1 parent 82d26f8 commit 1e58d62
Show file tree
Hide file tree
Showing 32 changed files with 460 additions and 142 deletions.
56 changes: 53 additions & 3 deletions app/src/main/kotlin/com/wire/android/navigation/HomeDestination.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,54 @@ 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.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.kalium.logic.data.conversation.ConversationFilter

@Suppress("LongParameterList")
sealed class HomeDestination(
@StringRes val title: Int,
@StringRes val tabName: Int = title,
@DrawableRes val icon: Int,
val isSearchable: Boolean = false,
val withNewConversationFab: Boolean = false,
val direction: Direction
) {
data object Conversations : HomeDestination(
title = R.string.conversations_screen_title,
tabName = R.string.conversations_all_tab_title,
icon = R.drawable.ic_conversation,
isSearchable = true,
withNewConversationFab = true,
direction = AllConversationsScreenDestination
)

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

data object Group : HomeDestination(
title = 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,
icon = R.drawable.ic_conversation,
isSearchable = true,
withNewConversationFab = true,
direction = OneOnOneConversationsScreenDestination
)

data object Settings : HomeDestination(
title = R.string.settings_screen_title,
icon = R.drawable.ic_settings,
Expand Down Expand Up @@ -83,7 +109,31 @@ sealed class HomeDestination(
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, Settings, Vault, Archive, Support, WhatsNew)
arrayOf(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.Archive,
HomeDestination.Settings,
HomeDestination.Support,
HomeDestination.Vault,
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ import com.wire.android.ui.theme.wireTypography
fun PreviewMenuBottomSheetItem() {
MenuBottomSheetItem(
title = "very long looooooong title",
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_erase,
contentDescription = "",
)
},
action = {
trailing = {
Row(verticalAlignment = Alignment.CenterVertically) {
Text(
text = "very long looooooong action",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ internal fun ConversationMainSheetContent(
add {
MenuBottomSheetItem(
title = stringResource(R.string.label_notifications),
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_mute,
contentDescription = null,
)
},
action = { NotificationsOptionsItemAction(conversationSheetContent.mutingConversationState) },
trailing = { NotificationsOptionsItemAction(conversationSheetContent.mutingConversationState) },
onItemClick = navigateToNotification,
onItemClickDescription = stringResource(id = R.string.content_description_open_notification_settings_label)
)
Expand Down Expand Up @@ -137,7 +137,7 @@ internal fun ConversationMainSheetContent(
// }
add {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_archive,
contentDescription = null,
Expand All @@ -164,7 +164,7 @@ internal fun ConversationMainSheetContent(
}
add {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_erase,
contentDescription = null,
Expand All @@ -187,7 +187,7 @@ internal fun ConversationMainSheetContent(
if (conversationSheetContent.canBlockUser()) {
add {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_block,
contentDescription = null,
Expand All @@ -210,7 +210,7 @@ internal fun ConversationMainSheetContent(
if (conversationSheetContent.canUnblockUser()) {
add {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_block,
contentDescription = null
Expand All @@ -232,7 +232,7 @@ internal fun ConversationMainSheetContent(
if (conversationSheetContent.canLeaveTheGroup()) {
add {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_leave,
contentDescription = null,
Expand All @@ -254,7 +254,7 @@ internal fun ConversationMainSheetContent(
if (conversationSheetContent.canDeleteGroup()) {
add {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_remove,
contentDescription = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.wire.android.ui.common.bottomsheet.MenuItemIcon
@Composable
fun CopyItemMenuOption(onCopyItemClick: () -> Unit) {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_copy,
contentDescription = stringResource(R.string.content_description_copy_the_message),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.wire.android.ui.common.bottomsheet.MenuItemIcon
@Composable
fun DeleteItemMenuOption(onDeleteItemClick: () -> Unit) {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_delete,
contentDescription = stringResource(R.string.content_description_delete_the_message),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.wire.android.ui.common.bottomsheet.MenuItemIcon
@Composable
fun DownloadAssetExternallyOption(onDownloadClick: () -> Unit) =
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_download,
contentDescription = stringResource(R.string.content_description_download_icon),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.wire.android.ui.common.bottomsheet.MenuItemIcon
@Composable
fun EditMessageMenuOption(onEditItemClick: () -> Unit) {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_edit,
contentDescription = stringResource(R.string.content_description_edit_the_message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun MessageDetailsMenuOption(
onMessageDetailsClick: () -> Unit
) {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_info,
contentDescription = stringResource(R.string.content_description_open_message_details),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.wire.android.ui.common.bottomsheet.MenuItemIcon
@Composable
fun OpenAssetExternallyOption(onOpenClick: () -> Unit) =
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_view,
contentDescription = stringResource(R.string.content_description_open_asset_icon),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.wire.android.ui.common.bottomsheet.MenuItemIcon
@Composable
fun ReplyMessageOption(onReplyItemClick: () -> Unit) {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_reply,
contentDescription = stringResource(R.string.content_description_reply_to_messge),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.wire.android.ui.common.bottomsheet.MenuItemIcon
@Composable
fun ShareAssetMenuOption(onShareAsset: () -> Unit) {
MenuBottomSheetItem(
icon = {
leading = {
MenuItemIcon(
id = R.drawable.ic_share_file,
contentDescription = stringResource(R.string.content_description_share_the_file),
Expand Down
23 changes: 22 additions & 1 deletion app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ 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.currentFilter
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
import com.wire.android.ui.common.FloatingActionButton
import com.wire.android.ui.common.bottomsheet.WireModalSheetLayout
import com.wire.android.ui.common.bottomsheet.rememberWireModalSheetState
import com.wire.android.ui.common.dialogs.PermissionPermanentlyDeniedDialog
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.common.snackbar.LocalSnackbarHostState
Expand All @@ -84,10 +88,12 @@ import com.wire.android.ui.destinations.SelfUserProfileScreenDestination
import com.wire.android.ui.home.conversations.PermissionPermanentlyDeniedDialogState
import com.wire.android.ui.home.conversations.details.GroupConversationActionType
import com.wire.android.ui.home.conversations.details.GroupConversationDetailsNavBackArgs
import com.wire.android.ui.home.conversationslist.filter.ConversationFilterSheetContent
import com.wire.android.ui.home.drawer.HomeDrawer
import com.wire.android.ui.home.drawer.HomeDrawerState
import com.wire.android.ui.home.drawer.HomeDrawerViewModel
import com.wire.android.util.permission.rememberShowNotificationsPermissionFlow
import com.wire.kalium.logic.data.conversation.ConversationFilter
import kotlinx.coroutines.launch

@RootNavGraph
Expand Down Expand Up @@ -234,6 +240,8 @@ fun HomeContent(
modifier: Modifier = Modifier,
) {
val context = LocalContext.current
val filterSheetState = rememberWireModalSheetState<ConversationFilter>()

with(homeStateHolder) {
fun openHomeDestination(item: HomeDestination) {
item.direction.handleNavigation(
Expand Down Expand Up @@ -285,13 +293,14 @@ fun HomeContent(
exit = shrinkVertically() + fadeOut(),
) {
HomeTopBar(
navigationItem = currentNavigationItem,
userAvatarData = homeState.userAvatarData,
title = stringResource(currentNavigationItem.title),
elevation = dimensions().spacing0x, // CollapsingTopBarScaffold manages applied elevation
withLegalHoldIndicator = homeState.shouldDisplayLegalHoldIndicator,
shouldShowCreateTeamUnreadIndicator = homeState.shouldShowCreateTeamUnreadIndicator,
onHamburgerMenuClick = ::openDrawer,
onNavigateToSelfUserProfile = onSelfUserClick,
onOpenConversationFilter = { filterSheetState.show(it) }
)
}
},
Expand Down Expand Up @@ -359,5 +368,17 @@ fun HomeContent(
)
}
)
WireModalSheetLayout(
sheetState = filterSheetState,
sheetContent = {
ConversationFilterSheetContent(
currentFilter = currentNavigationItem.currentFilter(),
onChangeFilter = { filter ->
filterSheetState.hide()
openHomeDestination(filter.toDestination())
}
)
}
)
}
}
Loading

0 comments on commit 1e58d62

Please sign in to comment.