package jackall.moncalc.viewmodel import android.databinding.BaseObservable import android.databinding.ObservableInt import android.view.View import android.widget.Toast import jackall.moncalc.App import jackall.moncalc.contract.MainServiceContract import jackall.moncalc.db.MonstDataRealmHelper import jackall.moncalc.db.QuestRecordRealmHelper import jackall.moncalc.vo.Fruit import jackall.moncalc.vo.Grade import jackall.moncalc.vo.QuestRecord import jackall.moncalc.vo.Temple import java.util.* /** * Created by matsumoto_k on 2017/11/01. */ class OverlayRegistViewModel(val mainServiceContract: MainServiceContract) : BaseObservable() { private val monstDataRealmHelper = MonstDataRealmHelper() private val questRecordRealmHelper = QuestRecordRealmHelper() val templeRank = ObservableInt(0) val fruitRank = ObservableInt(0) val gradeRank = ObservableInt(0) fun onClickRegist(view: View) { questRecordRealmHelper.insert( QuestRecord( templeId = monstDataRealmHelper.findIdByRank(Temple::class.java, templeRank.get()), fruitId = monstDataRealmHelper.findIdByRank(Fruit::class.java, fruitRank.get()), gradeId = monstDataRealmHelper.findIdByRank(Grade::class.java, gradeRank.get()), createAt = Date() ) ) Toast.makeText(App.instance, "記録しました", Toast.LENGTH_LONG).show() mainServiceContract.showMoveView() } fun onClickMin(view: View) { mainServiceContract.showMoveView() } fun onClickFinish(view: View) { mainServiceContract.finish() } fun realmInstanceClose() { monstDataRealmHelper.close() questRecordRealmHelper.close() } }