-
Notifications
You must be signed in to change notification settings - Fork 106
Modernize tutorial final code #1116
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
Closed
Closed
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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
33 changes: 0 additions & 33 deletions
33
samples/tutorial/tutorial-final/src/main/java/workflow/tutorial/TodoEditLayoutRunner.kt
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
samples/tutorial/tutorial-final/src/main/java/workflow/tutorial/TodoEditRunner.kt
This file contains hidden or 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,24 @@ | ||
package workflow.tutorial | ||
|
||
import com.squareup.workflow1.ui.ScreenViewRunner | ||
import com.squareup.workflow1.ui.ViewEnvironment | ||
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
import com.squareup.workflow1.ui.control | ||
import com.squareup.workflow1.ui.setBackHandler | ||
import workflow.tutorial.views.databinding.TodoEditViewBinding | ||
|
||
@OptIn(WorkflowUiExperimentalApi::class) | ||
class TodoEditRunner( | ||
private val binding: TodoEditViewBinding | ||
) : ScreenViewRunner<TodoEditScreen> { | ||
|
||
override fun showRendering( | ||
rendering: TodoEditScreen, | ||
environment: ViewEnvironment | ||
) { | ||
binding.root.setBackHandler(rendering.onBackPressed) | ||
binding.save.setOnClickListener { rendering.onSavePressed() } | ||
rendering.title.control(binding.todoTitle) | ||
rendering.note.control(binding.todoNote) | ||
} | ||
} |
24 changes: 15 additions & 9 deletions
24
samples/tutorial/tutorial-final/src/main/java/workflow/tutorial/TodoEditScreen.kt
This file contains hidden or 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,15 +1,21 @@ | ||
package workflow.tutorial | ||
|
||
import com.squareup.workflow1.ui.AndroidScreen | ||
import com.squareup.workflow1.ui.ScreenViewFactory | ||
import com.squareup.workflow1.ui.TextController | ||
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
import workflow.tutorial.views.databinding.TodoEditViewBinding | ||
|
||
@OptIn(WorkflowUiExperimentalApi::class) | ||
data class TodoEditScreen( | ||
/** The title of this todo item. */ | ||
val title: String, | ||
val title: TextController, | ||
/** The contents, or "note" of the todo. */ | ||
val note: String, | ||
|
||
/** Callbacks for when the title or note changes. */ | ||
val onTitleChanged: (String) -> Unit, | ||
val onNoteChanged: (String) -> Unit, | ||
val note: TextController, | ||
|
||
val discardChanges: () -> Unit, | ||
val saveChanges: () -> Unit | ||
) | ||
val onBackPressed: () -> Unit, | ||
val onSavePressed: () -> Unit | ||
) : AndroidScreen<TodoEditScreen> { | ||
override val viewFactory = | ||
ScreenViewFactory.fromViewBinding(TodoEditViewBinding::inflate, ::TodoEditRunner) | ||
} |
This file contains hidden or 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
14 changes: 12 additions & 2 deletions
14
samples/tutorial/tutorial-final/src/main/java/workflow/tutorial/TodoListScreen.kt
This file contains hidden or 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,14 +1,24 @@ | ||
package workflow.tutorial | ||
|
||
import com.squareup.workflow1.ui.AndroidScreen | ||
import com.squareup.workflow1.ui.ScreenViewFactory | ||
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
import workflow.tutorial.views.databinding.TodoListViewBinding | ||
|
||
/** | ||
* This should contain all data to display in the UI. | ||
* | ||
* It should also contain callbacks for any UI events, for example: | ||
* `val onButtonTapped: () -> Unit`. | ||
*/ | ||
@OptIn(WorkflowUiExperimentalApi::class) | ||
data class TodoListScreen( | ||
val username: String, | ||
val todoTitles: List<String>, | ||
val onTodoSelected: (Int) -> Unit, | ||
val onBack: () -> Unit | ||
) | ||
val onBackPressed: () -> Unit, | ||
val onAddPressed: () -> Unit | ||
): AndroidScreen<TodoListScreen> { | ||
override val viewFactory = | ||
ScreenViewFactory.fromViewBinding(TodoListViewBinding::inflate, ::TodoListScreenRunner) | ||
} |
This file contains hidden or 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 hidden or 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 |
---|---|---|
|
@@ -29,14 +29,15 @@ object TodoListWorkflow : StatelessWorkflow<ListProps, Output, TodoListScreen>() | |
): TodoListScreen { | ||
val titles = renderProps.todos.map { it.title } | ||
return TodoListScreen( | ||
username = renderProps.username, | ||
todoTitles = titles, | ||
onTodoSelected = { context.actionSink.send(selectTodo(it)) }, | ||
onBack = { context.actionSink.send(onBack()) } | ||
username = renderProps.username, | ||
todoTitles = titles.map { it.textValue }, | ||
onTodoSelected = { context.actionSink.send(selectTodo(it)) }, | ||
onBackPressed = { context.actionSink.send(postGoBack) }, | ||
onAddPressed = { context.actionSink.send(postNewTodo) } | ||
) | ||
} | ||
|
||
private fun onBack() = action { | ||
private val postGoBack = action { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments. |
||
// When an onBack action is received, emit a Back output. | ||
setOutput(Back) | ||
} | ||
|
@@ -46,7 +47,7 @@ object TodoListWorkflow : StatelessWorkflow<ListProps, Output, TodoListScreen>() | |
setOutput(SelectTodo(index)) | ||
} | ||
|
||
private fun new() = action { | ||
private val postNewTodo = action { | ||
// Tell our parent a new todo item should be created. | ||
setOutput(NewTodo) | ||
} | ||
|
Oops, something went wrong.
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.
nit: not understanding where the 'post' namign is coming from? I think i get that we are 'posting' either a discard or a save to our parent Workflow? Is that the intention?
I'm not sure that's helpful to me though as the name of the action.
LIke is the
action
about what it does (posting a save) or what it responds to (on "Save" clicked)? I feel like we've often used the latter, so maybe that's what is tripping me up. Maybe the former is preferrable?Maybe this is all pedantic (though if there's any place to be so, it would be the tutorial...).
I, for one, long for
Action
suffixes when we save actions like this. As in could we usediscardAction
,saveAction
-> telling you what it is (Action) and what it does (discard or save) but not the implementation details ('posting' to the parent).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 like the
*Action
notion, will adopt.Uh oh!
There was an error while loading. Please reload this page.
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.
Actually…
What I liked about the awkward
post*
names was that they communicated what was going to happen in response to the UI event. I don't think that's an implementation detail, it helps make visible what the role of this workflow is in the overall structure. And once I've put the names in that very active format, the*Action
suffix starts to sound noisy.WDYT: