Todo App - Android

The Todo application uses Suas to add, mark as done, delete and move an item in a to-do list. In our example, the list of todos is represented by a RecyclerView using an implementation of ItemTouchHelper to handle the swipe to delete and drag to move gestures. Also, it uses the TodoListAdapter to bind our State to the views. (Check the Todo application source code on GitHub)

Below is the MainActivity used in our todo application.

public class MainActivity extends AppCompatActivity implements Listener<TodoList>{

    private Store store;
    private TodoListAdapter todoListAdapter;

    protected void onCreate(Bundle savedInstanceState) {

        final RecyclerView todoList = findViewById(;
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);

        todoListAdapter = new TodoListAdapter(new ArrayList<>());


        store = Suas.createStore(new TodoReducer())
                .withMiddleware(monitorMiddleware, loggerMiddleware)


    protected void onStart() {
        store.addListener(TodoList.class, this);

    protected void onStop() {

    public void update(@NonNull TodoList todoList) {

The MainActivity first initializes the RecyclerView, TodoListAdapter and Store during onCreate(). Then, it adds itself as a Listener<TodoItem> during onStart() and removes itself during onStop().By doing this, the MainActivity receives all the updates in the update(@NonNull TodoList todoList) method.

All updates to the list happens in the update(@NonNull TodoList todoList) method, when todoListAdapter.update(todoList.getItems()) is called. Then the TodoListAdapter displays the new State:

void update(List<TodoItem> items) {

Different parts of the app dispatch Actions to the Store. Todo items are created by reading the input from the EditText when clicking Add Item.

public void onClick(View view) {
    String newTitle = newItemInput.getText().toString();
    Action addAction = ActionFactory.addAction(newTitle);


Then, items are marked as done by dispatching toggle Actions to the Store in the ViewHolder.

ViewHolder(View view) {

    titleLabel = view.findViewById(;
    checkBox = view.findViewById(;

    view.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            Action toggleAction = ActionFactory.toggleAction(getAdapterPosition());

All Actions related to gestures are dispatched in the ItemTouchHelper:

ItemTouchHelper itemTouchHelper = new ItemTouchHelper(
        new ItemTouchHelper.SimpleCallback(
                ItemTouchHelper.UP | ItemTouchHelper.DOWN,
                ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

            public boolean isLongPressDragEnabled() {
                return true;

            public boolean onMove(RecyclerView recyclerView,
                    ViewHolder viewHolder, ViewHolder target) {

                final int fromPos = viewHolder.getAdapterPosition();
                final int toPos = target.getAdapterPosition();

                Pair<Integer, Integer> fromToPositions = new Pair<>(fromPos, toPos);
                Action moveAction = ActionFactory.moveAction(fromToPositions);

                return true;

            public boolean isItemViewSwipeEnabled() {
                return true;

            public void onSwiped(ViewHolder viewHolder, int direction) {
                Action deleteAction = ActionFactory

What's Next

Todo application source code on GitHub

Learn more about Suas listeners

Suas listeners
Using the StateSelector
Adding a listener with a filter

Other sample apps

List of sample applications
Counter App Example
Todo app with settings example
Search Cities Example