package safeluck.drive.evaluation.DB.lightdb
|
|
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.viewModelScope
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.launch
|
|
/**DriveJudge
|
* Created by lzw on 2021/1/15. 09:46:49
|
* 邮箱:632393724@qq.com
|
* All Rights Saved! Chongqing AnYun Tech co. LTD
|
*/
|
class LightDefaultViewModel internal constructor(private val lightDefaultRepository: LightDefaultRepository): ViewModel() {
|
var allDefaultQuestion2Answers = lightDefaultRepository.getLightUseQuestions()
|
fun deleteItem(lightUseQuestions: LightUseQuestions){
|
viewModelScope.launch {
|
lightDefaultRepository.removeItem(lightUseQuestions)
|
}
|
}
|
@ExperimentalCoroutinesApi
|
override fun onCleared() {
|
super.onCleared()
|
viewModelScope.cancel()
|
}
|
|
fun updateQuestion2Answer(questionId: Int, answ: String) {
|
viewModelScope.launch {
|
lightDefaultRepository.updateQuest2Answer(questionId,answ)
|
}
|
}
|
|
fun addItem(questionId: Int, Question: String, flag: Int,answer:String) {
|
viewModelScope.launch {
|
lightDefaultRepository.addItem(questionId,Question,flag,answer)
|
}
|
}
|
}
|