-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Use type safe view states #73
Open
sebaslogen
wants to merge
3
commits into
main
Choose a base branch
from
feature/use-type-safe-view-states
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
*.iml | ||
.gradle | ||
.kotlin | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
|
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()), {}, {}, {}) | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe sealed ViewStates are inconvenient in usage. I tried it a few times, but always move away from them eventually, when not doing SDUI. Some of the reasons:
Unless you have a fix for this, I believe with the old ViewState you are more flexible and have to write less code to change values in the content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, I hadn't though on the perspective of SDUI vs non-SDUI.
My ideas through the reasons with your new perspective of non-SDUI apps:
The advantage here is that dev has to make an explicit decision about which type of loader (s)he wants to show, making the case of showing a PTR loader when there is no content impossible.
In this scenario, normally full-screen-errors are just a simple boolean, and transient-errors (like snackbars) can contain more complex logic like a message plus an action of a more complex type. So this distinction is an advantage.
instead of just
Is this understanding correct? Please correct me if I misunderstood this point. Otherwise, this is my proposed solution:
Since we can only modify content once we already have content, we can start those functions with a check, either a soft one or a hard one:
This has the advantage of making the code simple and readable but still able to catch bugs faster.
Let me know what you think of these solutions and if you think we can reach a more convenient and also safe solution.