Skip to content
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

Add search in file manager #876

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions components/filemanager/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ dependencies {
implementation(projects.components.bridge.pbutils)

implementation(projects.components.filemanager.api)
implementation(projects.components.fmsearch.api)

implementation(libs.kotlin.serialization.json)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@ import com.arkivanov.decompose.value.Value
import com.flipperdevices.core.di.AppGraph
import com.flipperdevices.filemanager.api.navigation.FileManagerDecomposeComponent
import com.flipperdevices.filemanager.impl.model.FileManagerNavigationConfig
import com.flipperdevices.fmsearch.api.FMSearchDecomposeComponent
import com.flipperdevices.ui.decompose.DecomposeComponent
import com.flipperdevices.ui.decompose.DecomposeOnBackParameter
import com.flipperdevices.ui.decompose.popOr
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import me.gulya.anvil.assisted.ContributesAssistedFactory

@Suppress("LongParameterList")
@ContributesAssistedFactory(AppGraph::class, FileManagerDecomposeComponent.Factory::class)
class FileManagerDecomposeComponentImpl @AssistedInject constructor(
@Assisted componentContext: ComponentContext,
@Assisted private val onBack: DecomposeOnBackParameter,
private val fileManagerListingFactory: FileManagerListingComponent.Factory,
private val fileManagerUploadingFactory: FileManagerUploadingComponent.Factory,
private val fileManagerEditingFactory: FileManagerEditingComponent.Factory,
private val fileManagerDownloadFactory: FileManagerDownloadComponent.Factory
private val fileManagerDownloadFactory: FileManagerDownloadComponent.Factory,
private val searchFileManagerFactory: FMSearchDecomposeComponent.Factory
) : FileManagerDecomposeComponent<FileManagerNavigationConfig>(),
ComponentContext by componentContext {

Expand Down Expand Up @@ -61,5 +64,11 @@ class FileManagerDecomposeComponentImpl @AssistedInject constructor(
config,
onBack = { navigation.popOr(onBack::invoke) }
)

is FileManagerNavigationConfig.Search -> searchFileManagerFactory(
componentContext = componentContext,
onBackParameter = { navigation.popOr(onBack::invoke) },
path = config.path
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ class FileManagerListingComponent @AssistedInject constructor(
deeplinkContent = content
)
)
},
onClickToSearch = {
navigation.pushToFront(FileManagerNavigationConfig.Search(config.path))
}
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ fun ComposableFileManagerScreen(
onOpenFolder: (FileItem) -> Unit,
onDownloadAndShareFile: (FileItem) -> Unit,
onOpenEditor: (FileItem) -> Unit,
onUploadFile: (path: String, DeeplinkContent) -> Unit
onUploadFile: (path: String, DeeplinkContent) -> Unit,
onClickToSearch: () -> Unit
) {
val fileManagerState by fileManagerViewModel.getFileManagerState().collectAsState()

Expand Down Expand Up @@ -89,7 +90,8 @@ fun ComposableFileManagerScreen(
},
onAddButton = {
showAddDialog = true
}
},
onClickToSearch = onClickToSearch
)
}

