-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It's time to get the Tutorial caught up with undeprecated API. This PR modifies only the final tutorial module. Once we're happy with the code, I'll back port the changes and update the prose in follow ups. - Use `AndroidScreen` and drop `ViewRegistry` - Use `View.setBackHandler` - Use `TextController` - More consistent naming, code style for actions and event handlers in `Screen` renderings I did not introduce `RenderContext.eventHandler {}`, that seems like it would just be confusing to a newcomer. Also not introducing big new blocks of material, in particular not introducing `Overlay`. I do think we should do that, but for this release I just want to focus on getting the deprecated code deleted.
- Loading branch information
Showing
32 changed files
with
346 additions
and
390 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
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
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
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 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.onBackClick) | ||
binding.save.setOnClickListener { rendering.onSaveClick() } | ||
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 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 onBackClick: () -> Unit, | ||
val onSaveClick: () -> Unit | ||
) : AndroidScreen<TodoEditScreen> { | ||
override val viewFactory = | ||
ScreenViewFactory.fromViewBinding(TodoEditViewBinding::inflate, ::TodoEditRunner) | ||
} |
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
14 changes: 12 additions & 2 deletions
14
samples/tutorial/tutorial-final/src/main/java/workflow/tutorial/TodoListScreen.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,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 onBackClick: () -> Unit, | ||
val onAddClick: () -> Unit | ||
): AndroidScreen<TodoListScreen> { | ||
override val viewFactory = | ||
ScreenViewFactory.fromViewBinding(TodoListViewBinding::inflate, ::TodoListScreenRunner) | ||
} |
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
15 changes: 12 additions & 3 deletions
15
samples/tutorial/tutorial-final/src/main/java/workflow/tutorial/TodoModel.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,6 +1,15 @@ | ||
package workflow.tutorial | ||
|
||
import com.squareup.workflow1.ui.TextController | ||
import com.squareup.workflow1.ui.WorkflowUiExperimentalApi | ||
|
||
@OptIn(WorkflowUiExperimentalApi::class) | ||
data class TodoModel( | ||
val title: String, | ||
val note: String | ||
) | ||
val title: TextController, | ||
val note: TextController | ||
) { | ||
constructor( | ||
title: String, | ||
note: String | ||
) : this(TextController(title), TextController(note)) | ||
} |
Oops, something went wrong.