-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
139 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package kr.co.di | ||
|
||
import kr.co.explore.ExploreViewModel | ||
import org.koin.core.module.dsl.viewModel | ||
import org.koin.dsl.module | ||
|
||
val exploreModule = | ||
module { | ||
viewModel { | ||
ExploreViewModel( | ||
get() | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
feature/explore/src/main/java/kr/co/explore/ExploreViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package kr.co.explore | ||
|
||
import kr.co.data.repository.RecentRepository | ||
import kr.co.model.ExploreSideEffect | ||
import kr.co.model.ExploreUiIntent | ||
import kr.co.model.ExploreUiState | ||
import kr.co.model.FileInfo | ||
import kr.co.ui.base.BaseMviViewModel | ||
import kr.co.util.readPDFOrDirectory | ||
|
||
internal class ExploreViewModel( | ||
private val recentRepository: RecentRepository, | ||
) : | ||
BaseMviViewModel<ExploreUiState, ExploreUiIntent, ExploreSideEffect>(ExploreUiState.INIT) { | ||
|
||
override fun handleIntent(intent: ExploreUiIntent) { | ||
when (intent) { | ||
is ExploreUiIntent.Init -> init(intent.path) | ||
is ExploreUiIntent.ClickFile -> onClickFile(intent.file) | ||
is ExploreUiIntent.ClickFolder -> onClickFolder(intent.folder) | ||
} | ||
} | ||
|
||
private fun init(path: String) = launch { | ||
path.debugLog("path") | ||
readPDFOrDirectory(path).let { | ||
reduce { | ||
copy( | ||
path = path, | ||
files = it | ||
) | ||
} | ||
} | ||
} | ||
|
||
private fun onClickFile(file: FileInfo) = launch { | ||
recentRepository.insert(file) | ||
}.invokeOnCompletion { | ||
postSideEffect(ExploreSideEffect.NavigateToPdf(file.path)) | ||
} | ||
|
||
private fun onClickFolder(folder: FileInfo) = | ||
postSideEffect(ExploreSideEffect.NavigateToFolder(folder.path)) | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
feature/explore/src/main/java/kr/co/model/ExploreSideEffect.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package kr.co.model | ||
|
||
import kr.co.ui.base.UiSideEffect | ||
|
||
internal sealed interface ExploreSideEffect: UiSideEffect { | ||
data class NavigateToFolder(val path: String) : ExploreSideEffect | ||
data class NavigateToPdf(val path: String) : ExploreSideEffect | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package kr.co.model | ||
|
||
import kr.co.ui.base.UiIntent | ||
|
||
internal sealed interface ExploreUiIntent: UiIntent { | ||
data class Init(val path: String): ExploreUiIntent | ||
data class ClickFile(val file: FileInfo): ExploreUiIntent | ||
data class ClickFolder(val folder: FileInfo): ExploreUiIntent | ||
} |
15 changes: 15 additions & 0 deletions
15
feature/explore/src/main/java/kr/co/model/ExploreUiState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package kr.co.model | ||
|
||
import kr.co.ui.base.UiState | ||
|
||
internal data class ExploreUiState( | ||
val path: String, | ||
val files: List<FileInfo>, | ||
): UiState { | ||
companion object { | ||
val INIT = ExploreUiState( | ||
path = "", | ||
files = emptyList(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters