-
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.
CHANGE to use type-safe view state to avoid illegal states
- Loading branch information
1 parent
2251484
commit 2042b01
Showing
4 changed files
with
29 additions
and
28 deletions.
There are no files selected for viewing
7 changes: 4 additions & 3 deletions
7
data/user/src/main/kotlin/nl/q42/template/data/user/local/UserLocalDataSource.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
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
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 |
---|---|---|
|
@@ -30,13 +30,16 @@ internal fun HomeContent( | |
horizontalAlignment = CenterHorizontally, | ||
) { | ||
|
||
/** | ||
* This is dummy. Use the strings file IRL. | ||
*/ | ||
viewState.userEmailTitle?.get()?.let { Text(text = it) } | ||
|
||
if (viewState.isLoading) CircularProgressIndicator() | ||
if (viewState.showError) Text(text = "Error") | ||
when(viewState) { | ||
is HomeViewState.Content -> { | ||
/** | ||
* This is dummy. Use the strings file IRL. | ||
*/ | ||
Text(text = viewState.userEmailTitle.get()) | ||
} | ||
HomeViewState.Loading -> CircularProgressIndicator() | ||
HomeViewState.Error -> Text(text = "Error") | ||
} | ||
|
||
Button(onClick = onLoadClicked) { | ||
Text("Refresh") | ||
|
@@ -55,22 +58,22 @@ internal fun HomeContent( | |
@Composable | ||
private fun HomeContentErrorPreview() { | ||
PreviewAppTheme { | ||
HomeContent(HomeViewState(showError = true), {}, {}, {}) | ||
HomeContent(HomeViewState.Error, {}, {}, {}) | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
private fun HomeContentLoadingPreview() { | ||
PreviewAppTheme { | ||
HomeContent(HomeViewState(isLoading = true), {}, {}, {}) | ||
HomeContent(HomeViewState.Loading, {}, {}, {}) | ||
} | ||
} | ||
|
||
@PreviewLightDark | ||
@Composable | ||
private fun HomeContentEmptyPreview() { | ||
PreviewAppTheme { | ||
HomeContent(HomeViewState(userEmailTitle = "[email protected]".toViewStateString()), {}, {}, {}) | ||
HomeContent(HomeViewState.Content(userEmailTitle = "[email protected]".toViewStateString()), {}, {}, {}) | ||
} | ||
} |