Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class ToDoPresenter @Inject constructor(val taskDao: TaskDao) {
var tasks = ArrayList<Task>()
var presentation: ToDoPresentation? = null
fun onCreate(toDoPresentation: ToDoPresentation) {
presentation = toDoPresentation
loadTasks()
}
fun onDestroy() {
presentation = null
}
fun loadTasks() {
tasks.clear()
tasks.addAll(taskDao.getAllTasks())
presentation?.showTasks(tasks)
}
fun addNewTask(taskDescription: String) {
val newTask = Task(description = taskDescription)
tasks.add(newTask)
taskDao.insertTask(newTask)
(tasks.size - 1).let {
presentation?.taskAddedAt(it)
presentation?.scrollTo(it)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment