-
Notifications
You must be signed in to change notification settings - Fork 46
feat: Navigate between folders (WPB-17392) #4018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5d9cdb6
746ca4f
5d64eec
80e6312
a5bd4a9
ecff721
940e2d2
07a447a
ef82c41
3aa58d7
b38e1ca
0ae45f1
c7e944a
1695291
3cd134b
7ab9dc8
d5845f9
f04d9e9
ee5d965
de832b2
27773d2
913dfa5
4f97fa8
6170d00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,12 +32,16 @@ import androidx.compose.ui.layout.ContentScale | |
| import androidx.compose.ui.res.painterResource | ||
| import androidx.compose.ui.res.stringResource | ||
| import androidx.hilt.navigation.compose.hiltViewModel | ||
| import androidx.paging.compose.LazyPagingItems | ||
| import androidx.paging.compose.collectAsLazyPagingItems | ||
| import com.ramcosta.composedestinations.annotation.Destination | ||
| import com.wire.android.feature.cells.R | ||
| import com.wire.android.feature.cells.ui.destinations.ConversationFilesWithSlideInTransitionScreenDestination | ||
| import com.wire.android.feature.cells.ui.destinations.CreateFolderScreenDestination | ||
| import com.wire.android.feature.cells.ui.destinations.PublicLinkScreenDestination | ||
| import com.wire.android.feature.cells.ui.dialog.CellsNewActionsBottomSheet | ||
| import com.wire.android.feature.cells.ui.model.CellNodeUi | ||
| import com.wire.android.navigation.BackStackMode | ||
| import com.wire.android.navigation.NavigationCommand | ||
| import com.wire.android.navigation.WireNavigator | ||
| import com.wire.android.navigation.style.PopUpNavigationAnimation | ||
|
|
@@ -48,6 +52,9 @@ import com.wire.android.ui.common.dimensions | |
| import com.wire.android.ui.common.scaffold.WireScaffold | ||
| import com.wire.android.ui.common.topappbar.NavigationIconType | ||
| import com.wire.android.ui.common.topappbar.WireCenterAlignedTopAppBar | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.SharedFlow | ||
| import kotlinx.coroutines.flow.StateFlow | ||
|
|
||
| /** | ||
| * Show files in one conversation. | ||
|
|
@@ -60,10 +67,33 @@ import com.wire.android.ui.common.topappbar.WireCenterAlignedTopAppBar | |
| @Composable | ||
| fun ConversationFilesScreen( | ||
| navigator: WireNavigator, | ||
| viewModel: CellViewModel = hiltViewModel(), | ||
| ) { | ||
|
|
||
| ConversationFilesScreenContent( | ||
| navigator = navigator, | ||
| currentNodeUuid = viewModel.currentNodeUuid(), | ||
| actions = viewModel.actions, | ||
| pagingListItems = viewModel.nodesFlow.collectAsLazyPagingItems(), | ||
| downloadFileSheet = viewModel.downloadFileSheet, | ||
| menu = viewModel.menu, | ||
| sendIntent = { viewModel.sendIntent(it) }, | ||
| ) | ||
| } | ||
|
|
||
| @Composable | ||
| fun ConversationFilesScreenContent( | ||
| navigator: WireNavigator, | ||
| currentNodeUuid: String?, | ||
| actions: Flow<CellViewAction>, | ||
| pagingListItems: LazyPagingItems<CellNodeUi>, | ||
| downloadFileSheet: StateFlow<CellNodeUi.File?>, | ||
| menu: SharedFlow<MenuOptions>, | ||
| sendIntent: (CellViewIntent) -> Unit, | ||
| modifier: Modifier = Modifier, | ||
| viewModel: CellViewModel = hiltViewModel() | ||
| screenTitle: String? = null, | ||
| navigationIconType: NavigationIconType = NavigationIconType.Close() | ||
| ) { | ||
| val pagingListItems = viewModel.nodesFlow.collectAsLazyPagingItems() | ||
| val sheetState = rememberWireModalSheetState<Unit>() | ||
|
|
||
| val isFabVisible = when { | ||
|
|
@@ -78,16 +108,16 @@ fun ConversationFilesScreen( | |
| sheetState.hide() | ||
| }, | ||
| onCreateFolder = { | ||
| navigator.navigate(NavigationCommand(CreateFolderScreenDestination())) | ||
| navigator.navigate(NavigationCommand(CreateFolderScreenDestination(currentNodeUuid))) | ||
| } | ||
| ) | ||
| WireScaffold( | ||
| modifier = modifier, | ||
| topBar = { | ||
| WireCenterAlignedTopAppBar( | ||
| onNavigationPressed = { navigator.navigateBack() }, | ||
| title = stringResource(R.string.conversation_files_title), | ||
| navigationIconType = NavigationIconType.Close(), | ||
| title = screenTitle ?: stringResource(R.string.conversation_files_title), | ||
| navigationIconType = navigationIconType, | ||
| elevation = dimensions().spacing0x | ||
| ) | ||
| }, | ||
|
|
@@ -122,12 +152,25 @@ fun ConversationFilesScreen( | |
| ) { innerPadding -> | ||
| Box(modifier = Modifier.padding(innerPadding)) { | ||
| CellScreenContent( | ||
| actionsFlow = viewModel.actions, | ||
| actionsFlow = actions, | ||
| pagingListItems = pagingListItems, | ||
| sendIntent = { viewModel.sendIntent(it) }, | ||
| downloadFileState = viewModel.downloadFileSheet, | ||
| fileMenuState = viewModel.menu, | ||
| sendIntent = sendIntent, | ||
| downloadFileState = downloadFileSheet, | ||
| menuState = menu, | ||
| isAllFiles = false, | ||
| onFolderClick = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest to use the intent - action API and send this to a ViewModel via sendIntent, prepare the right destination and send new OpenFolder action back to the view for navigation.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's more extra work to do, pass intent from view to viewModel back to view again.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By passing it via viewmodel
ViewModel must not know about navigation implementation details, but it should define the logic for handling user actions, like: |
||
| val folderPath = "$currentNodeUuid/${it.name}" | ||
| navigator.navigate( | ||
| NavigationCommand( | ||
| ConversationFilesWithSlideInTransitionScreenDestination( | ||
| folderPath, | ||
| it.name | ||
| ), | ||
| BackStackMode.NONE, | ||
| launchSingleTop = false | ||
| ) | ||
| ) | ||
| }, | ||
| showPublicLinkScreen = { assetId, fileName, linkId -> | ||
| navigator.navigate( | ||
| NavigationCommand( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /* | ||
| * Wire | ||
| * Copyright (C) 2025 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.feature.cells.ui | ||
|
|
||
| import androidx.compose.runtime.Composable | ||
| import androidx.hilt.navigation.compose.hiltViewModel | ||
| import androidx.paging.compose.collectAsLazyPagingItems | ||
| import com.ramcosta.composedestinations.annotation.Destination | ||
| import com.wire.android.navigation.WireNavigator | ||
| import com.wire.android.navigation.style.SlideNavigationAnimation | ||
| import com.wire.android.ui.common.topappbar.NavigationIconType | ||
|
|
||
| @Destination( | ||
| style = SlideNavigationAnimation::class, | ||
| navArgsDelegate = CellFilesNavArgs::class, | ||
| ) | ||
| @Composable | ||
| fun ConversationFilesWithSlideInTransitionScreen( | ||
| navigator: WireNavigator, | ||
| cellFilesNavArgs: CellFilesNavArgs, | ||
| viewModel: CellViewModel = hiltViewModel(), | ||
| ) { | ||
|
|
||
| ConversationFilesScreenContent( | ||
| navigator = navigator, | ||
| currentNodeUuid = viewModel.currentNodeUuid(), | ||
| screenTitle = cellFilesNavArgs.screenTitle, | ||
| actions = viewModel.actions, | ||
| pagingListItems = viewModel.nodesFlow.collectAsLazyPagingItems(), | ||
| downloadFileSheet = viewModel.downloadFileSheet, | ||
| menu = viewModel.menu, | ||
| sendIntent = { viewModel.sendIntent(it) }, | ||
| navigationIconType = NavigationIconType.Back() | ||
| ) | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to use existing API for communication between View and ViewModel. You can define another CellViewIntent type OnFolderClick and use existing sendIntent method to send it to ViewModel.
Or change existing intent OnFileClick to OnNodeClick and choose the handler in the ViewModel depending on the clicked node type (file / folder).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We will not need the viewModel here as we will navigate to a different screen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe right now we do not have any extra logic, but we could have some checks in future (e.g. permissions) which would be better to do in the view model.
I guess the only real reason to handle it via the view model is to make this flow testable via view model unit tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep it simple for now—no need to over-engineer prematurely. If we need to add permission checks or more complex logic later, we can refactor and move that into the ViewModel when it makes sense.