Step #2: Creating Some Fake Data

At the moment, our repository has no data. We need to fix this, so that we have some to-do items to show in our UI. But we have not built any forms to allow the user to create new to-do items either. So, for the time being, we can have our repository create some fake data, which we can then replace with user-supplied data later on.

To that end, replace the stub ToDoRepository that Android Studio gave us with:

package com.commonsware.todo

class ToDoRepository {
  var items = listOf(
    ToDoModel(
      description = "Buy a copy of _Exploring Android_",
      isCompleted = true,
      notes = "See https://wares.commonsware.com"
    ),
    ToDoModel(
      description = "Complete all of the tutorials"
    ),
    ToDoModel(
      description = "Write an app for somebody in my community",
      notes = "Talk to some people at non-profit organizations to see what they need!"
    )
  )
}

This just adds an items property that is a simple immutable list of three ToDoModel objects. We provide a description for all three models, but we use the default constructor options for some of the other properties.

Later, this is going to need to get a lot more complicated:

But, for the moment, this will suffice. In an upcoming tutorial, we will have our RosterListFragment get its data from this ToDoRepository singleton.


Prev Table of Contents Next

This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.