Newer
Older
OverlayMultiCounter / app / src / main / kotlin / jackall / overlaymulticounter / activity / MainActivity.kt
MatsumotoKeiju on 10 Nov 2017 1 KB [add] Main ad of banner
package jackall.overlaymulticounter.activity

import android.arch.lifecycle.ViewModelProviders
import android.databinding.DataBindingUtil
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.google.android.gms.ads.AdSize
import jackall.overlaymulticounter.Const
import jackall.overlaymulticounter.R
import jackall.overlaymulticounter.databinding.ActivityMainBinding
import jackall.overlaymulticounter.db.CounterRealmHelper
import jackall.overlaymulticounter.utils.AdUtil
import jackall.overlaymulticounter.viewmodel.MainViewModel
import jackall.overlaymulticounter.vo.Counter
import kotlinx.android.synthetic.main.activity_main.view.*

class MainActivity : AppCompatActivity() {

    lateinit var binding: ActivityMainBinding
    lateinit var mainViewModel: MainViewModel

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
        mainViewModel = ViewModelProviders.of(this, MainViewModel.Factory()).get(MainViewModel::class.java)
        binding.mainViewModel = mainViewModel
        lifecycle.addObserver(mainViewModel)

        if (CounterRealmHelper().getNextId() == 0) {
            CounterRealmHelper().insert(
                    Counter(CounterRealmHelper().getNextId(),
                            "Counter0",
                            0)
            )
        }
    }

    override fun onStart() {
        super.onStart()
        AdUtil.startBannerAd(this, binding.root.main_banner_frame, AdSize.BANNER, Const.mainBannerUnitId)
    }
}