-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from kongwoojin/feature/mvi-migration
Migrate to MVI architecture
- Loading branch information
Showing
33 changed files
with
544 additions
and
367 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
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
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/kongjak/koreatechboard/ui/article/ArticleEvent.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 com.kongjak.koreatechboard.ui.article | ||
|
||
import com.kongjak.koreatechboard.ui.base.UiEvent | ||
import java.util.UUID | ||
|
||
sealed class ArticleEvent : UiEvent { | ||
data class FetchData(val department: String, val uuid: UUID) : ArticleEvent() | ||
} |
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/kongjak/koreatechboard/ui/article/ArticleState.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,18 @@ | ||
package com.kongjak.koreatechboard.ui.article | ||
|
||
import com.kongjak.koreatechboard.domain.model.Article | ||
import com.kongjak.koreatechboard.ui.base.UiState | ||
import com.kongjak.koreatechboard.util.routes.Department | ||
import java.util.UUID | ||
|
||
data class ArticleState( | ||
val isLoading: Boolean = false, | ||
val isLoaded: Boolean = false, | ||
val isSuccess: Boolean = false, | ||
val article: Article? = null, | ||
val uuid: UUID = UUID.randomUUID(), | ||
val department: String = Department.School.name, | ||
val statusCode: Int = 200, | ||
val url: String = "", | ||
val error: String = "" | ||
) : UiState |
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
20 changes: 20 additions & 0 deletions
20
app/src/main/java/com/kongjak/koreatechboard/ui/base/BaseViewModel.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,20 @@ | ||
package com.kongjak.koreatechboard.ui.base | ||
|
||
import androidx.lifecycle.ViewModel | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
|
||
open class BaseViewModel<S : UiState, E : UiEvent>(initialState: S) : ViewModel() { | ||
private val _uiState = MutableStateFlow(initialState) | ||
val uiState get() = _uiState.asStateFlow() | ||
|
||
fun sendEvent(event: E) { | ||
reduce(_uiState.value, event) | ||
} | ||
|
||
fun setState(newState: S) { | ||
_uiState.value = newState | ||
} | ||
|
||
open fun reduce(oldState: S, event: E) {} | ||
} |
3 changes: 3 additions & 0 deletions
3
app/src/main/java/com/kongjak/koreatechboard/ui/base/UiEvent.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,3 @@ | ||
package com.kongjak.koreatechboard.ui.base | ||
|
||
interface UiEvent |
3 changes: 3 additions & 0 deletions
3
app/src/main/java/com/kongjak/koreatechboard/ui/base/UiState.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,3 @@ | ||
package com.kongjak.koreatechboard.ui.base | ||
|
||
interface UiState |
Oops, something went wrong.