Skip to content

Commit

Permalink
feat: filter folders [WPB-14442] (#3714)
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas authored Dec 10, 2024
1 parent d25e0dc commit e6d8091
Show file tree
Hide file tree
Showing 25 changed files with 724 additions and 142 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 @@ -41,6 +41,7 @@ import com.wire.android.R
import com.wire.android.model.Clickable
import com.wire.android.ui.common.WireCheckIcon
import com.wire.android.ui.common.clickable
import com.wire.android.ui.common.colorsScheme
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.theme.DEFAULT_WEIGHT
import com.wire.android.ui.theme.wireColorScheme
Expand All @@ -55,6 +56,7 @@ fun SelectableMenuBottomSheetItem(
titleStyleUnselected: TextStyle = MaterialTheme.wireTypography.body02,
titleStyleSelected: TextStyle = MaterialTheme.wireTypography.body02,
subLine: String? = null,
description: String? = null,
icon: @Composable () -> Unit = { },
onItemClick: Clickable = Clickable(enabled = false) {},
state: RichMenuItemState = RichMenuItemState.DEFAULT
Expand All @@ -77,12 +79,30 @@ fun SelectableMenuBottomSheetItem(
modifier = Modifier
.weight(DEFAULT_WEIGHT),
) {
MenuItemHeading(
title = title, color = titleColor,
titleStyleUnselected = titleStyleUnselected,
titleStyleSelected = titleStyleSelected,
state = state
)
Row {
MenuItemHeading(
title = title,
color = titleColor,
titleStyleUnselected = titleStyleUnselected,
titleStyleSelected = titleStyleSelected,
state = state,
modifier = if (description != null) {
Modifier
} else {
Modifier.weight(1F)
}
)
if (description != null) {
Text(
text = description,
style = MaterialTheme.wireTypography.body01,
color = colorsScheme().secondaryText,
modifier = Modifier
.weight(1f)
.padding(start = dimensions().spacing16x)
)
}
}
if (subLine != null) {
MenuItemSubLine(
subLine = subLine,
Expand All @@ -106,7 +126,7 @@ fun SelectableMenuBottomSheetItem(
@Composable
fun MenuItemHeading(
title: String,
modifier: Modifier = Modifier,
modifier: Modifier = Modifier.fillMaxWidth(),
titleStyleUnselected: TextStyle = MaterialTheme.wireTypography.body02,
titleStyleSelected: TextStyle = MaterialTheme.wireTypography.body02,
state: RichMenuItemState = RichMenuItemState.DEFAULT,
Expand All @@ -116,7 +136,7 @@ fun MenuItemHeading(
style = if (isSelectedItem(state)) titleStyleSelected else titleStyleUnselected,
color = if (isSelectedItem(state)) MaterialTheme.wireColorScheme.primary else color ?: MaterialTheme.wireColorScheme.onBackground,
text = title,
modifier = modifier.fillMaxWidth()
modifier = modifier
)
}

Expand Down
Loading

0 comments on commit e6d8091

Please sign in to comment.