Skip to content

Commit

Permalink
conversations from folders state improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Garzas committed Dec 10, 2024
1 parent 879e06f commit edb1ea7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 54 deletions.
39 changes: 17 additions & 22 deletions app/src/main/kotlin/com/wire/android/navigation/HomeDestination.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ 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(
Expand All @@ -43,6 +45,10 @@ 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,
Expand All @@ -60,15 +66,17 @@ sealed class HomeDestination(
)

data class Folder(
val folderId: String,
val folderName: String,
val folderNavArgs: FolderNavArgs
) : HomeDestination(
title = UIText.DynamicString(folderName),
title = UIText.DynamicString(folderNavArgs.folderName),
icon = R.drawable.ic_conversation,
isSearchable = true,
withNewConversationFab = true,
direction = FolderConversationsScreenDestination(folderId, folderName)
)
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),
Expand Down Expand Up @@ -122,21 +130,8 @@ 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 getArgumentsFromEntry(navBackStackEntry: NavBackStackEntry?): FolderNavArgs? {
return navBackStackEntry?.let {
if (it.destination.route == FolderConversationsScreenDestination.route) {
FolderConversationsScreenDestination.argsFrom(it)
} else {
null
}
}
}
fun values(): PersistentList<HomeDestination> =
persistentListOf(Conversations, Favorites, Group, OneOnOne, Settings, Vault, Archive, Support, WhatsNew)
}
}

Expand All @@ -146,7 +141,7 @@ fun HomeDestination.currentFilter(): ConversationFilter {
HomeDestination.Favorites -> ConversationFilter.Favorites
HomeDestination.Group -> ConversationFilter.Groups
HomeDestination.OneOnOne -> ConversationFilter.OneOnOne
is HomeDestination.Folder -> ConversationFilter.Folder(folderName = folderName, folderId = folderId)
is HomeDestination.Folder -> ConversationFilter.Folder(folderName = folderNavArgs.folderName, folderId = folderNavArgs.folderId)
HomeDestination.Archive,
HomeDestination.Settings,
HomeDestination.Support,
Expand All @@ -161,6 +156,6 @@ fun ConversationFilter.toDestination(): HomeDestination {
ConversationFilter.Favorites -> HomeDestination.Favorites
ConversationFilter.Groups -> HomeDestination.Group
ConversationFilter.OneOnOne -> HomeDestination.OneOnOne
is ConversationFilter.Folder -> HomeDestination.Folder(folderId = folderId, folderName = folderName)
is ConversationFilter.Folder -> HomeDestination.Folder(FolderNavArgs(folderId, folderName))
}
}
30 changes: 22 additions & 8 deletions app/src/main/kotlin/com/wire/android/ui/home/HomeScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ 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
Expand All @@ -63,6 +64,7 @@ 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
Expand Down Expand Up @@ -97,6 +99,9 @@ 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.ConversationFolder
import kotlinx.collections.immutable.PersistentList
import kotlinx.collections.immutable.persistentListOf
import kotlinx.coroutines.launch

