-
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.
- Loading branch information
Showing
5 changed files
with
54 additions
and
14 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
38 changes: 38 additions & 0 deletions
38
...droid/app/src/main/kotlin/dev/galex/yamvil/sample/features/dashboard/DashboardFragment.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,38 @@ | ||
package dev.galex.yamvil.sample.features.dashboard | ||
|
||
import androidx.fragment.app.viewModels | ||
import dev.galex.yamvil.fragments.base.MVIFragment | ||
|
||
class DashboardFragment: MVIFragment<DashboardUiState, DashboardUiEvent, DashboardUiAction>() { | ||
|
||
override val viewModel: DashboardViewModel by viewModels() | ||
override fun observeUiState(state: DashboardUiState) { | ||
when(state.state) { | ||
DashboardUiState.ContentState.Loading -> onLoading() | ||
is DashboardUiState.ContentState.Content -> onContent(state.state) | ||
DashboardUiState.ContentState.Error -> onError() | ||
} | ||
|
||
state.onAction { action -> | ||
when(action) { | ||
DashboardUiAction.NavigateToNext -> navigateToNext() | ||
} | ||
} | ||
} | ||
|
||
private fun navigateToNext() { | ||
// Do something with navigateToNext | ||
} | ||
|
||
private fun onLoading() { | ||
// Do something with loading | ||
} | ||
|
||
private fun onContent(content: DashboardUiState.ContentState.Content) { | ||
// Do something with content | ||
} | ||
|
||
private fun onError() { | ||
// Do something with error | ||
} | ||
} |
5 changes: 2 additions & 3 deletions
5
...ndroid/app/src/main/kotlin/dev/galex/yamvil/sample/features/dashboard/DashboardUiState.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
13 changes: 10 additions & 3 deletions
13
...roid/app/src/main/kotlin/dev/galex/yamvil/sample/features/dashboard/DashboardViewModel.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 |
---|---|---|
@@ -1,13 +1,20 @@ | ||
package dev.galex.yamvil.sample.features.dashboard | ||
|
||
import dev.galex.yamvil.models.Consumable | ||
import dev.galex.yamvil.viewmodels.MVIViewModel | ||
|
||
class DashboardViewModel: MVIViewModel<DashboardUiState, DashboardUiEvent>() { | ||
override fun handleEvent(event: DashboardUiEvent) { | ||
|
||
} | ||
|
||
override fun initializeUiState(): DashboardUiState { | ||
return DashboardUiState(state = DashboardUiState.ContentState.Loading) | ||
} | ||
override fun handleEvent(event: DashboardUiEvent) { | ||
when (event) { | ||
is DashboardUiEvent.ClickOnNext -> onClickOnNext() | ||
} | ||
} | ||
|
||
private fun onClickOnNext() { | ||
update { copy(action = Consumable(DashboardUiAction.NavigateToNext)) } | ||
} | ||
} |