Skip to content

Commit

Permalink
Refactor: ViewModel에서 폴더 구분
Browse files Browse the repository at this point in the history
  • Loading branch information
Guri999 committed Jan 10, 2025
1 parent 63245e6 commit f9874aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 2 additions & 2 deletions feature/explore/src/main/java/kr/co/explore/ExploreScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,15 @@ private fun ExploreScreen(
}
}

items(state.files.filter { it.isDirectory }) { folder ->
items(state.folders) { folder ->
FolderBox(
name = folder.name,
onClick = { handleIntent(ExploreUiIntent.ClickFolder(folder)) }
)
}

items(
items = state.files.filter { !it.isDirectory },
items = state.files,
span = { GridItemSpan(maxLineSpan) }
) { file ->
FileBox(
Expand Down
24 changes: 17 additions & 7 deletions feature/explore/src/main/java/kr/co/explore/ExploreViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@ internal class ExploreViewModel(
}

private fun init(path: String) = launch {
path.debugLog("path")
readPDFOrDirectory(path).let {
reduce {
copy(
path = path,
files = it
)
reduce {
copy(path = path)
}

readPDFOrDirectory(path).map { file ->
if (file.isDirectory) {
reduce {
copy(
folders = folders + file
)
}
} else {
reduce {
copy(
files = files + file
)
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions feature/explore/src/main/java/kr/co/model/ExploreUiState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import kr.co.ui.base.UiState

internal data class ExploreUiState(
val path: String,
val folders: List<FileInfo>,
val files: List<FileInfo>,
): UiState {
companion object {
val INIT = ExploreUiState(
path = "",
folders = emptyList(),
files = emptyList(),
)
}
Expand Down

0 comments on commit f9874aa

Please sign in to comment.