package jackall.overlaymulticounter.viewmodel import android.databinding.BaseObservable import android.databinding.ObservableField import android.view.View import io.realm.RealmChangeListener import jackall.overlaymulticounter.vo.Counter /** * Created by matsumoto_k on 2017/11/08. */ class CounterItemViewModel(val counter: Counter) : BaseObservable() { val id = counter.id val title = ObservableField<String>(counter.title) val count = ObservableField<String>(counter.count.toString()) val realmChangeListener = RealmChangeListener<Counter> { title.set(it.title) count.set(it.count.toString()) } init { counter.addChangeListener(realmChangeListener) } fun onClickPlus(view: View) { counter.count++ } fun onClickMinus(view: View) { counter.count-- } fun onClickReset(view: View) { counter.count = 0 } }