@RootNavGraph
Expand All @@ -109,10 +114,21 @@ fun HomeScreen(
homeViewModel: HomeViewModel = hiltViewModel(),
appSyncViewModel: AppSyncViewModel = hiltViewModel(),
homeDrawerViewModel: HomeDrawerViewModel = hiltViewModel(),
analyticsUsageViewModel: AnalyticsUsageViewModel = hiltViewModel()
analyticsUsageViewModel: AnalyticsUsageViewModel = hiltViewModel(),
foldersViewModel: ConversationFoldersVM =
hiltViewModelScoped<ConversationFoldersVMImpl, ConversationFoldersVM, ConversationFoldersStateArgs>(
ConversationFoldersStateArgs
)
) {
homeViewModel.checkRequirements { it.navigate(navigator::navigate) }
val homeScreenState = rememberHomeScreenState(navigator)
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 notificationsPermissionDeniedDialogState = rememberVisibilityState<PermissionPermanentlyDeniedDialogState>()
val showNotificationsPermissionDeniedDialog = {
notificationsPermissionDeniedDialogState.show(
Expand Down Expand Up @@ -173,7 +189,8 @@ fun HomeScreen(
onSelfUserClick = {
homeViewModel.sendOpenProfileEvent()
navigator.navigate(NavigationCommand(SelfUserProfileScreenDestination))
}
},
folders = foldersViewModel.state().folders
)

BackHandler(homeScreenState.drawerState.isOpen) {
Expand Down Expand Up @@ -244,10 +261,7 @@ fun HomeContent(
onNewConversationClick: () -> Unit,
onSelfUserClick: () -> Unit,
modifier: Modifier = Modifier,
foldersViewModel: ConversationFoldersVM =
hiltViewModelScoped<ConversationFoldersVMImpl, ConversationFoldersVM, ConversationFoldersStateArgs>(
ConversationFoldersStateArgs
),
folders: PersistentList<ConversationFolder> = persistentListOf()
) {
val context = LocalContext.current
val filterSheetState = rememberWireModalSheetState<ConversationFilterSheetData>()
Expand Down Expand Up @@ -315,7 +329,7 @@ fun HomeContent(
filterSheetState.show(
ConversationFilterSheetData(
currentFilter = it,
folders = foldersViewModel.state().folders
folders = folders
)
)
}
Expand Down
26 changes: 3 additions & 23 deletions app/src/main/kotlin/com/wire/android/ui/home/HomeStateHolder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,7 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import com.wire.android.navigation.HomeDestination
import com.wire.android.navigation.HomeDestination.Archive
import com.wire.android.navigation.HomeDestination.Conversations
import com.wire.android.navigation.HomeDestination.Favorites
import com.wire.android.navigation.HomeDestination.Group
import com.wire.android.navigation.HomeDestination.OneOnOne
import com.wire.android.navigation.HomeDestination.Settings
import com.wire.android.navigation.HomeDestination.Support
import com.wire.android.navigation.HomeDestination.Vault
import com.wire.android.navigation.HomeDestination.WhatsNew
import com.wire.android.navigation.Navigator
import com.wire.android.navigation.getBaseRoute
import com.wire.android.navigation.rememberTrackingAnimatedNavController
Expand Down Expand Up @@ -86,17 +78,7 @@ class HomeStateHolder(
@Composable
fun rememberHomeScreenState(
navigator: Navigator,
homeDestinations: List<HomeDestination> = listOf(
Conversations,
Favorites,
OneOnOne,
Group,
Settings,
Vault,
Archive,
Support,
WhatsNew
),
homeDestinations: List<HomeDestination>,
coroutineScope: CoroutineScope = rememberCoroutineScope(),
navController: NavHostController = rememberTrackingAnimatedNavController { route ->
homeDestinations.find { it.direction.route.getBaseRoute() == route }?.itemName
Expand All @@ -107,11 +89,9 @@ fun rememberHomeScreenState(
val searchBarState = rememberSearchbarState()
val navBackStackEntry by navController.currentBackStackEntryAsState()

val currentNavigationItemState = remember {
val currentNavigationItemState = remember(homeDestinations) {
derivedStateOf {
HomeDestination.getArgumentsFromEntry(navBackStackEntry)?.let { args ->
return@derivedStateOf HomeDestination.Folder(args.folderId, args.folderName)
} ?: navBackStackEntry?.destination?.route?.let { HomeDestination.fromRoute(it) ?: Conversations } ?: Conversations
navBackStackEntry?.let { entry -> homeDestinations.find { it.entryMatches(entry) } } ?: Conversations
}
}
val lazyListStates = homeDestinations.associateWith { rememberLazyListState() }
Expand Down

0 comments on commit edb1ea7

Please sign in to comment.