About Those Results
Just as we have a common Action
type that wraps up a bunch of disparate actions, we have a common Result
type that wraps up a bunch of disparate results. The Controller
uses the aforementioned BehaviorSubject
to emit Result
objects to interested parties.
Result
is structured similarly to Action
, using AutoValue for immutable objects, with static
factory methods to create instances associated with each type:
package com.commonsware.android.todo.impl;
import com.google.auto.value.AutoValue;
import java.util.Collections;
import java.util.List;
public abstract class Result {
public static Result added(ToDoModel model) {
return(new AutoValue_Result_Added(model));
}
public static Result modified(ToDoModel model) {
return(new AutoValue_Result_Modified(model));
}
static Result deleted(List<ToDoModel> models) {
return(new AutoValue_Result_Deleted(Collections.unmodifiableList(models)));
}
static Result loaded(List<ToDoModel> models, FilterMode filterMode) {
return(new AutoValue_Result_Loaded(Collections.unmodifiableList(models), filterMode));
}
static Result selected(int position) {
return(new AutoValue_Result_Selected(position));
}
static Result unselected(int position) {
return(new AutoValue_Result_Unselected(position));
}
static Result unselectedAll() {
return(new AutoValue_Result_UnselectedAll());
}
static Result showed(ToDoModel current) {
return(new AutoValue_Result_Showed(current));
}
static Result filter(FilterMode mode) {
return(new AutoValue_Result_Filter(mode));
}
@AutoValue
public static abstract class Added extends Result {
public abstract ToDoModel model();
}
@AutoValue
public static abstract class Modified extends Result {
public abstract ToDoModel model();
}
@AutoValue
public static abstract class Deleted extends Result {
public abstract List<ToDoModel> models();
}
@AutoValue
static abstract class Selected extends Result {
public abstract int position();
}
@AutoValue
static abstract class Unselected extends Result {
public abstract int position();
}
@AutoValue
static abstract class UnselectedAll extends Result {
}
@AutoValue
static abstract class Showed extends Result {
public abstract ToDoModel current();
}
@AutoValue
static abstract class Filter extends Result {
public abstract FilterMode filterMode();
}
@AutoValue
public static abstract class Loaded extends Result {
public abstract List<ToDoModel> models();
public abstract FilterMode filterMode();
}
}
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.