Expand Down Expand Up @@ -139,7 +141,8 @@ private fun ComposableFileManagerScreenInternal(
onOpenFolder: (FileItem) -> Unit,
deepLinkParser: DeepLinkParser,
onUploadFile: (DeeplinkContent) -> Unit,
onAddButton: () -> Unit
onAddButton: () -> Unit,
onClickToSearch: () -> Unit
) {
val context = LocalContext.current

Expand Down Expand Up @@ -167,7 +170,8 @@ private fun ComposableFileManagerScreenInternal(
onClickUploadButton = {
pickFileLauncher.launch("*/*")
},
onClickAddButton = onAddButton
onClickAddButton = onAddButton,
onClickToSearch = onClickToSearch
)
}
) { scaffoldPaddings ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fun ComposableFileManagerTopBar(
path: String,
onClickUploadButton: () -> Unit,
onClickAddButton: () -> Unit,
onClickToSearch: () -> Unit,
modifier: Modifier = Modifier
) {
TopAppBar(
Expand All @@ -32,8 +33,8 @@ fun ComposableFileManagerTopBar(
)
},
actions = {
if (isAbleToSave(path)) {
Row {
Row {
if (isAbleToSave(path)) {
IconButton(onClick = onClickAddButton) {
Icon(
painter = painterResource(
Expand All @@ -55,6 +56,14 @@ fun ComposableFileManagerTopBar(
)
}
}
if (path != "/") {
IconButton(onClick = onClickToSearch) {
Icon(
painter = painterResource(DesignSystem.drawable.ic_search),
contentDescription = null
)
}
}
}
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ fun ComposableFileManagerContent(
private fun ComposableFileManagerPreview() {
ComposableFileManagerContent(
fileManagerState = FileManagerState(
"/",
"/Test",
persistentSetOf(
FileItem.DUMMY_FOLDER,
FileItem.DUMMY_FILE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@ sealed class FileManagerNavigationConfig {
val path: String,
val shareFile: ShareFile
) : FileManagerNavigationConfig()

@Serializable
data class Search(
val path: String
) : FileManagerNavigationConfig()
}
1 change: 1 addition & 0 deletions components/fmsearch/api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
10 changes: 10 additions & 0 deletions components/fmsearch/api/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
plugins {
id("flipper.android-lib")
}

android.namespace = "com.flipperdevices.fmsearch.api"

dependencies {
implementation(projects.components.core.ui.decompose)
implementation(libs.bundles.decompose)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.flipperdevices.fmsearch.api

import com.arkivanov.decompose.ComponentContext
import com.flipperdevices.ui.decompose.DecomposeOnBackParameter
import com.flipperdevices.ui.decompose.ScreenDecomposeComponent

abstract class FMSearchDecomposeComponent(
componentContext: ComponentContext
) : ScreenDecomposeComponent(componentContext) {
fun interface Factory {
operator fun invoke(
componentContext: ComponentContext,
onBackParameter: DecomposeOnBackParameter,
path: String
): FMSearchDecomposeComponent
}
}
1 change: 1 addition & 0 deletions components/fmsearch/impl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
32 changes: 32 additions & 0 deletions components/fmsearch/impl/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins {
id("flipper.android-compose")
id("flipper.anvil")
}

android.namespace = "com.flipperdevices.fmsearch.impl"

dependencies {
implementation(projects.components.fmsearch.api)

implementation(projects.components.core.di)
implementation(projects.components.core.ui.theme)
implementation(projects.components.core.ui.decompose)
implementation(projects.components.core.ui.lifecycle)
implementation(projects.components.core.ui.ktx)
implementation(projects.components.core.ui.res)
implementation(projects.components.core.ui.searchbar)
implementation(projects.components.core.ktx)

// Compose
implementation(libs.compose.ui)
implementation(libs.compose.tooling)
implementation(libs.compose.foundation)
implementation(libs.compose.material)

implementation(projects.components.bridge.api)
implementation(projects.components.bridge.service.api)
implementation(projects.components.bridge.pbutils)

implementation(libs.bundles.decompose)
implementation(libs.kotlin.immutable.collections)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.flipperdevices.fmsearch.impl.api

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.CircularProgressIndicator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.arkivanov.decompose.ComponentContext
import com.flipperdevices.core.di.AppGraph
import com.flipperdevices.core.ui.lifecycle.viewModelWithFactoryWithoutRemember
import com.flipperdevices.core.ui.searchbar.ComposableSearchBar
import com.flipperdevices.core.ui.theme.LocalPallet
import com.flipperdevices.fmsearch.api.FMSearchDecomposeComponent
import com.flipperdevices.fmsearch.impl.R
import com.flipperdevices.fmsearch.impl.composable.SearchItemComposable
import com.flipperdevices.fmsearch.impl.viewmodel.FMSearchViewModel
import com.flipperdevices.ui.decompose.DecomposeOnBackParameter
import dagger.assisted.Assisted
import dagger.assisted.AssistedInject
import me.gulya.anvil.assisted.ContributesAssistedFactory

@ContributesAssistedFactory(AppGraph::class, FMSearchDecomposeComponent.Factory::class)
class FMSearchDecomposeComponentImpl @AssistedInject constructor(
@Assisted componentContext: ComponentContext,
@Assisted private val onBackParameter: DecomposeOnBackParameter,
@Assisted private val path: String,
private val searchViewModelFactory: FMSearchViewModel.Factory
) : FMSearchDecomposeComponent(componentContext) {
private val searchViewModel = viewModelWithFactoryWithoutRemember(path) {
searchViewModelFactory(path)
}

@Composable
override fun Render() {
Column {
ComposableSearchBar(
hint = stringResource(R.string.fm_search_hint),
onBack = onBackParameter::invoke,
onChangeText = searchViewModel::search
)
val result by searchViewModel.getSearchResult().collectAsState()
LazyColumn(horizontalAlignment = Alignment.CenterHorizontally) {
items(result.items) { item ->
SearchItemComposable(
modifier = Modifier.fillMaxWidth(),
searchItem = item
)
}
if (result.inProgress) {
item {
Box(
modifier = Modifier
.fillMaxWidth()
.height(64.dp),
contentAlignment = Alignment.Center
) {
CircularProgressIndicator(color = LocalPallet.current.accentSecond)
}
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.flipperdevices.fmsearch.impl.composable

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.Icon
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.flipperdevices.core.ui.ktx.image.painterResourceByKey
import com.flipperdevices.fmsearch.impl.R
import com.flipperdevices.fmsearch.impl.model.SearchItem

@Composable
fun SearchItemComposable(
searchItem: SearchItem,
modifier: Modifier = Modifier,
) = Row(modifier) {
Icon(
modifier = Modifier
.padding(all = 8.dp)
.size(48.dp),
painter = painterResourceByKey(
id = if (searchItem.isFolder) {
R.drawable.ic_folder
} else {
R.drawable.ic_file
}
),
contentDescription = null
)
Column(modifier = Modifier.padding(vertical = 8.dp)) {
Text(
modifier = Modifier.padding(end = 8.dp),
style = MaterialTheme.typography.h5,
text = searchItem.name
)

Text(
style = MaterialTheme.typography.h5,
text = searchItem.path
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.flipperdevices.fmsearch.impl.model

data class SearchItem(
val name: String,
val path: String,
val isFolder: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.flipperdevices.fmsearch.impl.model

import kotlinx.collections.immutable.ImmutableList

data class SearchResult(
val inProgress: Boolean,
val items: ImmutableList<SearchItem>
)
Loading
Loading