The following is the first few sections of a chapter from Exploring Android, plus headings for the remaining major sections, to give you an idea about the content of the chapter.


Defining Results

The final leg of the MVI flow is to have our Controller let other parties – notably, the RosterViewModel — know about changes that were made to our data. That will allow the RosterViewModel to fill the “Reducer” role from the MVI diagram, delivering a fresh ViewState to our “View”:

MVI Flow Diagram. Again.
Figure 182: MVI Flow Diagram. Again.

In this tutorial, we will just set up a Result class. In the next tutorial, we will have the Controller publish results, have the RosterViewModel subscribe to find out about those results, and deliver new ViewState objects based upon those results.

This tutorial is going to feel a lot like the tutorial where we defined the Action class. In this app, actions and results have a near 1:1 mapping. That is not always the case, though. For example, we could have had a dedicated Checked action, for when the user checks the CheckBox for an item. The Controller would handle creating the revised ToDoModel and updating the repository. However, the RosterViewModel does not care whether a ToDoModel changed because of a CheckBox in the list, the EditFragment, or something else. So, we would have the same result for two separate actions.

This is a continuation of the work we did in the previous tutorial. The book’s GitHub repository contains the results of the previous tutorial as well as the results of completing the work in this tutorial.

Step #1: Creating the Base Result Class

One more time, create a new Java class, by right-clicking over the com.commonsware.todo package in the java/ directory and choose “New” > “Java Class” from the context menu. For the name, fill in Result. Mark it as abstract, then click OK to create the class, giving you:

package com.commonsware.todo;

public abstract class Result {
}

Step #2: Defining Specific Results

The preview of this section took that left turn at Albuquerque.

Step #3: Building Factory Methods

The preview of this section apparently resembled a Pokémon.

What We Changed

The preview of this section is being chased by zombies.