package jackall.overlaymulticounter.activity import android.arch.lifecycle.ViewModelProviders import android.databinding.DataBindingUtil import android.os.Bundle import android.support.v7.app.AppCompatActivity import jackall.overlaymulticounter.R import jackall.overlaymulticounter.databinding.ActivityMainBinding import jackall.overlaymulticounter.db.CounterRealmHelper import jackall.overlaymulticounter.viewmodel.MainViewModel import jackall.overlaymulticounter.vo.Counter 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) ) } } }