package jackall.moncalc.fragment import android.arch.lifecycle.ViewModelProviders import android.databinding.DataBindingUtil import android.os.Bundle import android.support.v4.app.Fragment import android.support.v7.widget.DefaultItemAnimator import android.support.v7.widget.LinearLayoutManager import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import jackall.moncalc.R import jackall.moncalc.adapter.HistoryRecyclerAdapter import jackall.moncalc.databinding.FragmentHistoryBinding import kotlinx.android.synthetic.main.fragment_history.view.* /** * Created by matsumoto_k on 2017/11/03. */ class HistoryFragment : Fragment() { lateinit var binding: FragmentHistoryBinding val historyViewModel by lazy { ViewModelProviders.of(this, jackall.moncalc.viewmodel.HistoryViewModel.Factory(adapter)).get(jackall.moncalc.viewmodel.HistoryViewModel::class.java) } val adapter by lazy { HistoryRecyclerAdapter(activity) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) } override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { binding = DataBindingUtil.inflate<FragmentHistoryBinding>(layoutInflater, R.layout.fragment_history, container, false) binding.historyViewModel = historyViewModel lifecycle.addObserver(historyViewModel) binding.root.history_recycler_view.setHasFixedSize(true) binding.root.history_recycler_view.layoutManager = LinearLayoutManager(activity) (binding.root.history_recycler_view.itemAnimator as DefaultItemAnimator).supportsChangeAnimations = false binding.root.history_recycler_view.adapter = adapter return binding.root } }