Newer
Older
MonCalc / app / src / main / kotlin / jackall / moncalc / fragment / HistoryFragment.kt
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.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.gms.ads.AdSize
import jackall.moncalc.Const
import jackall.moncalc.R
import jackall.moncalc.adapter.HistoryRecyclerAdapter
import jackall.moncalc.databinding.FragmentHistoryBinding
import jackall.moncalc.utils.AdUtil
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()).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
    }

    override fun onStart() {
        super.onStart()
        AdUtil.startBannerAd(activity, binding.root.history_rectangle_banner_layout, AdSize.MEDIUM_RECTANGLE, Const.historyRectangleBannerUnitId)
    }
}