Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.wire.android.di.KaliumCoreLogic
import com.wire.kalium.cells.CellsScope
import com.wire.kalium.cells.domain.CellUploadManager
import com.wire.kalium.cells.domain.usecase.AddAttachmentDraftUseCase
import com.wire.kalium.cells.domain.usecase.CreateFolderUseCase
import com.wire.kalium.cells.domain.usecase.DeleteCellAssetUseCase
import com.wire.kalium.cells.domain.usecase.DownloadCellFileUseCase
import com.wire.kalium.cells.domain.usecase.GetCellFilesUseCase
Expand Down Expand Up @@ -120,4 +121,8 @@ class CellsModule {
@ViewModelScoped
@Provides
fun provideRetryAttachmentUploadUseCase(cellsScope: CellsScope): RetryAttachmentUploadUseCase = cellsScope.retryAttachmentUpload

@ViewModelScoped
@Provides
fun provideCreateFolderUseCase(cellsScope: CellsScope): CreateFolderUseCase = cellsScope.createFolderUseCase
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal fun NavController.navigateToItem(command: NavigationCommand) {
BackStackMode.NONE -> {
}
}
launchSingleTop = true
launchSingleTop = command.launchSingleTop
restoreState = true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.wire.android.navigation
import com.ramcosta.composedestinations.spec.DestinationSpec
import com.ramcosta.composedestinations.spec.NavGraphSpec
import com.wire.android.feature.cells.ui.destinations.ConversationFilesScreenDestination
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.sketch.destinations.DrawingCanvasScreenDestination
Expand All @@ -32,6 +33,7 @@ object WireMainNavGraph : NavGraphSpec {
.plus(DrawingCanvasScreenDestination)
.plus(PublicLinkScreenDestination)
.plus(ConversationFilesScreenDestination)
.plus(ConversationFilesWithSlideInTransitionScreenDestination)
.plus(CreateFolderScreenDestination)
override val destinationsByRoute = destinations.associateBy { it.route }
override val nestedNavGraphs = NavGraphs.root.nestedNavGraphs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ fun AttachmentDraftView(
) {

val extension = remember(attachment.fileName) { attachment.fileName.fileExtension() ?: "" }
val fileType = remember(extension) { AttachmentFileType.fromExtension(extension) }
val attachmentFileType = remember(extension) { AttachmentFileType.fromExtension(extension) }

AttachmentScaffold(
onClick = onClick,
onMenuButtonClick = onMenuButtonClick,
showMenuButton = attachment.uploadError,
modifier = modifier,
) {
when (fileType) {
when (attachmentFileType) {
AttachmentFileType.IMAGE -> AttachmentImageView(
attachment = attachment,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fun FileHeaderView(
labelColor: Color? = null,
isError: Boolean = false,
) {
val fileType = type ?: remember(extension) { AttachmentFileType.fromExtension(extension) }
val attachmentFileType = type ?: remember(extension) { AttachmentFileType.fromExtension(extension) }
val sizeString = remember(size) { size?.let { DeviceUtil.formatSize(size) } ?: "" }

Row(
Expand All @@ -72,7 +72,7 @@ fun FileHeaderView(
} else {
Image(
modifier = Modifier.size(dimensions().spacing16x),
painter = painterResource(id = fileType.icon()),
painter = painterResource(id = attachmentFileType.icon()),
contentDescription = null,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.constraintlayout.compose.ConstraintLayout
import com.wire.android.R
import com.wire.android.model.Clickable
import com.wire.android.feature.cells.domain.model.AttachmentFileType
import com.wire.android.model.Clickable
import com.wire.android.ui.common.attachmentdraft.ui.FileHeaderView
import com.wire.android.ui.common.clickable
import com.wire.android.ui.common.colorsScheme
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import androidx.compose.runtime.mutableStateMapOf
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wire.android.appLogger
import com.wire.android.feature.cells.domain.model.AttachmentFileType
import com.wire.android.feature.cells.domain.model.AttachmentFileType.IMAGE
import com.wire.android.feature.cells.domain.model.AttachmentFileType.PDF
import com.wire.android.feature.cells.domain.model.AttachmentFileType.VIDEO
import com.wire.android.feature.cells.domain.model.AttachmentFileType
import com.wire.android.ui.common.multipart.AssetSource
import com.wire.android.ui.common.multipart.MultipartAttachmentUi
import com.wire.android.ui.common.multipart.toUiModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ data class NavigationCommand(
* Whether we want to clear the previously added screens on the backstack, only until the current one, or none of them.
*/
val backStackMode: BackStackMode = BackStackMode.NONE,

/**
* Whether we want to clear the backstack of the current graph.
*/
val launchSingleTop: Boolean = true
)

enum class BackStackMode {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package com.wire.android.feature.cells.domain.model

import com.wire.android.feature.cells.R

enum class AttachmentFileType(private val extensions: List<String>) {
enum class AttachmentFileType(val extensions: List<String>) {
IMAGE(listOf("jpg", "jpeg", "png", "gif", "webp")),
VIDEO(listOf("mp4", "mov", "m4v", "ogv", "webm")),
AUDIO(listOf("mp3", "wav", "ogg", "m4a", "flac", "aac")),
Expand All @@ -30,25 +30,18 @@ enum class AttachmentFileType(private val extensions: List<String>) {
ARCHIVE(listOf("zip", "rar", "7z", "tar", "gz", "bz2", "xz", "z")),
CODE(
listOf(
"xml", "html", "htm", "js", "json", "css", "PHP", "phtml", "sparql",
"xml", "html", "htm", "js", "json", "css", "php", "phtml", "sparql",
"py", "cs", "java", "jsp", "sql", "cgi", "pl", "inc", "xsl", "c", "cpp", "kt"
)
),
OTHER(emptyList());

companion object {
fun fromExtension(extension: String): AttachmentFileType {
entries.forEach { type ->
if (extension.lowercase() in type.extensions) {
return type
}
}

return OTHER
}
fun fromExtension(ext: String): AttachmentFileType =
entries.firstOrNull { it.extensions.contains(ext.lowercase()) } ?: OTHER

fun fromMimeType(mimeType: String): AttachmentFileType {
return fromExtension(mimeType.substringAfterLast("/"))
return AttachmentFileType.fromExtension(mimeType.substringAfterLast("/"))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fun AllFilesScreen(
viewModel: CellViewModel = hiltViewModel(),
) {

val pagingListItems = viewModel.filesFlow.collectAsLazyPagingItems()
val pagingListItems = viewModel.nodesFlow.collectAsLazyPagingItems()

LaunchedEffect(searchBarState.searchQueryTextState.text) {
if (searchBarState.searchQueryTextState.text.isNotEmpty()) {
Expand All @@ -60,8 +60,11 @@ fun AllFilesScreen(
actionsFlow = viewModel.actions,
pagingListItems = pagingListItems,
sendIntent = { viewModel.sendIntent(it) },
onFolderClick = {
Copy link
Contributor

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).

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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.

// TODO: Handle folder click later
},
downloadFileState = viewModel.downloadFileSheet,
fileMenuState = viewModel.menu,
menuState = viewModel.menu,
isAllFiles = true,
isSearchResult = viewModel.hasSearchQuery(),
showPublicLinkScreen = { assetId, fileName, linkId ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
*/
package com.wire.android.feature.cells.ui

data class CellFilesNavArgs(val conversationId: String? = null)
data class CellFilesNavArgs(
val conversationId: String? = null,
val screenTitle: String? = null
)

Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.wire.android.feature.cells.domain.model.AttachmentFileType
import com.wire.android.feature.cells.ui.model.CellNodeUi
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.paging.LoadState
import androidx.paging.compose.LazyPagingItems
import androidx.paging.compose.itemContentType
import androidx.paging.compose.itemKey
import com.wire.android.feature.cells.R
import com.wire.android.feature.cells.ui.model.CellFileUi
import com.wire.android.feature.cells.ui.util.PreviewMultipleThemes
import com.wire.android.ui.common.button.WireSecondaryButton
import com.wire.android.ui.common.colorsScheme
Expand All @@ -52,9 +53,9 @@ import com.wire.android.ui.theme.WireTheme

@Composable
internal fun CellFilesScreen(
files: LazyPagingItems<CellFileUi>,
onFileClick: (CellFileUi) -> Unit,
onFileMenuClick: (CellFileUi) -> Unit,
cellNodes: LazyPagingItems<CellNodeUi>,
onItemClick: (CellNodeUi) -> Unit,
onItemMenuClick: (CellNodeUi) -> Unit,
) {

LazyColumn(
Expand All @@ -63,28 +64,28 @@ internal fun CellFilesScreen(
.fillMaxWidth(),
) {
items(
count = files.itemCount,
key = files.itemKey { it.uuid },
contentType = files.itemContentType { it }
count = cellNodes.itemCount,
key = cellNodes.itemKey { it.uuid },
contentType = cellNodes.itemContentType { it }
) { index ->

files[index]?.let { file ->
cellNodes[index]?.let { item ->
CellListItem(
modifier = Modifier
.animateItem()
.background(color = colorsScheme().surface)
.clickable { onFileClick(file) },
file = file,
onMenuClick = { onFileMenuClick(file) }
.clickable { onItemClick(item) },
cell = item,
onMenuClick = { onItemMenuClick(item) }
)
WireDivider(modifier = Modifier.fillMaxWidth())
}
}

when (files.loadState.append) {
when (cellNodes.loadState.append) {
is LoadState.Error -> item(contentType = "error") {
ErrorFooter(
onRetry = { files.retry() }
onRetry = { cellNodes.retry() }
)
}

Expand Down
Loading