Newer
Older
ToDoApp / app / src / main / java / keijumt / todoapp / addtask / AddEditTaskViewModel.kt
package keijumt.todoapp.addtask

import android.databinding.ObservableField
import keijumt.todoapp.BaseViewModel
import keijumt.todoapp.data.db.entity.Task
import keijumt.todoapp.data.repository.TaskRepository
import keijumt.todoapp.databinding.SingleLiveEvent
import javax.inject.Inject

/**
 * タスク追加のViewModel
 * Created by matsumoto_k on 2018/03/06.
 */
class AddEditTaskViewModel @Inject constructor(
        val repository: TaskRepository
) : BaseViewModel() {

    val taskTitle = ObservableField<String>("")
    val taskDetails = ObservableField<String>("")
    val taskAddEvent = SingleLiveEvent<Void>()

    fun onClickSave() {
        val task = Task(
                title = taskTitle.get(),
                details = taskDetails.get()
        )
        repository.save(task)
        taskAddEvent.call()
    }
}