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

import android.arch.lifecycle.ViewModelProviders
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import keijumt.todoapp.R
import keijumt.todoapp.databinding.FragmentAddEditTaskBinding
import keijumt.todoapp.di.Injectable
import keijumt.todoapp.di.ViewModelFactory
import javax.inject.Inject

/**
 * タスク追加のFragment
 * Created by matsumoto_k on 2018/03/06.
 */
class AddEditTaskFragment : Fragment(), Injectable {

    @Inject
    lateinit var viewModelFactory: ViewModelFactory

    lateinit var binding: FragmentAddEditTaskBinding
    lateinit var addEditTaskViewModel: AddEditTaskViewModel

    override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_add_edit_task, null, false)
        addEditTaskViewModel = ViewModelProviders.of(activity, viewModelFactory).get(AddEditTaskViewModel::class.java)
        binding.addEditTaskViewModel = addEditTaskViewModel
        lifecycle.addObserver(addEditTaskViewModel)
        return binding.root
    }
}